0

我正在使用 Drools 5.4.0.CR1,当我开始使用

...
XmlSolverFactory configurer = new XmlSolverFactory();
configurer.configure(SOLVER_CONFIG);
Solver solver = configurer.buildSolver();
solver.setPlanningProblem(initialSolution);
solver.solve();
....

我有这个输出

[exec:exec]
2012-04-30 11:10:46,296 [main] INFO  Solving started: time spend (169), score (-13hard/0soft), new best score (-13hard/0soft), random seed (0).
2012-04-30 11:10:46,338 [main] DEBUG     Step index (0), time spend (213), score (-12hard/0soft), new best score (null), accepted move size (10) for picked step (03-05-2012 P emp:EMPLOYEE1 => L).
2012-04-30 11:10:46,356 [main] DEBUG     Step index (1), time spend (231), score (-12hard/0soft), new best score (null), accepted move size (10) for picked step (02-05-2012 P emp:EMPLOYEE2 => S).
java.lang.NullPointerException
    at org.drools.planner.core.score.buildin.hardandsoft.DefaultHardAndSoftScore.compareTo(DefaultHardAndSoftScore.java:125)
    at org.drools.planner.core.score.buildin.hardandsoft.DefaultHardAndSoftScore.compareTo(DefaultHardAndSoftScore.java:27)
    at org.drools.planner.core.localsearch.decider.acceptor.tabu.AbstractTabuAcceptor.isAccepted(AbstractTabuAcceptor.java:121)
    at org.drools.planner.core.localsearch.decider.acceptor.CompositeAcceptor.isAccepted(CompositeAcceptor.java:58)
    at org.drools.planner.core.localsearch.decider.DefaultDecider.processMove(DefaultDecider.java:159)

这是跟踪日志:

2012-04-30 11:40:16,745 [main] INFO  Solving started: time spend (110), score (-13hard/0soft), new best score (-13hard/0soft), random seed (0).
    2012-04-30 11:40:16,781 [main] TRACE         Move score (-13hard/0soft), accepted (true) for move (01-05-2012 M emp:EMPLOYEE1 => P).
    2012-04-30 11:40:16,794 [main] TRACE         Move score (-13hard/0soft), accepted (true) for move (04-05-2012 L emp:EMPLOYEE2 => G).
    2012-04-30 11:40:16,794 [main] TRACE         Ignoring not doable move (01-05-2012 P emp:EMPLOYEE3 => P).
    2012-04-30 11:40:16,807 [main] TRACE         Move score (-13hard/0soft), accepted (true) for move (01-05-2012 M emp:EMPLOYEE4 => S).
    2012-04-30 11:40:16,819 [main] TRACE         Move score (-13hard/0soft), accepted (true) for move (03-05-2012 P emp:EMPLOYEE5 => A).
    ...
    2012-04-30 11:40:16,876 [main] TRACE         Move score (-12hard/0soft), accepted (true) for move (03-05-2012 P emp:EMPLOYEE21 => L).
    2012-04-30 11:40:16,876 [main] TRACE         Ignoring not doable move (01-05-2012 L emp:EMPLOYEE22 => L).
    2012-04-30 11:40:16,876 [main] TRACE         Ignoring not doable move (03-05-2012 N emp:EMPLOYEE23 => N).
    2012-04-30 11:40:16,887 [main] TRACE         Move score (-13hard/0soft), accepted (true) for move (02-05-2012 N emp:EMPLOYEE14 => TS).
    2012-04-30 11:40:16,898 [main] DEBUG     Step index (0), time spend (265), score (-12hard/0soft), new best score (null), accepted move size (10) for picked step (03-05-2012 P emp:EMPLOYEE21 => L).

似乎最好的解决方案没有使用分数值进行更新,但我们将解决方案类定义为您的示例(皇后示例),其中包含 getter 和 setter 分数。

有人对“新的最佳成绩”是否为空有任何建议吗?

谢谢!

4

3 回答 3

3

疯狂的猜测,但是cloneSolution您的解决方案是否可靠地克隆了分数和所有其他问题事实?

我在那里经历了一些无声的错误。

于 2012-05-01T07:02:36.933 回答
0

那条线是不可能的(理论上):

2012-04-30 ...     Step index (0), ..., new best score (null), ...

调试并找出产生空分数的原因。这绝对是一个错误(在规划器或您的代码中)。

我以前没见过这个。您是否使用自定义分数定义?

于 2012-04-30T09:30:21.767 回答
0

我遇到了与上面相同的错误,我可以通过简单地在我的解决方案类的克隆中设置分数来解决它,就像----->

public EmployeeRoster cloneSolution() {
    EmployeeRoster employeeRoster=new EmployeeRoster();
    employeeRoster.id=id;
    employeeRoster.shiftList=shiftList;
    employeeRoster.employeeList=employeeList;
    employeeRoster.score=score;
    return employeeRoster;
}

在 org.drools.planner.core.score.buildin.hardandsoft 的 org.drools.planner.core.score.buildin.hardandsoft.DefaultHardAndSoftScore.compareTo(DefaultHardAndSoftScore.java:125) 的线程“主”java.lang.NullPointerException 中的异常.DefaultHardAndSoftScore.compareTo(DefaultHardAndSoftScore.java:27) at org.drools.planner.core.localsearch.decider.acceptor.tabu.AbstractTabuAcceptor.isAccepted(AbstractTabuAcceptor.java:121) at org.drools.planner.core.localsearch.decider .DefaultDecider.processMove(DefaultDecider.java:159) at org.drools.planner.core.localsearch.decider.DefaultDecider.doMove(DefaultDecider.java:129) at org.drools.planner.core.localsearch.decider.DefaultDecider.decideNextStep (DefaultDecider.java:103) 在 org.drools.planner.core.localsearch.DefaultLocalSearchSolverPhase。在 org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:183) 处解决(DefaultLocalSearchSolverPhase.java:57) 在 org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:151)

于 2012-08-31T06:32:26.597 回答