Skip to content

Commit

Permalink
chore: allow enabling DLAS as it says in the docs (#1268)
Browse files Browse the repository at this point in the history
  • Loading branch information
triceo authored Dec 10, 2024
1 parent d55c510 commit e474d86
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ai.timefold.solver.core.config.localsearch.LocalSearchPhaseConfig;
import ai.timefold.solver.core.config.localsearch.LocalSearchType;
import ai.timefold.solver.core.config.phase.PhaseConfig;
import ai.timefold.solver.core.config.solver.PreviewFeature;
import ai.timefold.solver.core.config.solver.SolverConfig;

import org.jspecify.annotations.NonNull;
Expand All @@ -35,20 +36,16 @@ public enum SolverBenchmarkBluePrintType {
*/
EVERY_CONSTRUCTION_HEURISTIC_TYPE_WITH_EVERY_LOCAL_SEARCH_TYPE;

protected @NonNull List<SolverBenchmarkConfig> buildSolverBenchmarkConfigList() {
switch (this) {
case CONSTRUCTION_HEURISTIC_WITH_AND_WITHOUT_LOCAL_SEARCH:
return buildConstructionHeuristicWithAndWithoutLocalSearch();
case EVERY_CONSTRUCTION_HEURISTIC_TYPE:
return buildEveryConstructionHeuristicType();
case EVERY_LOCAL_SEARCH_TYPE:
return buildEveryLocalSearchType();
case EVERY_CONSTRUCTION_HEURISTIC_TYPE_WITH_EVERY_LOCAL_SEARCH_TYPE:
return buildEveryConstructionHeuristicTypeWithEveryLocalSearchType();
default:
throw new IllegalStateException("The solverBenchmarkBluePrintType ("
+ this + ") is not implemented.");
}
@NonNull
List<SolverBenchmarkConfig> buildSolverBenchmarkConfigList() {
return switch (this) {
case CONSTRUCTION_HEURISTIC_WITH_AND_WITHOUT_LOCAL_SEARCH ->
buildConstructionHeuristicWithAndWithoutLocalSearch();
case EVERY_CONSTRUCTION_HEURISTIC_TYPE -> buildEveryConstructionHeuristicType();
case EVERY_LOCAL_SEARCH_TYPE -> buildEveryLocalSearchType();
case EVERY_CONSTRUCTION_HEURISTIC_TYPE_WITH_EVERY_LOCAL_SEARCH_TYPE ->
buildEveryConstructionHeuristicTypeWithEveryLocalSearchType();
};
}

private List<SolverBenchmarkConfig> buildConstructionHeuristicWithAndWithoutLocalSearch() {
Expand All @@ -68,28 +65,37 @@ private List<SolverBenchmarkConfig> buildEveryConstructionHeuristicType() {
}

private List<SolverBenchmarkConfig> buildEveryLocalSearchType() {
return buildEveryLocalSearchType(null);
}

private List<SolverBenchmarkConfig> buildEveryLocalSearchType(ConstructionHeuristicType constructionHeuristicType) {
LocalSearchType[] lsTypes = LocalSearchType.getBluePrintTypes();
List<SolverBenchmarkConfig> solverBenchmarkConfigList = new ArrayList<>(lsTypes.length);
for (LocalSearchType lsType : lsTypes) {
solverBenchmarkConfigList.add(buildSolverBenchmarkConfig(null, true, lsType));
if (PreviewFeature.DIVERSIFIED_LATE_ACCEPTANCE != null && lsType == LocalSearchType.DIVERSIFIED_LATE_ACCEPTANCE) {
// When the preview feature is removed, this will fail at compile time
// and the code will have to be adjusted.
// Most likely, the preview feature will be promoted to a regular feature,
// and this if statement will be removed.
continue;
}
solverBenchmarkConfigList.add(buildSolverBenchmarkConfig(constructionHeuristicType, true, lsType));
}
return solverBenchmarkConfigList;
}

private List<SolverBenchmarkConfig> buildEveryConstructionHeuristicTypeWithEveryLocalSearchType() {
ConstructionHeuristicType[] chTypes = ConstructionHeuristicType.getBluePrintTypes();
LocalSearchType[] lsTypes = LocalSearchType.getBluePrintTypes();
List<SolverBenchmarkConfig> solverBenchmarkConfigList = new ArrayList<>(
chTypes.length * lsTypes.length);
List<SolverBenchmarkConfig> solverBenchmarkConfigList = new ArrayList<>(chTypes.length * lsTypes.length);
for (ConstructionHeuristicType chType : chTypes) {
for (LocalSearchType lsType : lsTypes) {
solverBenchmarkConfigList.add(buildSolverBenchmarkConfig(chType, true, lsType));
}
solverBenchmarkConfigList.addAll(buildEveryLocalSearchType(chType));
}
return solverBenchmarkConfigList;
}

protected @NonNull SolverBenchmarkConfig buildSolverBenchmarkConfig(
@NonNull
private SolverBenchmarkConfig buildSolverBenchmarkConfig(
@Nullable ConstructionHeuristicType constructionHeuristicType,
boolean localSearchEnabled, @Nullable LocalSearchType localSearchType) {
SolverBenchmarkConfig solverBenchmarkConfig = new SolverBenchmarkConfig();
Expand Down
3 changes: 3 additions & 0 deletions benchmark/src/main/resources/benchmark.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -3041,6 +3041,9 @@
<xs:enumeration value="LATE_ACCEPTANCE"/>


<xs:enumeration value="DIVERSIFIED_LATE_ACCEPTANCE"/>


<xs:enumeration value="GREAT_DELUGE"/>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum LocalSearchType {
TABU_SEARCH,
SIMULATED_ANNEALING,
LATE_ACCEPTANCE,
DIVERSIFIED_LATE_ACCEPTANCE,
GREAT_DELUGE,
VARIABLE_NEIGHBORHOOD_DESCENT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,15 @@ protected Acceptor<Solution_> buildAcceptor(HeuristicConfigPolicy<Solution_> con
} else {
var localSearchType_ = Objects.requireNonNullElse(localSearchType, LocalSearchType.LATE_ACCEPTANCE);
var acceptorConfig_ = new LocalSearchAcceptorConfig();
switch (localSearchType_) {
case HILL_CLIMBING:
case VARIABLE_NEIGHBORHOOD_DESCENT:
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.HILL_CLIMBING));
break;
case TABU_SEARCH:
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.ENTITY_TABU));
break;
case SIMULATED_ANNEALING:
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.SIMULATED_ANNEALING));
break;
case LATE_ACCEPTANCE:
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.LATE_ACCEPTANCE));
break;
case GREAT_DELUGE:
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.GREAT_DELUGE));
break;
default:
throw new IllegalStateException("The localSearchType (" + localSearchType_
+ ") is not implemented.");
}
var acceptorType = switch (localSearchType_) {
case HILL_CLIMBING, VARIABLE_NEIGHBORHOOD_DESCENT -> AcceptorType.HILL_CLIMBING;
case TABU_SEARCH -> AcceptorType.ENTITY_TABU;
case SIMULATED_ANNEALING -> AcceptorType.SIMULATED_ANNEALING;
case LATE_ACCEPTANCE -> AcceptorType.LATE_ACCEPTANCE;
case DIVERSIFIED_LATE_ACCEPTANCE -> AcceptorType.DIVERSIFIED_LATE_ACCEPTANCE;
case GREAT_DELUGE -> AcceptorType.GREAT_DELUGE;
};
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(acceptorType));
return buildAcceptor(acceptorConfig_, configPolicy);
}
}
Expand Down Expand Up @@ -161,6 +149,7 @@ protected LocalSearchForager<Solution_> buildForager(HeuristicConfigPolicy<Solut
break;
case SIMULATED_ANNEALING:
case LATE_ACCEPTANCE:
case DIVERSIFIED_LATE_ACCEPTANCE:
case GREAT_DELUGE:
// Fast stepping algorithm
foragerConfig_.setAcceptedCountLimit(1);
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/solver.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,8 @@

<xs:enumeration value="LATE_ACCEPTANCE"/>

<xs:enumeration value="DIVERSIFIED_LATE_ACCEPTANCE"/>

<xs:enumeration value="GREAT_DELUGE"/>

<xs:enumeration value="VARIABLE_NEIGHBORHOOD_DESCENT"/>
Expand Down

0 comments on commit e474d86

Please sign in to comment.