2

I declared two planning entities Run and School that have their own planning variables. In the solver config, there are separate construction heuristics for each entity, yet there is an issue that the selectorConfig has not entity Class. Using OptaPlanner 6.2.0. Any help is greatly appreciated.

<constructionHeuristic>
    <queuedEntityPlacer>
        <entitySelector id="placerEntitySelector">
            <entityClass>org.optaplanner.examples.cloudbalancing.domain.Run</entityClass>
            <cacheType>PHASE</cacheType>
        </entitySelector>
        <changeMoveSelector>
            <entitySelector mimicSelectorRef="placerEntitySelector"/>
        </changeMoveSelector>
    </queuedEntityPlacer>
</constructionHeuristic>

<constructionHeuristic>
    <queuedEntityPlacer>
        <entitySelector id="placerEntitySelector">
            <entityClass>org.optaplanner.examples.cloudbalancing.domain.School</entityClass>
            <cacheType>PHASE</cacheType>
        </entitySelector>
        <changeMoveSelector>
            <entitySelector mimicSelectorRef="placerEntitySelector"/>
        </changeMoveSelector>
    </queuedEntityPlacer>
</constructionHeuristic>

Stack trace

--- exec-maven-plugin:1.2.1:exec (default-cli) @ optaplanner-examples ---
Exception in thread "main" java.lang.IllegalArgumentException: The selectorConfig (EntitySelectorConfig(null)) has no entityClass (null) configured and because there are multiple in the entityClassSet ([class org.optaplanner.examples.cloudbalancing.domain.Run, class org.optaplanner.examples.cloudbalancing.domain.School]), it can not be deducted automatically.
 at org.optaplanner.core.config.heuristic.selector.SelectorConfig.deduceEntityDescriptor(SelectorConfig.java:81)
 at org.optaplanner.core.config.heuristic.selector.entity.EntitySelectorConfig.buildEntitySelector(EntitySelectorConfig.java:210)
 at org.optaplanner.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig.buildBaseMoveSelector(ChangeMoveSelectorConfig.java:64)
 at org.optaplanner.core.config.heuristic.selector.move.MoveSelectorConfig.buildMoveSelector(MoveSelectorConfig.java:189)
 at org.optaplanner.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig.buildBaseMoveSelector(UnionMoveSelectorConfig.java:75)
 at org.optaplanner.core.config.heuristic.selector.move.MoveSelectorConfig.buildMoveSelector(MoveSelectorConfig.java:189)
 at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildMoveSelector(LocalSearchPhaseConfig.java:143)
 at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildDecider(LocalSearchPhaseConfig.java:108)
 at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildPhase(LocalSearchPhaseConfig.java:93)
 at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildPhase(LocalSearchPhaseConfig.java:46)
 at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:205)
 at org.optaplanner.core.impl.solver.XStreamXmlSolverFactory.buildSolver(XStreamXmlSolverFactory.java:134)
 at org.optaplanner.examples.cloudbalancing.app.CloudBalancingHelloWorld.main(CloudBalancingHelloWorld.java:38)
------------------------------------------------------------------------
BUILD FAILURE

Here's the definition for the move selectors. Worked like a charm. I took a different approach to see if would work better than my original one. I did learn that the selection of the best entities and variables is not always obvious. I took a granular variable from my original solution and substituted it with a coarse entity and variable that couldn't be scored incrementally for any objective. The results were that the incremental scoring rules prevented the course entity and variable from changing state - and it wasn't possible to write a granular scoring rule. So, when defining entities and variables, they should be able to support granular/incremental scoring. My original approach generated the desired results.

    <localSearch>
    <unionMoveSelector>
        <changeMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.cloudbalancing.domain.Run</entityClass>
            </entitySelector>
            <valueSelector>
                <variableName>vehicle</variableName>
            </valueSelector>
        </changeMoveSelector>
        <swapMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.cloudbalancing.domain.Run</entityClass>
            </entitySelector>
        </swapMoveSelector>
        <changeMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.cloudbalancing.domain.School</entityClass>
            </entitySelector>
            <valueSelector>
                <variableName>startTime</variableName>
            </valueSelector>
        </changeMoveSelector>
        <swapMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.cloudbalancing.domain.School</entityClass>
            </entitySelector>
        </swapMoveSelector>
    </unionMoveSelector>

...

user2952819
  • 111
  • 8

1 Answers1

1

The exception happens in LocalSearchPhaseConfig.build...(), not in ConstructionHeuristicPhaseCondif.build...(), so it's an issue with your <localSearch> configuration, which isn't pasted here.

I suspect you're not configuring moveSelectors there and just relying on the out-of-the-box ones, which don't work ootb if there are multiple entity classes or variables (I made a jira for that).

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120