Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-2780

Match rule incorrectly using drools

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 8.28.0.Final
    • 8.26.0.Final
    • optaplanner-core
    • None

      I have 4 rules in drl file, as below

      rule "All planned"
          when
              Task(produceType == 2)
          then
              scoreHolder.addMediumConstraintMatch(kcontext, -10);
      end
      
      rule "If not planned, Dark fisrt"
          when
              Task(produceType == 2, artColorDegree == "Dark")
          then
              scoreHolder.addSoftConstraintMatch(kcontext, -10);
      end
      
      rule "If not planned, Light second"
          when
              Task(produceType == 2, artColorDegree == "Light")
          then
              scoreHolder.addSoftConstraintMatch(kcontext, -20);
      end
      
      rule "If not planned, White third"
          when
              Task(produceType == 2, artColorDegree == "White")
          then
              scoreHolder.addSoftConstraintMatch(kcontext, -30);
      end

       

      However, Task(produceType == 1) will match 1 of the 3 "If not planned *" rules.

          Constraint match totals:
              -30soft: constraint (If not planned, White third) has 1 matches:
                  -30soft: justifications ([Task{id=3, produceType=1, planDateId=8, machineGroupId=6}])
              -20soft: constraint (If not planned, Light second) has 1 matches:
                  -20soft: justifications ([Task{id=2, produceType=1, planDateId=8, machineGroupId=7}])
              -10soft: constraint (If not planned, Dark fisrt) has 1 matches:
                  -10soft: justifications ([Task{id=1, produceType=1, planDateId=2, machineGroupId=2}])
       

       

      Comment 1 of the 3 "If not planned *" rules, it will work correctly or 
      change comma(,) to &&, it will work correctly.

      rule "If not planned, Dark fisrt"
          when
              Task(produceType == 2 && artColorDegree == "Dark")
          then
              scoreHolder.addSoftConstraintMatch(kcontext, -10);
      end
      
      rule "If not planned, Light second"
          when
              Task(produceType == 2 && artColorDegree == "Light")
          then
              scoreHolder.addSoftConstraintMatch(kcontext, -20);
      end
      
      rule "If not planned, White third"
          when
              Task(produceType == 2 && artColorDegree == "White")
          then
              scoreHolder.addSoftConstraintMatch(kcontext, -30);
      end

       

      This is very unexpected, could anyone help to solve this, thanks.

              lpetrovi@redhat.com Lukáš Petrovický (Inactive)
              ewinchen Edwin Chen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: