Search code examples
droolsoptaplanner

OptaPlanner Drools implementation error


Hi I am just starting to use OptaPlanner in conjunction with drools. However I am having two issues. I belive it is down to my understanding of the syntax.

The following rule is throwing an error when I try to instantiate the solver.

//Soft constraints
rule "waistedArea"
    when
        $sheet : Sheet($area: (area * 10000))
        $usedAreaTotal : Number (intValue > 0 && intValue < $area ) from accumulate(
            Part(
                    sheet == $sheet,
                    $usedArea : requiredArea * 10000
                ),
            sum($usedArea)
        ) 
        $waste : ($area - $usedAreaTotal)
        eval($waste > 0)
     then
        insertLogical(new IntConstraintOccurrence("waistedArea", constraintType.NEGATIVE_SOFT, $waste,$sheet)
    end

The multiply by 10000 is a temporary cast from a double value to an int, nut aware of the syntax for this yet.

The rule is intended to calculate the waist value of a sheet that has a number of components assigned to it.

The rule throws the following error.

Message [id=1, level=ERROR, path=optaplanner-kie-namespace//Resources/DRLRools
/NestingRules.drl, line=71, column=0
   text=[ERR 102] Line 71:24 mismatched input '-' in rule "waistedArea"]
Message [id=2, level=ERROR, path=optaplanner-kie-namespace//Resources/DRLRools
/NestingRules.drl, line=0, column=0
   text=Parser returned a null Package]

Any explination would be helpful.


Solution

  • You cannot write this, because it is not a "Conditional Element":

    $waste : ($area - $usedAreaTotal)
    

    This is sufficient:

    eval($area > $usedAreaTotal)
    

    I don't see any good reason to multiply by 10000 - at the end, you compare two values, and multiplying with 10000 doesn't alter the relation. Number also has doubleValue().

    And: it's called waste - waist is where your belt is :-)