[rules-users] Check for overlapping dates

Edson Tirelli tirelli at post.com
Wed Aug 29 18:55:38 EDT 2007


    It all depends on how many simultaneous instances you have in your
working memory. If you have just a few instances, a simple and single rule
can handle your case... you don't need to check for nulls, unless you want
to explicitly handle them:

rule "Overlapping Dates"
   when
      $a : Address (  )
      $b : Address ( this != $a, beginDate > $a.beginDate, beginDate <
$a.endDate )
   then
      // $a and $b overlap
end

    Now, I had to do the same thing for a system that handled telecom calls
and we had hundreds of thousands of call objects at once in the working
memory. As you may be aware, rules like the one above have the potential to
generate combinatorial explosions. In my case, I created a high performance
data structure to index the dates and detect the overlaps and used the rules
only to drive the execution (of course, there were hundreds of other rules
doing other things too). This way I avoided the combinatorial explosion.

    Hope it helps.

    Edson

2007/8/29, Brian Enderle <brianke at gmail.com>:
>
> I have a situation where I need to check for overlapping dates in a
> collection
> of previous addresses.  I am only performing this check after checking
> that
> the beginDate and endDate are not null.
>
> Currently I am using an eval to perform an outside method.  Does anyone
> know
> if and how I could perform this same check using Drools.
>
> Curently my rules look something like this
>
> gloabl java.lang.Boolean dateErrorExists;   // starts off as false
> global ValidationUtils utils;
>
> rule "beginDate must exist"
>    when
>       Address ( beginDate != null )
>    then
>       dateMissing = true;
>       <display error>
> end
>
> rule "endDate must exist"
>    when
>       Address ( endDate != null )
>    then
>       dateMissing = true;
>       <display error>
> end
>
> rule "Previous Address dates cannot overlap"
>    salience -10
>    when
>       eval (dateMissing)
>       eval (utils.doAddressDatesOverlap())
>    then
>       <display error>
> end
>
> Our system simply runs thru the data checking the rules (no facts are
> changed)
> so the dateMissing global is reset to false everytime we perform our
> validation.
>
> The downside to this is I am having to re-get the data from the DB within
> the
> doAddressDatesOverlap() function.  This function orders the Address
> objects by
> their startDates and then compares the endDate of one with the startDate
> of
> the next and returns false if they overlap.
>
> If anyone knows of a cleaner, simpler or better way to perform this check
> within Drools I would appreciate the input.
>
> Thanks in advance,
> Brian Enderle
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070829/ed19d318/attachment.html 


More information about the rules-users mailing list