0

I'm building a very basic Drools-solver in OptaPlanner:

package org.bpmngenerator.solver;
dialect "java"

import org.optaplanner.core.api.score.buildin.simple.SimpleScoreHolder;

import org.bpmngenerator.domain.Cell;

global SimpleScoreHolder scoreHolder;

rule "notNull"
    when
        Cell(rule != null)
    then
        System.out.println("is not null");
end

rule "isNull"
    when
        Cell(rule == null)
    then
        System.out.println("is null");
end

Strangely, only the second rule ("isNull") gets fired in my example. The first rule ("notNull") never gets fired, although the Cell-elements of my solution are not null when the calculation is finished.

When I embed those two rules in an EasyScoreCalculator, both get fired. When I put these two rules into the .drl-file of the NQueens-Example (see http://docs.jboss.org/optaplanner/release/6.1.0.Final/optaplanner-docs/html_single/#nQueens for more), both rules get fired too. There is another difference between my code and the NQueens-Example. I get this warning for my code:

2015-04-09 16:51:43,162 [drools-worker-1] WARN  Exception jitting: rule != null This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-04-09 16:51:43,162 [drools-worker-1] WARN  Exception jitting: rule == null This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode

And this is my class org.bpmngenerator.domain.Cell:

@PlanningEntity 
@XStreamAlias("Cell")
public class Cell extends AbstractPersistable {

    private Column column;
    private Row row;

    // Planning variables: changes during planning, between score calculations.
    private ChomskyRule rule;

    public Column getColumn() {
        return column;
    }

    public void setColumn(Column column) {
        this.column = column;
    }

    public Row getRow() {
        return row;
    }

    public void setRow(Row row) {
        this.row = row;
    }

    @PlanningVariable(valueRangeProviderRefs = {"ruleRange"}) 
    public ChomskyRule getRule() {
        return rule;
    }

    public void setRule(ChomskyRule rule) {
        this.rule = rule;
    }

    // ************************************************************************
    // Complex methods
    // ************************************************************************

    public int getColumnIndex() {
        return column.getIndex();
    }

    public int getRowIndex() {
        return row.getIndex();
    }

    public String getRuleString() {
        if (rule == null) {
            return " ";
        }
        return rule.getRule();
    }

    public String getRuleLeftSide() {
        if (rule == null) {
            return " ";
        }
        return rule.getLeftSide();
    }

    public String getRuleRightSide() {
        if (rule == null) {
            return " ";
        }
        return rule.getRightSide();
    }

    @Override
    public String toString() {
        return column + "@" + row + " => " + rule;
    }

}
rob_87
  • 45
  • 1
  • 1
  • 8
  • How many Cells do you have? Because Cell's rule is a normal planning variable (it's not nullable=true), it will start out as null, but OptaPlanner will fill it before the CH ends (unless the value range is empty). But before the CH ends, it will definitely have called rules while some Cell's rule property is null (presuming all Cells start with a null rule). – Geoffrey De Smet Apr 10 '15 at 13:12
  • Thanks a lot for your response. I have 10 Cells. I don't get why both of these rules get fired for the nQueens-problem. Because both examples have the same structure. Instead of Queen I use Cell, and instead of Row I use Rule. – rob_87 Apr 10 '15 at 13:36
  • do you use the id trick like in NQueens. If so, is the id unique (and not null)? – Geoffrey De Smet Apr 12 '15 at 10:54
  • yes, I assign unique id's in the method createCellList in my NCellsGenerator – rob_87 Apr 13 '15 at 12:27

0 Answers0