javaconfigurationoptaplannerdrools-planner

OptaPlanner : ValueSelector can not use ValueRangeType.FROM_PLANNING_ENTITY_PROPERTY


I am using MoveSelector configuration in the ConstructionHeuristic Phase. It works fine with configuring filterClass and comparatorClass in EntitySelector.

However, in ValueSelector session, I am not able to use "ValueRangeType.FROM_PLANNING_ENTITY_PROPERTY" planning variable. It throws this exception: java.lang.IllegalArgumentException: The valueSelectorConfig (ValueSelectorConfig(row)) with resolvedCacheType (PHASE) and resolvedSelectionOrder (SORTED) needs to be based on a EntityIndependentValueSelector (FromEntityPropertyValueSelector(row)). Check your @ValueRangeProvider annotations.

Example NQueen Config: ...

<changeMoveSelector>
    <entitySelector mimicSelectorRef="placerEntitySelector">
    </entitySelector>
    <valueSelector>
       <variableName>row</variableName>
       <cacheType>PHASE</cacheType>
       <selectionOrder>SORTED</selectionOrder>
       <sorterComparatorClass>..RowWeightStrength</sorterComparatorClass>
    </valueSelector>
</changeMoveSelector>

....

** I need to use the valueRange depends on my planning Entity in order to use PossibleRowList for each Queen (for the performance sake) Any suggestion please? Thanks in advance.


Solution

  • That valueSelector is SORTED, so it needs to cache (to be able to sort them). But caching with a @ValueRangeProvider per entity is not supported if I recall correctly.

    This implies that the CH with a @ValueRangeProvider per entity only supports FIRST_FIT and FIRST_FIT_DECREASING, but not WEAKEST_FIT or STRONGEST_FIT. I believe there's a jira for this already (do link it here if you find it). We need to fix this.

    Meanwhile: a workaround would be to not use SORTED, but already sort them in each entity's value range list.