Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-1486

ValueSelectorConfig does not process filterClass declarations correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 8.2.0.Final
    • 7.21.0.Final
    • optaplanner-core
    • None
    • 2020 Week 52-03 (from Dec 21)
    • 1
    • Hide

      1. Add the following class to the cloud balancing example:

      package org.optaplanner.examples.cloudbalancing.optional.value;
      
      import org.optaplanner.core.impl.heuristic.selector.common.decorator.SelectionFilter;
      import org.optaplanner.core.impl.score.director.ScoreDirector;
      import org.optaplanner.examples.cloudbalancing.domain.CloudBalance;
      
      public class ExampleValueSelectorFilter implements SelectionFilter<CloudBalance, Object> {
          @Override
          public boolean accept(ScoreDirector<CloudBalance> scoreDirector, Object selection) {
              return true;
          }
      }
      

      2. Modify the configuration to include the following local search configuration:

        <localSearch>
          <changeMoveSelector>
            <valueSelector>
            <filterClass>org.optaplanner.examples.cloudbalancing.optional.value.ExampleValueSelectorFilter</filterClass>
            </valueSelector>
          </changeMoveSelector>
          <acceptor>
            <entityTabuSize>7</entityTabuSize>
          </acceptor>
          <forager>
            <acceptedCountLimit>1000</acceptedCountLimit>
          </forager>
        </localSearch>
      

      3. Run the example in debug with a breakpoint on the accept() method method of the ExampleValueSelectorFilter

      Expected outcome is that the breakpoint would be hit, and the planning values filtered.

      Show
      1. Add the following class to the cloud balancing example: package org.optaplanner.examples.cloudbalancing.optional.value; import org.optaplanner.core.impl.heuristic.selector.common.decorator.SelectionFilter; import org.optaplanner.core.impl.score.director.ScoreDirector; import org.optaplanner.examples.cloudbalancing.domain.CloudBalance; public class ExampleValueSelectorFilter implements SelectionFilter<CloudBalance, Object > { @Override public boolean accept(ScoreDirector<CloudBalance> scoreDirector, Object selection) { return true ; } } 2. Modify the configuration to include the following local search configuration: <localSearch> <changeMoveSelector> <valueSelector> <filterClass> org.optaplanner.examples.cloudbalancing.optional.value.ExampleValueSelectorFilter </filterClass> </valueSelector> </changeMoveSelector> <acceptor> <entityTabuSize> 7 </entityTabuSize> </acceptor> <forager> <acceptedCountLimit> 1000 </acceptedCountLimit> </forager> </localSearch> 3. Run the example in debug with a breakpoint on the accept() method method of the ExampleValueSelectorFilter Expected outcome is that the breakpoint would be hit, and the planning values filtered.
    • NEW
    • NEW

      The configuration is ignored when setting a filter class on a value selector, e.g.:

      <valueSelector>
            <filterClass>...Selector</filterClass>
      </valueSelector>
      

      As indicated in PLANNER-394 and in the docs, it should now be possible to configure a filterClass on a valueSelector.

      In the EntitySelectorConfig class, the filterClass is carried over during the inherit() method with the line:

              filterClassList = ConfigUtils.inheritOverwritableProperty(
                      filterClassList, inheritedConfig.getFilterClassList());
      

      This line doesn't appear in the ValueSelectorConfig, which causes the filter list to become null during phase initialization, and therefore the custom filters are never instantiated.

              rsynek@redhat.com Radovan Synek (Inactive)
              shaone Robert Hirst (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: