Java 尝试在Optaplanner中为分数添加值(使用Drools)
我有一个非常简单(可能太简单)的规则,我想在Drools中强制执行,以便在Optaplanner中为我的硬分数添加一个值。 基本上,在我的解决方案类Java 尝试在Optaplanner中为分数添加值(使用Drools),java,drools,optaplanner,Java,Drools,Optaplanner,我有一个非常简单(可能太简单)的规则,我想在Drools中强制执行,以便在Optaplanner中为我的硬分数添加一个值。 基本上,在我的解决方案类TaskAssignment中,我生成了一个taskConflictList,每当出现冲突时,它就会添加到taskConflictLog: public List<TaskConflict> calculateTaskConflictList(){ List<TaskConflict> taskConflictList=
TaskAssignment
中,我生成了一个taskConflictList
,每当出现冲突时,它就会添加到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;
}
但我收到一条错误消息,$tCL无法解析为变量
这感觉是一件很容易的事情,但由于某种原因,我无法集中注意力。在示例中,查找以参数化结尾的类,例如在数据集中的考试排班中:
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
这是您得到的唯一错误吗?-在你的类中是否有一个
public int gettaskconfig()
任务分配?我将在一周或两周内制作一个关于用户玩参数化对象的视频,并将其发布到G+/twitter。你制作了关于使用参数化对象的视频吗?是的,请参阅考试视频,optaplanner.org->learn->video's。
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