我目前正在研究基于甘特图的计划化问题,用户可以选择要计划的任务,而OptaPlanner可以为他们完成计划。
我使用增量Java分数计算,而不使用drools引擎。 我的问题是OptaPlanner不会将Instant作为计划变量,因为它无法为其找到PlanningId。
我一直坚持让OptaPlanner使用多个线程。 我当前的模型似乎有缺陷,或者我不了解如何正确使用OptaPlanner。
我尝试将Instant遮罩在另一个类后面,但仍然没有帮助。
我的模型仅使用一个PlanningEntity,这是一项任务。
这是我的@PlanningEntity的简化版本:
@PlanningEntity(difficultyComparatorClass = TaskDifficultyComparator.class)
public class Task extends AbstractTask {
private Machine machine;
private Instant start;
@PlanningId
private Integer id;
@PlanningVariable(valueRangeProviderRefs = {"machineRange"}, nullable = true, strengthComparatorClass = MachineStrengthComparator.class)
public Machine getMachine() {
return machine;
}
@PlanningVariable(valueRangeProviderRefs = {"timeRange"}, nullable = true, strengthComparatorClass = StartStengthComparator.class)
public Instant getStart() {
return start;
}
}
在我的配置中,我将此添加到了Solver标记中:
<moveThreadCount>AUTO</moveThreadCount>
这给了我一个例外:
Exception in thread "Thread-6" java.lang.IllegalStateException: The move thread with moveThreadIndex (0) has thrown an exception. Relayed here in the parent thread.
at org.optaplanner.core.impl.heuristic.thread.OrderByMoveIndexBlockingQueue.take(OrderByMoveIndexBlockingQueue.java:142)
at org.optaplanner.core.impl.localsearch.decider.MultiThreadedLocalSearchDecider.forageResult(MultiThreadedLocalSearchDecider.java:187)
at org.optaplanner.core.impl.localsearch.decider.MultiThreadedLocalSearchDecider.decideNextStep(MultiThreadedLocalSearchDecider.java:157)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:70)
at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:87)
[...]
Caused by: java.lang.IllegalArgumentException: The externalObject (2019-04-16T20:31:17.162Z) cannot be looked up.
Maybe give the class (class java.time.Instant) a PlanningId annotation or change the PlanningSolution annotation's LookUpStrategyType or don't rely on functionality that depends on ScoreDirector.lookUpWorkingObject().
at org.optaplanner.core.impl.domain.lookup.NoneLookUpStrategy.lookUpWorkingObject(NoneLookUpStrategy.java:47)
at org.optaplanner.core.impl.domain.lookup.LookUpManager.lookUpWorkingObject(LookUpManager.java:74)
[...]
我希望OptaPlanner使用任务的ID,但是似乎它想要每个PlanningVariables的ID。我可以在计算机上添加ID,但不能在即时消息上添加ID。
答案 0 :(得分:0)
java.time.Instant
是不可变的,因此任何查找都可以返回相同的对象实例。就像Integer,Double,LocalDate等一样,不需要@PlanningId
开始。这暴露了OptaPlanner中的3个问题:
请在issue.jboss.org项目PLANNER上为2.和3.创建一个jira。