|
@@ -11,6 +11,9 @@ import java.util.stream.Collectors;
|
11
|
11
|
|
12
|
12
|
public class Instance {
|
13
|
13
|
|
|
14
|
+ /** Name of the instance. Same as the filename from which the instance is loaded. */
|
|
15
|
+ public final String name;
|
|
16
|
+
|
14
|
17
|
/** Number of jobs in the instance */
|
15
|
18
|
public final int numJobs;
|
16
|
19
|
|
|
@@ -60,7 +63,8 @@ public class Instance {
|
60
|
63
|
* This should no be called directly. Instead, Instance objects should be created with the
|
61
|
64
|
* <code>Instance.fromFile()</code> static method.
|
62
|
65
|
*/
|
63
|
|
- Instance(int numJobs, int numTasks) {
|
|
66
|
+ Instance(String name, int numJobs, int numTasks) {
|
|
67
|
+ this.name = name;
|
64
|
68
|
this.numJobs = numJobs;
|
65
|
69
|
this.numTasks = numTasks;
|
66
|
70
|
this.numMachines = numTasks;
|
|
@@ -71,19 +75,20 @@ public class Instance {
|
71
|
75
|
|
72
|
76
|
/** Parses a instance from a file. */
|
73
|
77
|
public static Instance fromFile(Path path) throws IOException {
|
|
78
|
+ String name = path.getFileName().toString();
|
74
|
79
|
Iterator<String> lines = Files.readAllLines(path).stream()
|
75
|
80
|
.filter(l -> !l.startsWith("#"))
|
76
|
81
|
.collect(Collectors.toList())
|
77
|
82
|
.iterator();
|
78
|
83
|
|
79
|
84
|
Scanner header = new Scanner(lines.next());
|
80
|
|
- int num_jobs = header.nextInt();
|
81
|
|
- int num_tasks = header.nextInt();
|
82
|
|
- Instance pb = new Instance(num_jobs, num_tasks);
|
|
85
|
+ int numJobs = header.nextInt();
|
|
86
|
+ int numTasks = header.nextInt();
|
|
87
|
+ Instance pb = new Instance(name, numJobs, numTasks);
|
83
|
88
|
|
84
|
|
- for(int job = 0 ; job<num_jobs ; job++) {
|
|
89
|
+ for(int job = 0 ; job<numJobs ; job++) {
|
85
|
90
|
Scanner line = new Scanner(lines.next());
|
86
|
|
- for(int task = 0 ; task < num_tasks ; task++) {
|
|
91
|
+ for(int task = 0 ; task < numTasks ; task++) {
|
87
|
92
|
pb.machines[job][task] = line.nextInt();
|
88
|
93
|
pb.durations[job][task] = line.nextInt();
|
89
|
94
|
}
|