Repository navigation
Expand file tree
/
Copy pathCPHExperiment.java
More file actions
60 lines (44 loc) · 2.08 KB
/
Copy pathCPHExperiment.java
File metadata and controls
60 lines (44 loc) · 2.08 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
package cph;
import cph.instance.CPHInstance;
import cph.instance.CPHInstancesManager;
import cph.algorithm.CPHRandomConstructive;
import java.io.IOException;
import jmh.algorithm.MultiStartSearch;
import jmh.algorithm.MultiStartSearch.MSConfig;
import jmh.algorithm.Objective;
import jmh.algorithm.Solution;
import jmh.experiment.ExperimentManager;
import jmh.instance.FormatException;
/**
* Runs the Capacitated p-hub experiment: for every {@code phub_50_5} instance it
* compares the four multi-start configurations and reports the results. CPH is a
* minimization problem.
*
* <p>Only the problem-specific wiring lives here (instance type, constructive and
* objective); everything else is the shared framework.
*/
public class CPHExperiment {
private static final long TIMEOUT_MILLIS = 10 * 1000;
public static void main(String[] args) throws IOException, FormatException {
var instancesManager = new CPHInstancesManager();
var instances = instancesManager.getInstancesByType("phub_50_5");
var manager = new ExperimentManager(Objective.MINIMIZE);
for (var instanceFile : instances) {
CPHInstance instance = instanceFile.loadInstance();
Solution solution;
solution = search(instance, MSConfig.RANDOM);
manager.addSolution(instance, "Random", solution);
solution = search(instance, MSConfig.FIRST_IMPROVEMENT_RANDOM);
manager.addSolution(instance, "First Improvement Random", solution);
solution = search(instance, MSConfig.FIRST_IMPROVEMENT_LEXICOGRAPHICAL);
manager.addSolution(instance, "First Improvement Lexicographical", solution);
solution = search(instance, MSConfig.BEST_IMPROVEMENT);
manager.addSolution(instance, "Best Improvement", solution);
}
manager.experimentFinished();
}
private static Solution search(CPHInstance instance, MSConfig config) {
return new MultiStartSearch(new CPHRandomConstructive(instance), config, Objective.MINIMIZE)
.calculateSolution(TIMEOUT_MILLIS);
}
}