1

I have a rule of the form

rule "notBar"
    when
        $foo : Foo(bar == false)
    then
        insertLogical(new IntConstraintOccurrence("notBar", ConstraintType.NEGATIVE_SOFT,
                $foo));
end

I expect to see this fired once for every Foo with bar being false however the rule is only fired once. Confusingly if I change the $foo : Foo(bar == false) to $foo : Foo() then it is correctly fired for all Foo's. What am I missing?

Jim
  • 22,354
  • 6
  • 52
  • 80
  • And you're sure that there are several Foo's with false bars? I don't see any problems with this rule. – fnst Jul 07 '11 at 09:38

1 Answers1

1

Bah. I'm an idiot. My cloneSolution method was calling a copy constructor which didn't correctly copy bar.

Jim
  • 22,354
  • 6
  • 52
  • 80
  • if `foo` is a planning entity (= changes during planning, for example a RoomAssignment) it should be deep cloned, but if `bar` is just a planning fact (= does not change during planning, for example a Room) there's no need to clone it, you can just copy the reference. Although in this case bar is a boolean, so that's just a copy of the value too. See any of the Drools Planner examples. Btw, What kind of planning problem are you solving? – Geoffrey De Smet Jul 07 '11 at 19:36
  • @Geoffrey De Smet foo does change but I hadn't thought that I could just copy the reference of facts, think there's a bit of code which does this so can fix that. Just a little bin packing program to help me learn Drools (specifically planner). – Jim Jul 08 '11 at 09:12