Pravesh Jain
Pravesh Jain

Reputation: 4288

Optaplanner : dynamic termination config

I want to configure my termination strategy dynamically. My intention is that the solver should terminate when either it has tried 10k steps or when the score has not improved for 4k steps. For that I am setting the phases in config as follows:

<constructionHeuristic></constructionHeuristic>
<localSearch></localSearch>

And then before starting the solver, I set

TerminationConfig terminationConfig = new TerminationConfig();
terminationConfig.setTerminationCompositionStyle(TerminationCompositionStyle.OR);
terminationConfig.setUnimprovedStepCountLimit(4000);
terminationConfig.setStepCountLimit(10000);

LocalSearchPhaseConfig localSearchPhaseConfig = (LocalSearchPhaseConfig) solverFactory.getSolverConfig().getPhaseConfigList().get(1);
localSearchPhaseConfig.setTerminationConfig(terminationConfig);

I tried keeping the value of unimprovedStepCount as 1 but it still does not terminate after 30-40 minutes. How can I define this config?

Also, do I need to define the constructionHeuristic and constructionHeuristic in the xml config explicitly or are they inferred by default?

Upvotes: 0

Views: 225

Answers (2)

Pravesh Jain
Pravesh Jain

Reputation: 4288

The problem was in my SelectionFilter. There was a bug such that the accept method of SelectionFilter was always returning false and hence the local search phase was not progressing at all.

After resolving it, the dynamic termination config works as it is.

Upvotes: 0

k88
k88

Reputation: 1934

Isn't it this ?

  <localSearch>
    <termination>
      <terminationCompositionStyle>OR</terminationCompositionStyle>
      <unimprovedStepCountLimit>4000</unimprovedStepCountLimit>
      <stepCountLimit>10000</stepCountLimit>
    </termination>
  </localSearch>

If you don't define a CH the default is FIRST_FIT I believe.

Upvotes: 1

Related Questions