0

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.

Jon
  • 75
  • 7

1 Answers1

1

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 :-)

laune
  • 30,276
  • 3
  • 26
  • 40
  • Thank you for your comments, I had already discovered the eval option. I am currently having difficulty with another rule (as well as my spelling :)). Please could you provide a simple cast example, as from what I have read the soft rules do not work efficiently with real numbers. Is this correct? – Jon Jun 09 '14 at 09:51
  • Yes, floats/doubles are [inherently broken](http://docs.jboss.org/drools/release/latest/optaplanner-docs/html_single/index.html#avoidFloatingPointNumbersInScoreCalculation) (but OptaPlanner still supports them). Just use a long and multiple your floats/doubles by 1000 if you need 3 decimal number accuracy, by 10000 if you need 4, etc. Or use BigDecimal. – Geoffrey De Smet Jun 10 '14 at 08:59
  • @GeoffreyDeSmet But a mere multiplication with a power of 10 doesn't convert from floating point to integer. Using a small but *integral* unit of area avoids this issue, but this must be implemented in the data model, Sheet and Part. – laune Jun 10 '14 at 09:46
  • 1
    Thank you for your comments. I resolved this by having a configurable precision value within the model and then providing a accessor to an integer representation of the real number. – Jon Jun 10 '14 at 10:16
  • For more background into this discussion, see [why there are far more doubles between 0.0 an 1.0 than between 1.0 and 2.0](http://stackoverflow.com/questions/2978930/how-many-double-numbers-are-there-between-0-0-and-1-0) and [what whe should know about floating point arethmetic](http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) – Geoffrey De Smet Jun 12 '14 at 07:23