如何解决OptaPlanner,DRL 错误,累积多头得到双倍
我的第一个 OptaPlanner 项目,将任务分配给工作人员。启动应用程序时出现以下错误:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalStateException: There are errors in a score DRL:
Error Messages:
Message [id=1,kieBase=defaultKieBase,level=ERROR,path=com....taskassignment/TaskAssignmentRules.drl,line=7,column=0
text=Rule Compilation error The method addSoftConstraintMatch(RuleContext,long) in the type HardMediumSoftLongScoreHolder is not applicable for the arguments (RuleContext,double)]
Task 类是这样的:
public class Task {
...
private long durationInSec; // how long the task takes
...
}
想要有一个公平规则,以便所有工人的总持续时间相似,DRL 在这里:
package com.....taskassignment;
import org.optaplanner.core.api.score.buildin.hardmediumsoftlong.HardMediumSoftLongScoreHolder;
import com.....domain.*;
global HardMediumSoftLongScoreHolder scoreHolder;
rule "fairness"
when
$worker : Worker(name != null)
accumulate(
Task(worker == $worker,$d : durationInSec);
$s : sum($d*$d)
)
then
scoreHolder.addSoftConstraintMatch(kcontext,-$s);
end
不明白为什么 $s 是双数?如果最后一行是这样的:
scoreHolder.addSoftConstraintMatch(kcontext,-1);
然后没有出现错误。我怎样才能解决这个问题?我使用 HardMediumSoftLongScore 是因为我认为 double 比 long 慢。
解决方法
解决了这个问题
scoreHolder.addSoftConstraintMatch(kcontext,-$s.longValue());
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。