0

我正在 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”)永远不会被触发,尽管我的解决方案的单元格元素在计算完成时不为空。

当我将这两条规则嵌入到 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;
    }

}
4

0 回答 0