[rules-users] [Drools Planner] Hard constraint appears to be ignored

Reinis drools at orbit-x.de
Sun Feb 26 11:51:47 EST 2012


Hello, it appears that hard constraint I have defined is being ignored 
in some rare cases. Here's an example:

This is what my application logs after getting best solution after 
solver has returned from solve():

2012-02-23 21:28:54,595 [main] INFO  Project Project1 assignment 
563:[2012-02-27T13:00:00.000/2012-02-27T17:00:00.000] was assigned to John

2012-02-23 21:28:54,597 [main] INFO  Project Project2 assignment 
508:[2012-02-27T13:00:00.000/2012-02-27T17:00:00.000] was assigned to John

(The log says that John was assigned twice in same time period to two 
different assignments (assignment 563 and assignment 508)

Here short explanation of the relevant domain data
assignment.id = 563
assignment.interval = 2012-02-27T13:00:00.000/2012-02-27T17:00:00.000
assignment.project = Project1
assignment.resource = John

And this is rule that, to my opinion should've prohibited that two 
assignments get assigned to the same resource:

rule "only one assignment within interval for the same resource"
     when
         $leftAssignment : Assignment($leftId : id, $interval : 
interval, resource != null, $resource : resource)
         $rightAssignment : Assignment(interval == $interval, resource 
== $resource, id != $leftId)
     then
         insertLogical(new IntConstraintOccurrence("only one assignment 
within interval for the same resource", ConstraintType.NEGATIVE_HARD, 1, 
$leftAssignment, $rightAssignment));
end

The score looks like this:

2012-02-23 21:28:54,594 [main] DEBUG The hard score is: 0 and the soft 
score is: -532

So no hard constraints are broken according to planner.

My question is not what is wrong with this particular example (unless it 
is obvious for you), but if you can think of any anti-pattern that would 
cause this behavior?

What I already checked is:
- this happens really sporadically (most of the time the result is 
CORRECT but in 1 from 5 runs I get this kind of error);
- I checked, re-checked and re-re-checked all the hashCode, compareTo, 
solutionHashCode, solutionCompare, clone, ... methods - they appear to 
be correct;
- moves are simple and I tried to keep them consistent with the way 
moves in drools-planner examples are constructed;

Would be great if you could give me a hint to what direction I should 
look next.

br
Reinis



More information about the rules-users mailing list