Skip to content

Commit

Permalink
PLANNER-1238 fail fast if move type doesn't support phase caching and…
Browse files Browse the repository at this point in the history
… used as such
  • Loading branch information
ge0ffrey committed Sep 5, 2018
1 parent 8aa10f7 commit 1895ad8
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 0 deletions.
Expand Up @@ -194,6 +194,7 @@ public MoveSelector buildMoveSelector(HeuristicConfigPolicy configPolicy,
MoveSelector moveSelector = buildBaseMoveSelector(configPolicy,
SelectionCacheType.max(minimumCacheType, resolvedCacheType),
determineBaseRandomSelection(resolvedCacheType, resolvedSelectionOrder));
validateResolvedCacheType(resolvedCacheType, moveSelector);

moveSelector = applyFiltering(resolvedCacheType, resolvedSelectionOrder, moveSelector);
moveSelector = applySorting(resolvedCacheType, resolvedSelectionOrder, moveSelector);
Expand All @@ -204,6 +205,15 @@ public MoveSelector buildMoveSelector(HeuristicConfigPolicy configPolicy,
return moveSelector;
}

private void validateResolvedCacheType(SelectionCacheType resolvedCacheType, MoveSelector moveSelector) {
if (!moveSelector.supportsPhaseAndSolverCaching()
&& resolvedCacheType.compareTo(SelectionCacheType.PHASE) >= 0) {
throw new IllegalArgumentException("The moveSelectorConfig (" + this
+ ") has a resolvedCacheType (" + resolvedCacheType + ") that is not supported.\n"
+ "Maybe don't use a <cacheType> on this type of moveSelector.");
}
}

/**
* @param configPolicy never null
* @return null if no unfolding is needed
Expand Down
Expand Up @@ -25,4 +25,8 @@
*/
public interface MoveSelector extends IterableSelector<Move> {

default boolean supportsPhaseAndSolverCaching() {
return false;
}

}
Expand Up @@ -67,6 +67,11 @@ public List<MoveSelector> getChildMoveSelectorList() {
return childMoveSelectorList;
}

@Override
public boolean supportsPhaseAndSolverCaching() {
return true;
}

// ************************************************************************
// Worker methods
// ************************************************************************
Expand Down
Expand Up @@ -39,6 +39,11 @@ public MoveIteratorFactoryToMoveSelectorBridge(MoveIteratorFactory moveIteratorF
this.randomSelection = randomSelection;
}

@Override
public boolean supportsPhaseAndSolverCaching() {
return true;
}

// ************************************************************************
// Worker methods
// ************************************************************************
Expand Down
Expand Up @@ -57,6 +57,11 @@ public SelectionCacheType getCacheType() {
return cacheType;
}

@Override
public boolean supportsPhaseAndSolverCaching() {
return true;
}

// ************************************************************************
// Worker methods
// ************************************************************************
Expand Down
Expand Up @@ -51,6 +51,11 @@ public ChangeMoveSelector(EntitySelector entitySelector, ValueSelector valueSele
phaseLifecycleSupport.addEventListener(valueSelector);
}

@Override
public boolean supportsPhaseAndSolverCaching() {
return !chained;
}

@Override
public void solvingStarted(DefaultSolverScope solverScope) {
super.solvingStarted(solverScope);
Expand Down
Expand Up @@ -81,6 +81,11 @@ public SwapMoveSelector(EntitySelector leftEntitySelector, EntitySelector rightE
}
}

@Override
public boolean supportsPhaseAndSolverCaching() {
return !anyChained;
}

@Override
public void solvingStarted(DefaultSolverScope solverScope) {
super.solvingStarted(solverScope);
Expand Down
Expand Up @@ -171,6 +171,7 @@ public static MoveSelector mockMoveSelector(Class<?> moveClass,
when(moveSelector.isNeverEnding()).thenReturn(false);
when(moveSelector.getCacheType()).thenReturn(SelectionCacheType.JUST_IN_TIME);
when(moveSelector.getSize()).thenReturn((long) moveList.size());
when(moveSelector.supportsPhaseAndSolverCaching()).thenReturn(true);
return moveSelector;
}

Expand Down

0 comments on commit 1895ad8

Please sign in to comment.