我在OptaPlanner中构建了一个非常基本的Drools解算器:
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
奇怪的是,在我的例子中只有第二条规则(" isNull")被触发。第一个规则(" notNull")永远不会被触发,尽管我的解决方案的Cell元素在计算完成时不为null。
当我在EasyScoreCalculator中嵌入这两个规则时,两者都被解雇了。 当我将这两个规则放入NQueens-Example的.drl文件中时(请参阅http://docs.jboss.org/optaplanner/release/6.1.0.Final/optaplanner-docs/html_single/#nQueens了解更多信息),这两个规则也会被触发。我的代码和NQueens-Example之间还有另一个区别。我的代码收到了这个警告:
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
这是我的班级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;
}
}