如果我在optaplanner中使用多线程,则会引发异常

时间:2018-08-22 11:12:22

标签: optaplanner

2018-08-22 18:56:18,007 61345 [main] DEBUG o.o.c.i.c.DefaultConstructionHeuristicPhase [Line:142] -     CH step (910), time spent (45305), score (-456init/0hard/0soft), selected move count (810), picked move ([Lecture #ClassUnit # 1 - Curriculum 641#语文 @ null null {null -> Period-0}, Lecture #ClassUnit # 1 - Curriculum 641#语文 @ null null {null -> Room 801}]).
2018-08-22 18:56:18,016 61354 [main] DEBUG o.o.c.i.c.DefaultConstructionHeuristicPhase [Line:142] -     CH step (911), time spent (45314), score (-456init/0hard/0soft), selected move count (40), picked move (Lecture #ClassUnit # 1 - Curriculum 641#语文 @ Period-0 Room 801 {null -> null}).
2018-08-22 18:56:18,045 61383 [main] INFO  o.o.c.i.c.DefaultConstructionHeuristicPhase [Line:160] - Construction Heuristic phase (0) ended: time spent (45343), best score (-456init/0hard/0soft), score calculation speed (8509/sec), step total (912).

java.lang.IllegalStateException: Local Search phase (1) needs to start from an initialized solution, but the planning variable (Lecture.teacher) is uninitialized for the entity (Lecture #ClassUnit # 1 - Curriculum 641#语文 @ Period-0 Room 801).
Maybe there is no Construction Heuristic configured before this phase to initialize the solution.
Or maybe the getter/setters of your planning variables in your domain classes aren't implemented correctly.

    at org.optaplanner.core.impl.phase.AbstractPhase.assertWorkingSolutionInitialized(AbstractPhase.java:220)
    at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.phaseStarted(DefaultLocalSearchPhase.java:118)
    at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:64)
    at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:87)
    at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:191)
    at org.optaplanner.core.api.solver.Solver$solve.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
    at com.bugu.queen.service.solver.CourseScheduleSolverFactoryServiceTest.createSolver(CourseScheduleSolverFactoryServiceTest.groovy:223)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

但是,如果我通过更改config xml来禁用多个cpu,例如

<!-- To solve faster by saturating multiple CPU cores -->
    <moveThreadCount>AUTO</moveThreadCount>

那么,是错误还是我的错误?

并且我在getRangeList返回之前检查了教师范围,我确定它不是空的。

我使用

<constructionHeuristic>
        <constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>

    </constructionHeuristic>

1 个答案:

答案 0 :(得分:0)

我怀疑Move.rebase()出了错。这可能是由于与您放置@PlanningId注释的位置有关。

我想确切地知道出了什么问题,因此OptaPlanner的FULL_ASSERT模式可以更快地检测到它(并且可能会更好地解释它)。请创建带有复制器的吉拉。