-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTSPLIBConfiguration.java
More file actions
80 lines (66 loc) · 3.11 KB
/
Copy pathTSPLIBConfiguration.java
File metadata and controls
80 lines (66 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package ai.timefold.solver.benchmarks.competitive.tsplib95;
import java.math.RoundingMode;
import ai.timefold.solver.benchmarks.competitive.AbstractCompetitiveBenchmark;
import ai.timefold.solver.benchmarks.competitive.Configuration;
import ai.timefold.solver.benchmarks.examples.tsp.domain.Tour;
import ai.timefold.solver.benchmarks.examples.tsp.domain.TspSolution;
import ai.timefold.solver.benchmarks.examples.tsp.domain.Visit;
import ai.timefold.solver.benchmarks.examples.tsp.domain.solver.nearby.VisitNearbyDistanceMeter;
import ai.timefold.solver.benchmarks.examples.tsp.score.TspConstraintProvider;
import ai.timefold.solver.core.config.constructionheuristic.ConstructionHeuristicPhaseConfig;
import ai.timefold.solver.core.config.localsearch.LocalSearchPhaseConfig;
import ai.timefold.solver.core.config.solver.SolverConfig;
import ai.timefold.solver.core.config.solver.termination.TerminationConfig;
public enum TSPLIBConfiguration implements Configuration<TSPLIBDataset> {
/**
* Community edition, everything left on default.
*/
COMMUNITY_EDITION(false),
/**
* Full power of the enterprise edition.
*/
ENTERPRISE_EDITION(true);
private final boolean usesEnterprise;
TSPLIBConfiguration(boolean usesEnterprise) {
this.usesEnterprise = usesEnterprise;
}
@Override
public SolverConfig getSolverConfig(TSPLIBDataset dataset) {
return switch (this) {
case COMMUNITY_EDITION -> getCommunityEditionSolverConfig(dataset);
case ENTERPRISE_EDITION -> getEnterpriseEditionSolverConfig(dataset);
};
}
@Override
public boolean usesEnterprise() {
return usesEnterprise;
}
@Override
public String entityLabel() {
return "Vehicle";
}
@Override
public String valueLabel() {
return "Location";
}
private SolverConfig getCommunityEditionSolverConfig(TSPLIBDataset dataset) {
var threshold = dataset.getBestKnownSolution().negate()
.setScale(0, RoundingMode.HALF_EVEN);
var terminationConfig = new TerminationConfig()
.withSpentLimit(getMaximumDurationPerDataset())
.withUnimprovedSecondsSpentLimit(AbstractCompetitiveBenchmark.UNIMPROVED_SECONDS_TERMINATION)
.withBestScoreLimit(Long.toString(threshold.longValue()));
return new SolverConfig()
.withSolutionClass(TspSolution.class)
.withEntityClasses(Tour.class, Visit.class)
.withConstraintProviderClass(TspConstraintProvider.class)
.withTerminationConfig(terminationConfig)
.withPhases(new ConstructionHeuristicPhaseConfig(), new LocalSearchPhaseConfig());
}
private SolverConfig getEnterpriseEditionSolverConfig(TSPLIBDataset dataset) {
// Inherit community config, add move thread count and nearby distance meter.
return getCommunityEditionSolverConfig(dataset)
.withMoveThreadCount(Integer.toString(AbstractCompetitiveBenchmark.ENTERPRISE_MOVE_THREAD_COUNT))
.withNearbyDistanceMeterClass(VisitNearbyDistanceMeter.class);
}
}