我是optaPlanner的新手,我正试图通过更改晚餐派对示例来解决不同类型的问题,从而更好地学习如何使用它。我添加了一个名为sameSleepingPreference的新分数规则,它使用我创建的名为sleepingPreference的新枚举,该属性是guest虚拟机的属性。具有相同睡眠偏好的人彼此相邻。
rule "sameSleepingPreference"
when
$leftDesignation : SeatDesignation($leftGuest : guest)
$rightDesignation : SeatDesignation(isRightOf($leftDesignation), $rightGuest : guest)
eval($leftGuest.sleepingPreference.equals($rightGuest.sleepingPreference))
then
scoreHolder.addConstraintMatch(kcontext, +1);
end
当我尝试使用只有四个人的数据表运行optaPlanner时,该示例工作正常。但是,我通过改变晚餐派对示例中的一个原始数据表,制作了144个人的长名单,它给了我这个错误:
2015-07-23 10:41:59,414 [AWT-EventQueue-0] INFO Opened: data\dinnerparty\unsolved\hannahWeddingTest.xml
2015-07-23 10:42:01,012 [SwingWorker-pool-4-thread-1] INFO Solving started: time spent (97), best score (uninitialized/-14400), environment mode (REPRODUCIBLE), random (JDK with seed 0).
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Solving failed.
at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.done(SolverAndPersistenceFrame.java:297)
at javax.swing.SwingWorker$5.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
at sun.swing.AccumulativeRunnable.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$300(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.RuntimeException: org.optaplanner.examples.dinnerparty.solver.Rule_sameSleepingPreference1438171934Eval0Invoker@a59a25b3 : java.lang.NullPointerException
at org.drools.core.rule.EvalCondition.isAllowed(EvalCondition.java:123)
at org.drools.core.phreak.PhreakEvalNode.doLeftInserts(PhreakEvalNode.java:55)
at org.drools.core.phreak.PhreakEvalNode.doNode(PhreakEvalNode.java:39)
at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:342)
at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:161)
at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:116)
at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:231)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:106)
at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1016)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1302)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1289)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1262)
at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.calculateScore(DroolsScoreDirector.java:87)
at org.optaplanner.examples.dinnerparty.solver.solution.initializer.DinnerPartySolutionInitializer.initializeSeatDesignationList(DinnerPartySolutionInitializer.java:69)
at org.optaplanner.examples.dinnerparty.solver.solution.initializer.DinnerPartySolutionInitializer.changeWorkingSolution(DinnerPartySolutionInitializer.java:41)
at org.optaplanner.core.impl.phase.custom.DefaultCustomPhase.doStep(DefaultCustomPhase.java:78)
at org.optaplanner.core.impl.phase.custom.DefaultCustomPhase.solve(DefaultCustomPhase.java:60)
at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:213)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:176)
at org.optaplanner.examples.common.business.SolutionBusiness.solve(SolutionBusiness.java:302)
at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.doInBackground(SolverAndPersistenceFrame.java:286)
at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.doInBackground(SolverAndPersistenceFrame.java:1)
at javax.swing.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at org.optaplanner.examples.dinnerparty.solver.Rule_sameSleepingPreference1438171934.eval0(Rule_sameSleepingPreference1438171934.java:8)
at org.optaplanner.examples.dinnerparty.solver.Rule_sameSleepingPreference1438171934Eval0InvokerGenerated.evaluate(Unknown Source)
at org.optaplanner.examples.dinnerparty.solver.Rule_sameSleepingPreference1438171934Eval0Invoker.evaluate(Unknown Source)
at org.drools.core.rule.EvalCondition.isAllowed(EvalCondition.java:118)
... 27 more
我的144人的例子是不可能解决的,还是有不同的问题?我已经尝试使睡眠偏好规则添加点并从分数中减去分数(我使用简单分数)但两者都导致程序失败。
答案 0 :(得分:0)
这是编写该规则的推荐方法,因为“eval”已弃用且drools ==
变为相同的调用:
rule "sameSleepingPreference"
when
$leftDesignation : SeatDesignation($leftGuest : guest)
$rightDesignation : SeatDesignation(isRightOf($leftDesignation), $leftGuest.sleepingPreference == guest.sleepingPreference)
then
scoreHolder.addConstraintMatch(kcontext, +1);
end