We are solving an allocation problem in OptaPlanner where each machine/period combination has a material allocated to it.
The planning entity has the machine/period key and its planning variable is a private Material allocatedMaterial field which represents a problem fact.
We understand that neighborhood search should help the optimizer focus on the vicinities of the planning entity - which is defined by a distance metric based on time/period distance.
Out aim is to narrow the entity search to the ones that are closest to the last entity that was changed.
We have set up the configuration below:
<changeMoveSelector>
<entitySelector id="entitySelector1"/>
<valueSelector>
<nearbySelection>
<originEntitySelector mimicSelectorRef="entitySelector1"/>
<nearbyDistanceMeterClass>org.test.AllocationDistanceMeter</nearbyDistanceMeterClass>
<nearbySelectionDistributionType>
PARABOLIC_DISTRIBUTION</nearbySelectionDistributionType>
<parabolicDistributionSizeMaximum>40</parabolicDistributionSizeMaximum>
</nearbySelection>
</valueSelector>
</changeMoveSelector>
With this configuration DistanceMeter:
- The initial DistanceMeter call receives a null value for the destination
- On the following calls the destination is interpreted as the problem fact instead of the planning entity (machine/period) and throws the error
Exception in thread "main" java.lang.IllegalArgumentException: The entitySelectorConfig (EntitySelectorConfig(null)) has a mimicSelectorRef (entitySelector1) for which no entitySelector with that id exists (in its solver phase).
at org.optaplanner.core.impl.heuristic.selector.entity.EntitySelectorFactory.buildMimicReplaying(EntitySelectorFactory.java:132)
public class AllocationDistanceMeter implements NearbyDistanceMeter<EntityClass, EntityClass> {
@Override
public double getNearbyDistance(EntityClassorigin, EntityClassdestination) {
return Math.abs(origin.period - destination.period);
}
}
I have tried changing the ValueSelector to an EntitySelector. In that case I get the following error message:
The entitySelectorConfig (EntitySelectorConfig(null)) has a mimicSelectorRef (entitySelector1) for which no entitySelector with that id exists (in its solver phase)
Configuration with an EntitySelector:
<changeMoveSelector>
<entitySelector id="entitySelector1">
<nearbySelection>
<originEntitySelector mimicSelectorRef="entitySelector1"/>
<nearbyDistanceMeterClass>org.test.AllocationDistanceMeter</nearbyDistanceMeterClass> <nearbySelectionDistributionType>PARABOLIC_DISTRIBUTION</nearbySelectionDistributionType>
<parabolicDistributionSizeMaximum>40</parabolicDistributionSizeMaximum>
</nearbySelection>
</entitySelector>
</changeMoveSelector>
Is ChangeMoveSelector + Nearby Selection based on Entity Selection supported by OptaPlanner? If so, what is wrong with the configuration?