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

奇妙なことに、私の例では 2 番目のルール ("isNull") だけが実行されます。最初のルール (「notNull」) は起動されませんが、計算が終了したときに私のソリューションのセル要素は null ではありません。

これら 2 つのルールを EasyScoreCalculator に埋め込むと、両方とも起動されます。これら 2 つのルールを 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