My construction heuristic's calculation speed decreases alot over time, takes more than 5 minutes to run. I have about 25 resources to allocate 450 tasks. My current configuration for the construction heuristic is the following:
<constructionHeuristic>
<queuedValuePlacer>
<entityClass>pt.ferreiradesa.plantufting.planner.domain.Robot</entityClass>
<valueSelector id="1" variableName="prods">
</valueSelector>
<changeMoveSelector>
<filterClass>pt.ferreiradesa.plantufting.planner.domain.solver.ProdAssignMoveFilter</filterClass>
<selectedCountLimit>1</selectedCountLimit>
<valueSelector mimicSelectorRef="1" />
</changeMoveSelector>
</queuedValuePlacer>
</constructionHeuristic>
What I noticed is this configuration only uses about 3 of the 25 resources. So to try to randomize it a bit I tried the following configuration:
<constructionHeuristic>
<queuedEntityPlacer>
<entitySelector id="placerEntitySelector">
<entityClass>pt.ferreiradesa.plantufting.planner.domain.Robot</entityClass>
<cacheType>JUST_IN_TIME</cacheType>
<selectionOrder>RANDOM</selectionOrder>
</entitySelector>
<changeMoveSelector>
<filterClass>pt.ferreiradesa.plantufting.planner.domain.solver.ProdAssignMoveFilter</filterClass>
<entitySelector mimicSelectorRef="placerEntitySelector"/>
<valueSelector>
<cacheType>JUST_IN_TIME</cacheType>
<selectionOrder>RANDOM</selectionOrder>
<selectedCountLimit>1</selectedCountLimit>
</valueSelector>
</changeMoveSelector>
</queuedEntityPlacer>
</constructionHeuristic>
But that throws me an error that it can't cast ListAssignMove to ListChangeMove. Even if I remove the filterclass, it throws me an indexoutofrange exception.
I'm using chained through time, so all I needed was to assign the tasks to the resources quickly in the construction heuristic. I even tried removing all the constraints, but the speed remains the same.
Related
I want to experiment with different local search configurations. They all use the same neighborhood, so I defined the unionMoveSelector in the inheritedSolverBenchmark.
<inheritedSolverBenchmark>
<solver>
...
<localSearch>
<termination>
<unimprovedSecondsSpentLimit>30</unimprovedSecondsSpentLimit>
</termination>
<unionMoveSelector>
<changeMoveSelector />
<swapMoveSelector />
<pillarChangeMoveSelector>
<subPillarType>ALL</subPillarType>
</pillarChangeMoveSelector>
<pillarSwapMoveSelector>
<subPillarType>ALL</subPillarType>
</pillarSwapMoveSelector>
</unionMoveSelector>
</localSearch>
</solver>
</inheritedSolverBenchmark>
Then I created various benchmarks to compare:
<solverBenchmark>
<name>Tabu</name>
<solver>
<localSearch>
<localSearchType>TABU_SEARCH</localSearchType>
</localSearch>
</solver>
</solverBenchmark>
<solverBenchmark>
<name>LateAcceptance</name>
<solver>
<localSearch>
<localSearchType>LATE_ACCEPTANCE</localSearchType>
</localSearch>
</solver>
</solverBenchmark>
<solverBenchmark>
<name>GreatDeluge</name>
<solver>
<localSearch>
<localSearchType>GREAT_DELUGE</localSearchType>
</localSearch>
</solver>
</solverBenchmark>
<solverBenchmark>
<name>Tabu_LA</name>
<solver>
<localSearch>
<acceptor>
<entityTabuSize>7</entityTabuSize>
<lateAcceptanceSize>400</lateAcceptanceSize>
</acceptor>
<forager>
<acceptedCountLimit>1000</acceptedCountLimit>
</forager>
</localSearch>
</solver>
</solverBenchmark>
But now it seems that OptaPlanner executes three phases (construction + 2 x local search). I had expected the localSearch configuration from inheritedSolverBenchmark and plannerBenchmark to be merged. Is that not the case?
No, I am afraid it's not.
When inherited, the SolverConfig's phaseList gets list-merged, not overwritten, nor list-element-merged:
Nobody want's overwritten (as that would just ignore what's in the inherited config), so that's not it.
list-merged: some cases want this. I 've used it a lot to define a CH in the inherited config and the LS variants in the single benchmarks.
list-element-merged: what you're asking. Some cases want this.
We can't detect automatically if it's a case that needs list-merged or list-element-merged, so we had to make a choice and we went with list-merged.
Fix: Either declare it more verbosely or look at the Freemarker template support.
I have in solverConfig.xml defined filterClasses
<localSearch>
<unionMoveSelector>
<changeMoveSelector>
<filterClass>...</filterClass>
</changeMoveSelector>
<swapMoveSelector>
<filterClass>...</filterClass>
</swapMoveSelector>
<tailChainSwapMoveSelector>
<filterClass>...</filterClass>
</tailChainSwapMoveSelector>
</unionMoveSelector>
(...)
<localSearch>
And in some cases, when there is no moves in log I can see WARN's:
Bailing out of neverEnding selector (..) to avoid infinite loop.
Which is fine, but after some changes are made and addProblemFactChange is called algoritms do not start working again. Restarting works fine, so it is some problem with this method.
solver.isSolving() is returning true.
What could be the reason for this behavior?
During testing and benchmarking, I unintentionally introduced an additional level of unionMoveSelector in my xml solver configuration file:
<unionMoveSelector>
<unionMoveSelector>
<changeMoveSelector>
<fixedProbabilityWeight>1.0</fixedProbabilityWeight>
<valueSelector variableName="start"/>
</changeMoveSelector>
<changeMoveSelector>
<fixedProbabilityWeight>1.0</fixedProbabilityWeight>
<valueSelector variableName="duration"/>
</changeMoveSelector>
<swapMoveSelector>
<filterClass>io.solvice.shift.domain.ShiftAssignmentSwapFilter</filterClass>
<fixedProbabilityWeight>0.1</fixedProbabilityWeight>
</swapMoveSelector>
<swapMoveSelector>
<filterClass>io.solvice.shift.domain.EmployeeSwapFilter</filterClass>
<fixedProbabilityWeight>0.1</fixedProbabilityWeight>
</swapMoveSelector>
<moveIteratorFactory>
<fixedProbabilityWeight>0.1</fixedProbabilityWeight>
<moveIteratorFactoryClass>customMoveIteratorFactory1</moveIteratorFactoryClass>
</moveIteratorFactory>
<moveIteratorFactory>
<fixedProbabilityWeight>1.0</fixedProbabilityWeight>
<moveIteratorFactoryClass>customMoveIteratorFactory2</moveIteratorFactoryClass>
</moveIteratorFactory>
</unionMoveSelector>
</unionMoveSelector>
Extensive testing (albeit on a single, hard-to-tackle instance) has shown that my solver performs better with this additional level than without.
Can someone please explain to me what this does and why it might outperform the other situation?
Is there any way to enable nearby selection in Optaplanner for the subChainChangeMoveSelector or subChainSwapMoveSelector?
I have successfully enabled it for the tail move selector as follows:
<tailChainSwapMoveSelector>
<entitySelector id="tcsm1"/>
<valueSelector>
<variableName>prevReq</variableName>
<nearbySelection>
<originEntitySelector mimicSelectorRef="tcsm1"/>
<nearbyDistanceMeterClass>NearbyMeterTransportChain</nearbyDistanceMeterClass>
</nearbySelection>
</valueSelector>
</tailChainSwapMoveSelector>
However, the same config for any of the two chained movemenents returns an XStream error, explaining that neither of them can have a entitySelector.
I just checked, the docs chapter "Move and Neighborhood Selection" does document the advanced configuration of subchain change/swap move selectors. Take a look.
How can i set multiple value selectors for one move selector in Optaplanner? the documentation says clearly that: "A MoveSelector is often composed out of EntitySelectors, ValueSelectors or even other MoveSelectors, which can be configured individually if desired", which i assume means multiple value selectors can be assigned to one move selector, which makes sense to me, however i get an unmarshalling error when trying that.
<unionMoveSelector>
<changeMoveSelector>
<entitySelector>
<entityClass>com.rdthree.plenty.domain.activity.Activity</entityClass>
</entitySelector>
<valueSelector>
<variableName>startTime</variableName>
</valueSelector>
<valueSelector>
<variableName>endTime</variableName>
</valueSelector> <--this is the line where the error stems from
<filterClass>myclass(don't want to say the name of it)</filterClass>
</changeMoveSelector>
</unionMoveSelector>
error:
java.lang.IllegalArgumentException: Unmarshalling of solverConfigResource (activitySolverConfig.xml) fails.
cause:
Caused by: com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$DuplicateFieldException: Duplicate field valueSelectorConfig
---- Debugging information ----
field : valueSelectorConfig
class : org.optaplanner.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig
required-type : org.optaplanner.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number : 36
class[1] : org.optaplanner.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig
class[2] : org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig
class[3] : org.optaplanner.core.config.solver.SolverConfig
version : 1.4.7
-------------------------------
i'm not copying the entire error text but i can assure you it's referring to the fact that i have two value selectors.
A changeMoveSelector can only have 1 valueSelector currently.
I presume you want a cartesian product (otherwise you can use a unionMoveSelector) over those 2 changeMoveSelectors, so:
<cartesianProductMoveSelector>
<changeMoveSelector>
<entitySelector id="cartesianProductEntitySelector"/>>
<valueSelector>
<variableName>startTime</variableName>
</valueSelector>
</changeMoveSelector>
<changeMoveSelector>
<entitySelector mimicSelectorRef="cartesianProductEntitySelector"/>
<valueSelector>
<variableName>endTime</variableName>
</valueSelector>
</changeMoveSelector>
</cartesianProductMoveSelector>
This means that a single move (a CompositeMove) changes both the startTime and the endTime of 1 (and the same) entity. See docs section about cartesianProductMoveSelector and mimic selection for more info.
Note that this cartesianProductMoveSelector can be nested in a unionMoveSelector if desired to union those CompositeMoves with other moves.