[jboss-jira] [JBoss JIRA] (JBRULES-3144) undo-then: when rule becomes no longer true execute a callback"
Geoffrey De Smet (Updated) (JIRA)
jira-events at lists.jboss.org
Fri Dec 16 04:57:09 EST 2011
[ https://issues.jboss.org/browse/JBRULES-3144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Geoffrey De Smet updated JBRULES-3144:
--------------------------------------
Description:
Here's what I'd like to be able to do:
{code}
rule "serviceConflict"
when
$leftProcessAssignment : MrProcessAssignment($service : service, $machine : machine, $leftId : id)
$rightProcessAssignment : MrProcessAssignment(service == $service, machine == $machine, id > $leftId)
then
scoreCalculator.addToHardScore(1); // No insertLogical or accumulate of those ConstraintOccurence's needed
undo-then
scoreCalculator.substractFromHardScore(1);
end
{code}
And here's a more complex example where the weight isn't a static "1":
{code}
rule "serviceLocationSpread"
when
$service : MrService($locationSpread : locationSpread)
$spreadCount : Number(intValue < $locationSpread) from accumulate(
$location : MrLocation()
and exists MrProcessAssignment(service == $service, location == $location),
count($location)
)
then
scoreCalculator.addToHardScore($locationSpread - $spreadCount.intValue());
undo-then
scoreCalculator.substractFromHardScore($locationSpread - $spreadCount.intValue());
// $spreadCount should still be the same as it used to be
end
{code}
was:
<_conan_> ge0ffrey: can do unfalse situation
<ge0ffrey> conan: is there a way to get a "when the rule no longer applies, execture this code"?
<_conan_> ge0ffrey: i.e. when a ruel becomes untrue execute a callback
<ge0ffrey> conan: yes!
<_conan_> yes
<_conan_> it's trivial to do actually
<ge0ffrey> conan: what's the code name for that feature?
<_conan_> not related to TMS
<ge0ffrey> yep
<_conan_> you can potentially hack one for yourself
<_conan_> in about 10 minutes
<ge0ffrey> I 'd also need to have a value which was caclulated in hte the orginal RHS
<_conan_> but the feature over all will take a lot of thought, due to language design
<_conan_> but for your use case
<_conan_> it's trivial to do
<_conan_> in the rule you have the Activation
<_conan_> the impl is the AgendaItem
<ge0ffrey> conan: would love to do this (espeically if I get some appointed time for it :)
<_conan_> you can do kcontext.getActivation
<_conan_> it'll take you 15 minutes to do it
<_conan_> change AgendaItem to have new field reference Callable or what ever you want to use.
<ge0ffrey> k
<_conan_> in the consequnce just do agendaItem.addCallable( new Callable() {............ } );
<_conan_> i.e. use an anonymous class
<_conan_> the only thing you need to do now
<_conan_> is in RuleTerminalNode in retractLeftTuple is agendaItem.executeCallables()
<_conan_> that's it
<_conan_> it's that trivial
<ge0ffrey> (copy pasting htis in an issue to look at later, as my workspace is open on my fork today)
<_conan_> I just don't want to expose that as a generic feature
<_conan_> because the issue needs more thought
<ge0ffrey> of course
<_conan_> with regards to language design
<_conan_> but for your use case
<_conan_> and as you are an expert
<_conan_> it's fine
<_conan_> I'd suggest you just maintain a "patched" version of drools for that feature
<ge0ffrey> but if the exeperiment works well, we can look at language design
<_conan_> yes
<_conan_> I need this anyway
<_conan_> becausae rule engines need to tell peopl when things stop being true
<ge0ffrey> conan: not going to start using for released planner until it's in drools expert for real
> undo-then: when rule becomes no longer true execute a callback"
> ---------------------------------------------------------------
>
> Key: JBRULES-3144
> URL: https://issues.jboss.org/browse/JBRULES-3144
> Project: Drools
> Issue Type: Task
> Security Level: Public(Everyone can see)
> Components: drools-core (expert), drools-planner
> Reporter: Geoffrey De Smet
> Assignee: Geoffrey De Smet
>
> Here's what I'd like to be able to do:
> {code}
> rule "serviceConflict"
> when
> $leftProcessAssignment : MrProcessAssignment($service : service, $machine : machine, $leftId : id)
> $rightProcessAssignment : MrProcessAssignment(service == $service, machine == $machine, id > $leftId)
> then
> scoreCalculator.addToHardScore(1); // No insertLogical or accumulate of those ConstraintOccurence's needed
> undo-then
> scoreCalculator.substractFromHardScore(1);
> end
> {code}
> And here's a more complex example where the weight isn't a static "1":
> {code}
> rule "serviceLocationSpread"
> when
> $service : MrService($locationSpread : locationSpread)
> $spreadCount : Number(intValue < $locationSpread) from accumulate(
> $location : MrLocation()
> and exists MrProcessAssignment(service == $service, location == $location),
> count($location)
> )
> then
> scoreCalculator.addToHardScore($locationSpread - $spreadCount.intValue());
> undo-then
> scoreCalculator.substractFromHardScore($locationSpread - $spreadCount.intValue());
> // $spreadCount should still be the same as it used to be
> end
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list