1

我有一个非常简单(可能太简单)的规则,我想在 Drools 中强制执行,以允许将一个值添加到我在 Optaplanner 中的硬分数中。基本上,在我的解决方案类TaskAssignment中,我正在生成 a ,每次发生冲突时都会taskConflictList添加到 a :taskConflictLog

public List<TaskConflict> calculateTaskConflictList(){
   List<TaskConflict> taskConflictList=new ArrayList<TaskConflict>();
   taskConflictLog=0;
    for(Task leftTask:taskList){
        for(Task rightTask:taskList){
            if(leftTask.solutionEquals(rightTask)==!true){
                if(leftTask.getAssignedDevAsString().equals(rightTask.getAssignedDevAsString())){
                if((rightTask.getAllottedStartTime()<=leftTask.getAllottedStartTime()) //long bit of code here....//){
                    taskConflictList.add(new TaskConflict(leftTask,rightTask));
                    taskConflictLog++;
                }
                }
            }
        }
    }
    return taskConflictList;       
   }

然后我想做的就是把这个taskConflictLog行为的负面作为 Drools 中的硬分数。我目前输入了这个:

rule "OnlyDoOneTaskAtTime"
when
    $TA:TaskAssignment($tCL:taskConflictLog)

then
    scoreHolder.addHardConstraintMatch(kcontext,-$tCL);

end

但我收到一条错误消息$tCL cannot be resolved to a variable

这感觉是一件很容易的事情,但由于某种原因,我无法理解它。有没有一个简单的解决方案

4

1 回答 1

1

在示例中,在数据集中查找以 结尾的类Parametrization,例如在考试花名册中:

public class InstitutionParametrization extends AbstractPersistable { // SINGLETON per Solution

    private int twoInARowPenalty;
    private int twoInADayPenalty;
    private int periodSpreadLength;
    private int periodSpreadPenalty;
    private int mixedDurationPenalty;
    private int frontLoadLargeTopicSize;
    private int frontLoadLastPeriodSize;
    private int frontLoadPenalty;

    ...
}

然后在 DRL 中:

rule "twoExamsInADay"
    when
        $institutionParametrization : InstitutionParametrization(twoInADayPenalty != 0)
        $topicConflict : TopicConflict($leftTopic : leftTopic, $rightTopic : rightTopic)
        $leftExam : Exam(topic == $leftTopic, $leftDayIndex : dayIndex, $leftPeriodIndex : periodIndex, period != null)
        $rightExam : Exam(topic == $rightTopic, dayIndex == $leftDayIndex,
            Math.abs($leftPeriodIndex - periodIndex) > 1)
    then
        scoreHolder.addSoftConstraintMatch(kcontext,
                $topicConflict.getStudentSize() * (- $institutionParametrization.getTwoInADayPenalty()));
end

// Exams which share students have to few periods between them
rule "periodSpread"
    when
        $institutionParametrization : InstitutionParametrization(periodSpreadPenalty != 0)
        ...
    then
        scoreHolder.addSoftConstraintMatch(kcontext,
                ... * (- $institutionParametrization.getPeriodSpreadPenalty()));
end
于 2014-04-28T08:02:33.137 回答