[rules-users] Controlling Rule Execution

Wolfgang Laun wolfgang.laun at gmail.com
Wed Jul 31 02:36:34 EDT 2013


On 31/07/2013, jking527467 <jason.king at openroadsconsulting.com> wrote:
> All,
>
> I'm new to Drools and I'm faced with what seems to be a pretty trivial task
> that's taken a lot longer than expected.
>
> I'm working mainly with distances and am looking for an plain English
> response to this trivial problem.

Plain English? Here is it in DRL:

rule "not active thing"
when
    Range( $near: near, $far: far )
    $a: Actor()
    $t: Thing( ! active )
then
end

rule "activate near range"
extends "not active thing"
when
    eval( isInRange( $a, $t, $near ) )
then
    modify( $t ){ setActive( true ) }
end

rule "activate far range"
extends "not active thing"
when
    not ( $n: Thing( isInRange( $a, $n, $near ) ) )
    eval( isInRange( $a, $t, $far ) )
then
    modify( $t ){ setActive( true ) }
end

>
> Here's the problem:
>
> - Activate all things within x miles.
>   - If nothing is within x miles, activate all things within y miles.
>
> It seems pretty straight forward but here's my dilemma.  If I execute on y
> miles first, everything within x miles will also be activated.  I need to
> ensure the things between x and y miles aren't activated if anything is
> within x miles of a certain fact.

Don't think in terms of "executing first" and (needlessly) exercising control.#

As you can see from the rules, simply transform your spec into LHS
patterns. Both clauses have their one-to-one correspondence in the
second and third rule, respectively, while the first one simply
addresses the "player" facts.

-W

>
> Does this make any sense to anyone?  I'm have a hard time grasping the
> proper approach and have looked into activation groups, etc. but haven't
> had
> any luck.
>
> Any help is GREATLY appreciated!!!
>
> Thanks in advance!
> Jason
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Controlling-Rule-Execution-tp4025231.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list