Skip to content

Commit 28c4966

Browse files
committed
chore: add optimization profiles
1 parent 21dc302 commit 28c4966

22 files changed

Lines changed: 321 additions & 336 deletions

core/src/main/java/ai/timefold/solver/core/config/evolutionaryalgorithm/EvolutionaryAlgorithmPhaseConfig.java

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,24 @@
1111
import org.jspecify.annotations.Nullable;
1212

1313
@XmlType(propOrder = {
14-
"complexProblem",
15-
"agentCount",
1614
"populationConfig",
17-
"evolutionaryAgentConfig",
15+
"workerConfig",
1816
})
1917
@NullMarked
2018
public class EvolutionaryAlgorithmPhaseConfig extends PhaseConfig<EvolutionaryAlgorithmPhaseConfig> {
2119

2220
public static final String XML_ELEMENT_NAME = "evolutionaryAlgorithm";
2321

24-
@Nullable
25-
private Boolean complexProblem;
26-
27-
@Nullable
28-
private Integer agentCount;
29-
3022
@Nullable
3123
private EvolutionaryPopulationConfig populationConfig = null;
3224

3325
@Nullable
34-
private EvolutionaryAgentConfig evolutionaryAgentConfig = null;
26+
private EvolutionaryWorkerConfig workerConfig = null;
3527

3628
// ************************************************************************
3729
// Constructors and simple getters/setters
3830
// ************************************************************************
3931

40-
public @Nullable Boolean getComplexProblem() {
41-
return complexProblem;
42-
}
43-
44-
public void setComplexProblem(@Nullable Boolean complexProblem) {
45-
this.complexProblem = complexProblem;
46-
}
47-
48-
public @Nullable Integer getAgentCount() {
49-
return agentCount;
50-
}
51-
52-
public void setAgentCount(@Nullable Integer agentCount) {
53-
this.agentCount = agentCount;
54-
}
55-
5632
public @Nullable EvolutionaryPopulationConfig getPopulationConfig() {
5733
return populationConfig;
5834
}
@@ -61,46 +37,33 @@ public void setPopulationConfig(@Nullable EvolutionaryPopulationConfig populatio
6137
this.populationConfig = populationConfig;
6238
}
6339

64-
public @Nullable EvolutionaryAgentConfig getEvolutionaryAgentConfig() {
65-
return evolutionaryAgentConfig;
40+
public @Nullable EvolutionaryWorkerConfig getWorkerConfig() {
41+
return workerConfig;
6642
}
6743

68-
public void setEvolutionaryAgentConfig(@Nullable EvolutionaryAgentConfig evolutionaryAgentConfig) {
69-
this.evolutionaryAgentConfig = evolutionaryAgentConfig;
44+
public void setWorkerConfig(@Nullable EvolutionaryWorkerConfig workerConfig) {
45+
this.workerConfig = workerConfig;
7046
}
7147

7248
// ************************************************************************
7349
// With methods
7450
// ************************************************************************
7551

76-
public EvolutionaryAlgorithmPhaseConfig withComplexProblem(Boolean complexProblem) {
77-
setComplexProblem(complexProblem);
78-
return this;
79-
}
80-
81-
public EvolutionaryAlgorithmPhaseConfig withAgentCount(Integer agentCount) {
82-
setAgentCount(agentCount);
83-
return this;
84-
}
85-
8652
public EvolutionaryAlgorithmPhaseConfig withPopulationConfig(EvolutionaryPopulationConfig populationConfig) {
8753
setPopulationConfig(populationConfig);
8854
return this;
8955
}
9056

91-
public EvolutionaryAlgorithmPhaseConfig withEvolutionaryAgentConfig(EvolutionaryAgentConfig evolutionaryAgentConfig) {
92-
setEvolutionaryAgentConfig(evolutionaryAgentConfig);
57+
public EvolutionaryAlgorithmPhaseConfig withWorkerConfig(EvolutionaryWorkerConfig workerConfig) {
58+
setWorkerConfig(workerConfig);
9359
return this;
9460
}
9561

9662
@Override
9763
public EvolutionaryAlgorithmPhaseConfig inherit(EvolutionaryAlgorithmPhaseConfig inheritedConfig) {
9864
super.inherit(inheritedConfig);
99-
complexProblem = ConfigUtils.inheritOverwritableProperty(complexProblem, inheritedConfig.getComplexProblem());
100-
agentCount = ConfigUtils.inheritOverwritableProperty(agentCount, inheritedConfig.getAgentCount());
10165
populationConfig = ConfigUtils.inheritConfig(populationConfig, inheritedConfig.getPopulationConfig());
102-
evolutionaryAgentConfig =
103-
ConfigUtils.inheritConfig(evolutionaryAgentConfig, inheritedConfig.getEvolutionaryAgentConfig());
66+
workerConfig = ConfigUtils.inheritConfig(workerConfig, inheritedConfig.getWorkerConfig());
10467
return this;
10568
}
10669

@@ -114,8 +77,8 @@ public void visitReferencedClasses(Consumer<@Nullable Class<?>> classVisitor) {
11477
if (populationConfig != null) {
11578
populationConfig.visitReferencedClasses(classVisitor);
11679
}
117-
if (evolutionaryAgentConfig != null) {
118-
evolutionaryAgentConfig.visitReferencedClasses(classVisitor);
80+
if (workerConfig != null) {
81+
workerConfig.visitReferencedClasses(classVisitor);
11982
}
12083
}
12184
}

core/src/main/java/ai/timefold/solver/core/config/evolutionaryalgorithm/EvolutionaryIndividualGeneratorConfig.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@
1818
import org.jspecify.annotations.Nullable;
1919

2020
@XmlType(propOrder = {
21-
"inheritanceRate",
2221
"customPhaseCommandClassList",
2322
"customProperties",
2423
"constructionHeuristic"
2524
})
2625
@NullMarked
2726
public class EvolutionaryIndividualGeneratorConfig extends PhaseConfig<EvolutionaryIndividualGeneratorConfig> {
2827

29-
@Nullable
30-
private Double inheritanceRate = null;
31-
3228
@XmlElement(name = "customPhaseCommandClass")
3329
@Nullable
3430
private List<Class<? extends PhaseCommand>> customPhaseCommandClassList = null;
@@ -44,14 +40,6 @@ public class EvolutionaryIndividualGeneratorConfig extends PhaseConfig<Evolution
4440
// Constructors and simple getters/setters
4541
// ************************************************************************
4642

47-
public @Nullable Double getInheritanceRate() {
48-
return inheritanceRate;
49-
}
50-
51-
public void setInheritanceRate(@Nullable Double inheritanceRate) {
52-
this.inheritanceRate = inheritanceRate;
53-
}
54-
5543
public @Nullable List<Class<? extends PhaseCommand>> getCustomPhaseCommandClassList() {
5644
return customPhaseCommandClassList;
5745
}
@@ -81,11 +69,6 @@ public void setConstructionHeuristic(@Nullable ConstructionHeuristicPhaseConfig
8169
// With methods
8270
// ************************************************************************
8371

84-
public EvolutionaryIndividualGeneratorConfig withInheritanceRate(@Nullable Double inheritanceRate) {
85-
setInheritanceRate(inheritanceRate);
86-
return this;
87-
}
88-
8972
public EvolutionaryIndividualGeneratorConfig withCustomPhaseCommandClassList(
9073
List<Class<? extends PhaseCommand>> customPhaseCommandClassList) {
9174
setCustomPhaseCommandClassList(customPhaseCommandClassList);
@@ -106,7 +89,6 @@ public EvolutionaryIndividualGeneratorConfig withCustomProperties(Map<String, St
10689
@Override
10790
public EvolutionaryIndividualGeneratorConfig inherit(EvolutionaryIndividualGeneratorConfig inheritedConfig) {
10891
super.inherit(inheritedConfig);
109-
inheritanceRate = ConfigUtils.inheritOverwritableProperty(inheritanceRate, inheritedConfig.getInheritanceRate());
11092
customPhaseCommandClassList = ConfigUtils.inheritMergeableListProperty(customPhaseCommandClassList,
11193
inheritedConfig.getCustomPhaseCommandClassList());
11294
customProperties = ConfigUtils.inheritMergeableMapProperty(customProperties, inheritedConfig.getCustomProperties());

core/src/main/java/ai/timefold/solver/core/config/evolutionaryalgorithm/EvolutionaryLocalSearchConfig.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,18 @@
1212
import org.jspecify.annotations.Nullable;
1313

1414
@XmlType(propOrder = {
15-
"inheritanceRate",
1615
"localSearch",
1716
})
1817
@NullMarked
1918
public class EvolutionaryLocalSearchConfig extends PhaseConfig<EvolutionaryLocalSearchConfig> {
2019

21-
@Nullable
22-
private Double inheritanceRate = null;
23-
2420
@Nullable
2521
private LocalSearchPhaseConfig localSearch = null;
2622

2723
// ************************************************************************
2824
// Constructors and simple getters/setters
2925
// ************************************************************************
3026

31-
public @Nullable Double getInheritanceRate() {
32-
return inheritanceRate;
33-
}
34-
35-
public void setInheritanceRate(@Nullable Double inheritanceRate) {
36-
this.inheritanceRate = inheritanceRate;
37-
}
38-
3927
public @Nullable LocalSearchPhaseConfig getLocalSearch() {
4028
return localSearch;
4129
}
@@ -48,11 +36,6 @@ public void setLocalSearch(@Nullable LocalSearchPhaseConfig localSearch) {
4836
// With methods
4937
// ************************************************************************
5038

51-
public EvolutionaryLocalSearchConfig withInheritanceRate(@Nullable Double inheritanceRate) {
52-
setInheritanceRate(inheritanceRate);
53-
return this;
54-
}
55-
5639
public EvolutionaryLocalSearchConfig withLocalSearch(LocalSearchPhaseConfig localSearch) {
5740
setLocalSearch(localSearch);
5841
return this;
@@ -61,7 +44,6 @@ public EvolutionaryLocalSearchConfig withLocalSearch(LocalSearchPhaseConfig loca
6144
@Override
6245
public EvolutionaryLocalSearchConfig inherit(EvolutionaryLocalSearchConfig inheritedConfig) {
6346
super.inherit(inheritedConfig);
64-
inheritanceRate = ConfigUtils.inheritOverwritableProperty(inheritanceRate, inheritedConfig.getInheritanceRate());
6547
localSearch = ConfigUtils.inheritConfig(localSearch, inheritedConfig.getLocalSearch());
6648
return this;
6749
}

core/src/main/java/ai/timefold/solver/core/config/evolutionaryalgorithm/EvolutionaryAgentConfig.java renamed to core/src/main/java/ai/timefold/solver/core/config/evolutionaryalgorithm/EvolutionaryWorkerConfig.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
import org.jspecify.annotations.Nullable;
1212

1313
@XmlType(propOrder = {
14+
"exploratoryRate",
1415
"individualGeneratorConfig",
1516
"localSearchConfig",
1617
})
1718
@NullMarked
18-
public class EvolutionaryAgentConfig extends PhaseConfig<EvolutionaryAgentConfig> {
19+
public class EvolutionaryWorkerConfig extends PhaseConfig<EvolutionaryWorkerConfig> {
20+
21+
@Nullable
22+
private Double exploratoryRate;
1923

2024
@Nullable
2125
private EvolutionaryIndividualGeneratorConfig individualGeneratorConfig = null;
@@ -27,6 +31,14 @@ public class EvolutionaryAgentConfig extends PhaseConfig<EvolutionaryAgentConfig
2731
// Constructors and simple getters/setters
2832
// ************************************************************************
2933

34+
public @Nullable Double getExploratoryRate() {
35+
return exploratoryRate;
36+
}
37+
38+
public void setExploratoryRate(@Nullable Double exploratoryRate) {
39+
this.exploratoryRate = exploratoryRate;
40+
}
41+
3042
public @Nullable EvolutionaryIndividualGeneratorConfig getIndividualGeneratorConfig() {
3143
return individualGeneratorConfig;
3244
}
@@ -47,29 +59,35 @@ public void setLocalSearchConfig(@Nullable EvolutionaryLocalSearchConfig localSe
4759
// With methods
4860
// ************************************************************************
4961

50-
public EvolutionaryAgentConfig
62+
public EvolutionaryWorkerConfig withExploratoryRate(Double exploratoryRate) {
63+
setExploratoryRate(exploratoryRate);
64+
return this;
65+
}
66+
67+
public EvolutionaryWorkerConfig
5168
withIndividualGeneratorConfig(EvolutionaryIndividualGeneratorConfig individualGeneratorConfig) {
5269
setIndividualGeneratorConfig(individualGeneratorConfig);
5370
return this;
5471
}
5572

56-
public EvolutionaryAgentConfig withLocalSearchConfig(EvolutionaryLocalSearchConfig localSearchConfig) {
73+
public EvolutionaryWorkerConfig withLocalSearchConfig(EvolutionaryLocalSearchConfig localSearchConfig) {
5774
setLocalSearchConfig(localSearchConfig);
5875
return this;
5976
}
6077

6178
@Override
62-
public EvolutionaryAgentConfig inherit(EvolutionaryAgentConfig inheritedConfig) {
79+
public EvolutionaryWorkerConfig inherit(EvolutionaryWorkerConfig inheritedConfig) {
6380
super.inherit(inheritedConfig);
81+
exploratoryRate = ConfigUtils.inheritOverwritableProperty(exploratoryRate, inheritedConfig.getExploratoryRate());
6482
individualGeneratorConfig =
6583
ConfigUtils.inheritConfig(individualGeneratorConfig, inheritedConfig.getIndividualGeneratorConfig());
6684
localSearchConfig = ConfigUtils.inheritConfig(localSearchConfig, inheritedConfig.getLocalSearchConfig());
6785
return this;
6886
}
6987

7088
@Override
71-
public EvolutionaryAgentConfig copyConfig() {
72-
return new EvolutionaryAgentConfig().inherit(this);
89+
public EvolutionaryWorkerConfig copyConfig() {
90+
return new EvolutionaryWorkerConfig().inherit(this);
7391
}
7492

7593
@Override

core/src/main/java/ai/timefold/solver/core/enterprise/TimefoldSolverEnterpriseService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ <Solution_> PartitionedSearchPhase<Solution_> buildPartitionedSearch(int phaseIn
178178

179179
<Solution_, Score_ extends Score<Score_>, State_ extends SolutionState<Solution_, Score_>>
180180
EvolutionaryDecider<Solution_, Score_> buildHybridGeneticSearch(HeuristicConfigPolicy<Solution_> solverConfigPolicy,
181-
int agentCount, int populationSize, int generationSize, int eliteGroupSize, int populationRestartCount,
182-
List<HybridGeneticSearchWorkerContext<Solution_, Score_, State_>> agentContextList,
181+
int workerCount, int populationSize, int generationSize, int eliteGroupSize, int populationRestartCount,
182+
List<HybridGeneticSearchWorkerContext<Solution_, Score_, State_>> workerContextList,
183183
PhaseTermination<Solution_> phaseTermination, BestSolutionRecaller<Solution_> bestSolutionRecaller);
184184

185185
<Solution_> EntitySelector<Solution_> applyNearbySelection(EntitySelectorConfig entitySelectorConfig,
@@ -230,7 +230,7 @@ enum Feature {
230230
SCORE_ANALYSIS("Score analysis", "do not use SolutionManager's analyze() method"),
231231
RECOMMENDATIONS("Recommendations", "do not use SolutionManager's recommendAssignment() method"),
232232
EVOLUTIONARY_ALGORITHM("Evolutionary Algorithm",
233-
"remove the agent count property from the evolutionary algorithm configuration");
233+
"remove the worker count property from the evolutionary algorithm configuration");
234234

235235
private final String name;
236236
private final String workaround;

core/src/main/java/ai/timefold/solver/core/impl/evolutionaryalgorithm/DefaultEvolutionaryAlgorithmPhase.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ public final class DefaultEvolutionaryAlgorithmPhase<Solution_> extends Abstract
1818
implements EvolutionaryAlgorithmPhase<Solution_>, EvolutionaryAlgorithmPhaseLifecycleListener<Solution_> {
1919

2020
private final EvolutionaryDecider<Solution_, ?> evolutionaryDecider;
21-
private final boolean isComplex;
2221

2322
public DefaultEvolutionaryAlgorithmPhase(Builder<Solution_> builder) {
2423
super(builder);
2524
this.evolutionaryDecider = builder.evolutionaryDecider;
26-
this.isComplex = builder.isComplex;
2725
}
2826

2927
// ************************************************************************
@@ -90,10 +88,10 @@ public void phaseEnded(EvolutionaryAlgorithmPhaseScope<Solution_> phaseScope) {
9088
phaseScope.endingNow();
9189
var statistics = phaseScope.getPopulation().getStatistics();
9290
logger.info(
93-
"Evolutionary Algorithm phase ({}) ended: time spent ({}), best score ({}), best generation ({}), best iteration ({}), generation total ({}), iteration total ({}), overconstrained ({}).",
91+
"Evolutionary Algorithm phase ({}) ended: time spent ({}), best score ({}), best generation ({}), best iteration ({}), generation total ({}), iteration total ({}).",
9492
phaseScope.getPhaseIndex(), phaseScope.calculateSolverTimeMillisSpentUpToNow(), phaseScope.getBestScore().raw(),
9593
statistics.bestGeneration(), statistics.bestIteration(), statistics.generationCount(),
96-
statistics.individualCount(), isComplex);
94+
statistics.individualCount());
9795
}
9896

9997
@Override
@@ -118,13 +116,11 @@ public void solvingError(SolverScope<Solution_> solverScope, Exception exception
118116
public static class Builder<Solution_> extends AbstractPhaseBuilder<Solution_> {
119117

120118
private final EvolutionaryDecider<Solution_, ?> evolutionaryDecider;
121-
private final boolean isComplex;
122119

123120
public Builder(int phaseIndex, String logIndentation, PhaseTermination<Solution_> phaseTermination,
124-
EvolutionaryDecider<Solution_, ?> evolutionaryDecider, boolean isComplex) {
121+
EvolutionaryDecider<Solution_, ?> evolutionaryDecider) {
125122
super(phaseIndex, logIndentation, phaseTermination);
126123
this.evolutionaryDecider = evolutionaryDecider;
127-
this.isComplex = isComplex;
128124
}
129125

130126
@Override

0 commit comments

Comments
 (0)