Search code examples
javaoptaplannertimefold

Timefold: Is it possible to filter out all trivial 2opt moves for PlanningListVariable?


I'm trying to solve tsp with PlanningListVariable.

I've configured kOptMoves like this:

  <kOptListMoveSelector>
    <minimumK>2</minimumK>
    <maximumK>2</maximumK>
  </kOptListMoveSelector>

And I see in the log trivial moves with abs(firstEndpointIndex - secondEndpointIndex) <= 1.

For example:

2023-12-07 14:03:20,831 DEBUG [ai.tim.sol.cor.imp.loc.DefaultLocalSearchPhase] (pool-7-thread-1)     LS step (91293), time spent (60096), score (0hard/-20852279soft),     best score (0hard/-20852279soft), accepted/selected move count (1/192), picked move (2-Opt(firstEntity=salesman.mainModel.domain.Route@5ad597bf, secondEntity=salesman.mainModel.domain.Route@5ad597bf, firstEndpointIndex=99, secondEndpointIndex=99)).
2023-12-07 14:03:20,831 DEBUG [ai.tim.sol.cor.imp.loc.DefaultLocalSearchPhase] (pool-7-thread-1)     LS step (91294), time spent (60096), score (0hard/-20852279soft),     best score (0hard/-20852279soft), accepted/selected move count (1/51), picked move (2-Opt(firstEntity=salesman.mainModel.domain.Route@5ad597bf, secondEntity=salesman.mainModel.domain.Route@5ad597bf, firstEndpointIndex=8, secondEndpointIndex=7)).
2023-12-07 14:03:20,831 DEBUG [ai.tim.sol.cor.imp.loc.DefaultLocalSearchPhase] (pool-7-thread-1)     LS step (91295), time spent (60096), score (0hard/-20852279soft),     best score (0hard/-20852279soft), accepted/selected move count (1/92), picked move (2-Opt(firstEntity=salesman.mainModel.domain.Route@5ad597bf, secondEntity=salesman.mainModel.domain.Route@5ad597bf, firstEndpointIndex=96, secondEndpointIndex=95)).

I am quite sure these moves are trivial, so I want to filter them.

I know the common way to do that is to use filter-class with SelectionFilter interface. But the problem is KOptListMove class is not public, so I can't use it in my filter class. Is there another way?


Solution

  • You make a good point. We probably should've made the class public. What bothers me more though is that you even have to write a filter like this; these trivial situations should have been filtered out by default. Something to fix for the next version of Timefold Solver.

    At this time, I cannot think of a workaround.