Skip to content

Commit e474d86

Browse files
authored
chore: allow enabling DLAS as it says in the docs (#1268)
1 parent d55c510 commit e474d86

File tree

5 files changed

+43
-42
lines changed

5 files changed

+43
-42
lines changed

benchmark/src/main/java/ai/timefold/solver/benchmark/config/blueprint/SolverBenchmarkBluePrintType.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import ai.timefold.solver.core.config.localsearch.LocalSearchPhaseConfig;
1212
import ai.timefold.solver.core.config.localsearch.LocalSearchType;
1313
import ai.timefold.solver.core.config.phase.PhaseConfig;
14+
import ai.timefold.solver.core.config.solver.PreviewFeature;
1415
import ai.timefold.solver.core.config.solver.SolverConfig;
1516

1617
import org.jspecify.annotations.NonNull;
@@ -35,20 +36,16 @@ public enum SolverBenchmarkBluePrintType {
3536
*/
3637
EVERY_CONSTRUCTION_HEURISTIC_TYPE_WITH_EVERY_LOCAL_SEARCH_TYPE;
3738

38-
protected @NonNull List<SolverBenchmarkConfig> buildSolverBenchmarkConfigList() {
39-
switch (this) {
40-
case CONSTRUCTION_HEURISTIC_WITH_AND_WITHOUT_LOCAL_SEARCH:
41-
return buildConstructionHeuristicWithAndWithoutLocalSearch();
42-
case EVERY_CONSTRUCTION_HEURISTIC_TYPE:
43-
return buildEveryConstructionHeuristicType();
44-
case EVERY_LOCAL_SEARCH_TYPE:
45-
return buildEveryLocalSearchType();
46-
case EVERY_CONSTRUCTION_HEURISTIC_TYPE_WITH_EVERY_LOCAL_SEARCH_TYPE:
47-
return buildEveryConstructionHeuristicTypeWithEveryLocalSearchType();
48-
default:
49-
throw new IllegalStateException("The solverBenchmarkBluePrintType ("
50-
+ this + ") is not implemented.");
51-
}
39+
@NonNull
40+
List<SolverBenchmarkConfig> buildSolverBenchmarkConfigList() {
41+
return switch (this) {
42+
case CONSTRUCTION_HEURISTIC_WITH_AND_WITHOUT_LOCAL_SEARCH ->
43+
buildConstructionHeuristicWithAndWithoutLocalSearch();
44+
case EVERY_CONSTRUCTION_HEURISTIC_TYPE -> buildEveryConstructionHeuristicType();
45+
case EVERY_LOCAL_SEARCH_TYPE -> buildEveryLocalSearchType();
46+
case EVERY_CONSTRUCTION_HEURISTIC_TYPE_WITH_EVERY_LOCAL_SEARCH_TYPE ->
47+
buildEveryConstructionHeuristicTypeWithEveryLocalSearchType();
48+
};
5249
}
5350

5451
private List<SolverBenchmarkConfig> buildConstructionHeuristicWithAndWithoutLocalSearch() {
@@ -68,28 +65,37 @@ private List<SolverBenchmarkConfig> buildEveryConstructionHeuristicType() {
6865
}
6966

7067
private List<SolverBenchmarkConfig> buildEveryLocalSearchType() {
68+
return buildEveryLocalSearchType(null);
69+
}
70+
71+
private List<SolverBenchmarkConfig> buildEveryLocalSearchType(ConstructionHeuristicType constructionHeuristicType) {
7172
LocalSearchType[] lsTypes = LocalSearchType.getBluePrintTypes();
7273
List<SolverBenchmarkConfig> solverBenchmarkConfigList = new ArrayList<>(lsTypes.length);
7374
for (LocalSearchType lsType : lsTypes) {
74-
solverBenchmarkConfigList.add(buildSolverBenchmarkConfig(null, true, lsType));
75+
if (PreviewFeature.DIVERSIFIED_LATE_ACCEPTANCE != null && lsType == LocalSearchType.DIVERSIFIED_LATE_ACCEPTANCE) {
76+
// When the preview feature is removed, this will fail at compile time
77+
// and the code will have to be adjusted.
78+
// Most likely, the preview feature will be promoted to a regular feature,
79+
// and this if statement will be removed.
80+
continue;
81+
}
82+
solverBenchmarkConfigList.add(buildSolverBenchmarkConfig(constructionHeuristicType, true, lsType));
7583
}
7684
return solverBenchmarkConfigList;
7785
}
7886

7987
private List<SolverBenchmarkConfig> buildEveryConstructionHeuristicTypeWithEveryLocalSearchType() {
8088
ConstructionHeuristicType[] chTypes = ConstructionHeuristicType.getBluePrintTypes();
8189
LocalSearchType[] lsTypes = LocalSearchType.getBluePrintTypes();
82-
List<SolverBenchmarkConfig> solverBenchmarkConfigList = new ArrayList<>(
83-
chTypes.length * lsTypes.length);
90+
List<SolverBenchmarkConfig> solverBenchmarkConfigList = new ArrayList<>(chTypes.length * lsTypes.length);
8491
for (ConstructionHeuristicType chType : chTypes) {
85-
for (LocalSearchType lsType : lsTypes) {
86-
solverBenchmarkConfigList.add(buildSolverBenchmarkConfig(chType, true, lsType));
87-
}
92+
solverBenchmarkConfigList.addAll(buildEveryLocalSearchType(chType));
8893
}
8994
return solverBenchmarkConfigList;
9095
}
9196

92-
protected @NonNull SolverBenchmarkConfig buildSolverBenchmarkConfig(
97+
@NonNull
98+
private SolverBenchmarkConfig buildSolverBenchmarkConfig(
9399
@Nullable ConstructionHeuristicType constructionHeuristicType,
94100
boolean localSearchEnabled, @Nullable LocalSearchType localSearchType) {
95101
SolverBenchmarkConfig solverBenchmarkConfig = new SolverBenchmarkConfig();

benchmark/src/main/resources/benchmark.xsd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,9 @@
30413041
<xs:enumeration value="LATE_ACCEPTANCE"/>
30423042

30433043

3044+
<xs:enumeration value="DIVERSIFIED_LATE_ACCEPTANCE"/>
3045+
3046+
30443047
<xs:enumeration value="GREAT_DELUGE"/>
30453048

30463049

core/src/main/java/ai/timefold/solver/core/config/localsearch/LocalSearchType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public enum LocalSearchType {
1212
TABU_SEARCH,
1313
SIMULATED_ANNEALING,
1414
LATE_ACCEPTANCE,
15+
DIVERSIFIED_LATE_ACCEPTANCE,
1516
GREAT_DELUGE,
1617
VARIABLE_NEIGHBORHOOD_DESCENT;
1718

core/src/main/java/ai/timefold/solver/core/impl/localsearch/DefaultLocalSearchPhaseFactory.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,15 @@ protected Acceptor<Solution_> buildAcceptor(HeuristicConfigPolicy<Solution_> con
107107
} else {
108108
var localSearchType_ = Objects.requireNonNullElse(localSearchType, LocalSearchType.LATE_ACCEPTANCE);
109109
var acceptorConfig_ = new LocalSearchAcceptorConfig();
110-
switch (localSearchType_) {
111-
case HILL_CLIMBING:
112-
case VARIABLE_NEIGHBORHOOD_DESCENT:
113-
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.HILL_CLIMBING));
114-
break;
115-
case TABU_SEARCH:
116-
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.ENTITY_TABU));
117-
break;
118-
case SIMULATED_ANNEALING:
119-
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.SIMULATED_ANNEALING));
120-
break;
121-
case LATE_ACCEPTANCE:
122-
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.LATE_ACCEPTANCE));
123-
break;
124-
case GREAT_DELUGE:
125-
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(AcceptorType.GREAT_DELUGE));
126-
break;
127-
default:
128-
throw new IllegalStateException("The localSearchType (" + localSearchType_
129-
+ ") is not implemented.");
130-
}
110+
var acceptorType = switch (localSearchType_) {
111+
case HILL_CLIMBING, VARIABLE_NEIGHBORHOOD_DESCENT -> AcceptorType.HILL_CLIMBING;
112+
case TABU_SEARCH -> AcceptorType.ENTITY_TABU;
113+
case SIMULATED_ANNEALING -> AcceptorType.SIMULATED_ANNEALING;
114+
case LATE_ACCEPTANCE -> AcceptorType.LATE_ACCEPTANCE;
115+
case DIVERSIFIED_LATE_ACCEPTANCE -> AcceptorType.DIVERSIFIED_LATE_ACCEPTANCE;
116+
case GREAT_DELUGE -> AcceptorType.GREAT_DELUGE;
117+
};
118+
acceptorConfig_.setAcceptorTypeList(Collections.singletonList(acceptorType));
131119
return buildAcceptor(acceptorConfig_, configPolicy);
132120
}
133121
}
@@ -161,6 +149,7 @@ protected LocalSearchForager<Solution_> buildForager(HeuristicConfigPolicy<Solut
161149
break;
162150
case SIMULATED_ANNEALING:
163151
case LATE_ACCEPTANCE:
152+
case DIVERSIFIED_LATE_ACCEPTANCE:
164153
case GREAT_DELUGE:
165154
// Fast stepping algorithm
166155
foragerConfig_.setAcceptedCountLimit(1);

core/src/main/resources/solver.xsd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,8 @@
18531853

18541854
<xs:enumeration value="LATE_ACCEPTANCE"/>
18551855

1856+
<xs:enumeration value="DIVERSIFIED_LATE_ACCEPTANCE"/>
1857+
18561858
<xs:enumeration value="GREAT_DELUGE"/>
18571859

18581860
<xs:enumeration value="VARIABLE_NEIGHBORHOOD_DESCENT"/>

0 commit comments

Comments
 (0)