From e474d86befeddd9e8a9ff9ad78d5af097ebea7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Petrovick=C3=BD?= Date: Tue, 10 Dec 2024 12:53:30 +0100 Subject: [PATCH] chore: allow enabling DLAS as it says in the docs (#1268) --- .../SolverBenchmarkBluePrintType.java | 48 +++++++++++-------- benchmark/src/main/resources/benchmark.xsd | 3 ++ .../config/localsearch/LocalSearchType.java | 1 + .../DefaultLocalSearchPhaseFactory.java | 31 ++++-------- core/src/main/resources/solver.xsd | 2 + 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/benchmark/src/main/java/ai/timefold/solver/benchmark/config/blueprint/SolverBenchmarkBluePrintType.java b/benchmark/src/main/java/ai/timefold/solver/benchmark/config/blueprint/SolverBenchmarkBluePrintType.java index 0a55e3d8cb..15be1df619 100644 --- a/benchmark/src/main/java/ai/timefold/solver/benchmark/config/blueprint/SolverBenchmarkBluePrintType.java +++ b/benchmark/src/main/java/ai/timefold/solver/benchmark/config/blueprint/SolverBenchmarkBluePrintType.java @@ -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; @@ -35,20 +36,16 @@ public enum SolverBenchmarkBluePrintType { */ EVERY_CONSTRUCTION_HEURISTIC_TYPE_WITH_EVERY_LOCAL_SEARCH_TYPE; - protected @NonNull List 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 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 buildConstructionHeuristicWithAndWithoutLocalSearch() { @@ -68,10 +65,21 @@ private List buildEveryConstructionHeuristicType() { } private List buildEveryLocalSearchType() { + return buildEveryLocalSearchType(null); + } + + private List buildEveryLocalSearchType(ConstructionHeuristicType constructionHeuristicType) { LocalSearchType[] lsTypes = LocalSearchType.getBluePrintTypes(); List 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; } @@ -79,17 +87,15 @@ private List buildEveryLocalSearchType() { private List buildEveryConstructionHeuristicTypeWithEveryLocalSearchType() { ConstructionHeuristicType[] chTypes = ConstructionHeuristicType.getBluePrintTypes(); LocalSearchType[] lsTypes = LocalSearchType.getBluePrintTypes(); - List solverBenchmarkConfigList = new ArrayList<>( - chTypes.length * lsTypes.length); + List 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(); diff --git a/benchmark/src/main/resources/benchmark.xsd b/benchmark/src/main/resources/benchmark.xsd index 0bcae1ee66..953ad98344 100644 --- a/benchmark/src/main/resources/benchmark.xsd +++ b/benchmark/src/main/resources/benchmark.xsd @@ -3041,6 +3041,9 @@ + + + diff --git a/core/src/main/java/ai/timefold/solver/core/config/localsearch/LocalSearchType.java b/core/src/main/java/ai/timefold/solver/core/config/localsearch/LocalSearchType.java index be6df33c3d..47255cf370 100644 --- a/core/src/main/java/ai/timefold/solver/core/config/localsearch/LocalSearchType.java +++ b/core/src/main/java/ai/timefold/solver/core/config/localsearch/LocalSearchType.java @@ -12,6 +12,7 @@ public enum LocalSearchType { TABU_SEARCH, SIMULATED_ANNEALING, LATE_ACCEPTANCE, + DIVERSIFIED_LATE_ACCEPTANCE, GREAT_DELUGE, VARIABLE_NEIGHBORHOOD_DESCENT; diff --git a/core/src/main/java/ai/timefold/solver/core/impl/localsearch/DefaultLocalSearchPhaseFactory.java b/core/src/main/java/ai/timefold/solver/core/impl/localsearch/DefaultLocalSearchPhaseFactory.java index 1bcd67e5ea..08d06a7792 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/localsearch/DefaultLocalSearchPhaseFactory.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/localsearch/DefaultLocalSearchPhaseFactory.java @@ -107,27 +107,15 @@ protected Acceptor buildAcceptor(HeuristicConfigPolicy 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); } } @@ -161,6 +149,7 @@ protected LocalSearchForager buildForager(HeuristicConfigPolicy + +