public ConstructionHeuristicPhase buildPhase(int phaseIndex, HeuristicConfigPolicy solverConfigPolicy,
BestSolutionRecaller bestSolutionRecaller, Termination solverTermination) {
HeuristicConfigPolicy phaseConfigPolicy = solverConfigPolicy.createPhaseConfigPolicy();
phaseConfigPolicy.setReinitializeVariableFilterEnabled(true);
phaseConfigPolicy.setInitializedChainedValueFilterEnabled(true);
DefaultConstructionHeuristicPhase phase = new DefaultConstructionHeuristicPhase();
configurePhase(phase, phaseIndex, phaseConfigPolicy, bestSolutionRecaller, solverTermination);
phase.setDecider(buildDecider(phaseConfigPolicy, phase.getTermination()));
ConstructionHeuristicType constructionHeuristicType_ = constructionHeuristicType == null
? ConstructionHeuristicType.FIRST_FIT : constructionHeuristicType;
phaseConfigPolicy.setEntitySorterManner(entitySorterManner != null ? entitySorterManner
: constructionHeuristicType_.getDefaultEntitySorterManner());
phaseConfigPolicy.setValueSorterManner(valueSorterManner != null ? valueSorterManner
: constructionHeuristicType_.getDefaultValueSorterManner());
EntityPlacerConfig entityPlacerConfig;
if (ConfigUtils.isEmptyCollection(entityPlacerConfigList)) {
entityPlacerConfig = constructionHeuristicType_.newEntityPlacerConfig();
} else if (entityPlacerConfigList.size() == 1) {
entityPlacerConfig = entityPlacerConfigList.get(0);
if (constructionHeuristicType != null) {
throw new IllegalArgumentException("The constructionHeuristicType (" + constructionHeuristicType
+ ") should not be configured if the entityPlacerConfig (" + entityPlacerConfig
+ ") is explicitly configured.");
}
} else {
// TODO entityPlacerConfigList is only a List because of XStream limitations.
throw new IllegalArgumentException("The entityPlacerConfigList (" + entityPlacerConfigList
+ ") must be a singleton or empty. Use multiple " + ConstructionHeuristicPhaseConfig.class
+ " elements to initialize multiple entity classes.");
}
EntityPlacer entityPlacer = entityPlacerConfig.buildEntityPlacer(
phaseConfigPolicy, phase.getTermination());
phase.setEntityPlacer(entityPlacer);
EnvironmentMode environmentMode = phaseConfigPolicy.getEnvironmentMode();
if (environmentMode.isNonIntrusiveFullAsserted()) {
phase.setAssertStepScoreFromScratch(true);
}
if (environmentMode.isIntrusiveFastAsserted()) {
phase.setAssertExpectedStepScore(true);
}
return phase;
}