Don't think procedurally, just write the *rule* for a missing post ;-)

rule "missing fence post"
when
    FencePost( $d: distanceFromStart )
    FencePost( distanceFromStart == $d + 2*FencePost.GAP )
    not FencePost( distanceFromStart == $d + FencePost.GAP )
then
    System.out.println( "Missing: " + ($d + FencePost.GAP) );
end

-W

On 9 February 2012 16:41, mikeg <m...@thegoldners.com> wrote:

> I need to write a rule to identify a missing element in a group of facts.
>
> For example, let us say I want to ensure that my fence has a fence post
> every 8 feet.  My fact declaration is as follows:
>
> declare FencePost
>  identifier : String
>  distanceFromStart: Long
> end
>
> If I add the following facts into my session:
>
> FencePost("a", 0)
> FencePost("x", 8)
> FencePost("e", 24)
>
> I want a rule that will notify the user that there is a missing fence post
> between "x" and "e".
>
> I've been looking into using "collect" into a TreeSet/TreeMap to get a
> collection sorted on the "distanceFromStart", but I cannot figure out how
> to
> compare adjacent elements in the collection.
>
> Any ideas?
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-do-I-write-a-rule-to-detect-a-missing-value-in-a-group-of-facts-tp3729818p3729818.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to