问题
I am new to optplanner and playing around with using it to solve a timetabling problem however after all the setup, when I try to solve the problem, I get the following error:
java.lang.IllegalStateException: The selectionList contains 2 times the same selection (c0001{t000}-0 @ null + null) and (c0001{t000}-1 @ null + null).
at org.optaplanner.core.impl.heuristic.selector.common.decorator.WeightFactorySelectionSorter.sort(WeightFactorySelectionSorter.java:58)
at org.optaplanner.core.impl.heuristic.selector.entity.decorator.SortingEntitySelector.constructCache(SortingEntitySelector.java:44)
at org.optaplanner.core.impl.heuristic.selector.common.SelectionCacheLifecycleBridge.phaseStarted(SelectionCacheLifecycleBridge.java:49)
at org.optaplanner.core.impl.phase.event.PhaseLifecycleSupport.firePhaseStarted(PhaseLifecycleSupport.java:39)
at org.optaplanner.core.impl.heuristic.selector.AbstractSelector.phaseStarted(AbstractSelector.java:47)
at org.optaplanner.core.impl.phase.event.PhaseLifecycleSupport.firePhaseStarted(PhaseLifecycleSupport.java:39)
at org.optaplanner.core.impl.heuristic.selector.AbstractSelector.phaseStarted(AbstractSelector.java:47)
at org.optaplanner.core.impl.phase.event.PhaseLifecycleSupport.firePhaseStarted(PhaseLifecycleSupport.java:39)
at org.optaplanner.core.impl.constructionheuristic.placer.AbstractEntityPlacer.phaseStarted(AbstractEntityPlacer.java:41)
at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.phaseStarted(DefaultConstructionHeuristicPhase.java:124)
at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.solve(DefaultConstructionHeuristicPhase.java:67)
at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:214)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:176)
Has anyone come across this before and can you please help if you have.
回答1:
It looks like a problem in your dataset (or in a domain object's equals() method).
The selectionList contains 2 times the same selection (c0001{t000}-0 @ null + null) and (c0001{t000}-1 @ null + null).
It thinks that these 2 lectures are the same:
- c0001...-0 // Lecture 0 of course 0001
- c0001...-1 // Lecture 1 of course 0001
Obviously they are not equal, because they have a different lectureIndexInCourse.
Lecture inherits it's equals method from AbstractPersistable, which does equality based on id.
My bet is that your Lectures in your dataset either have a null id or there are duplicates.
来源:https://stackoverflow.com/questions/32614204/optaplanner-the-selectionlist-contains-2-times-the-same-selection