Browse Source

Improve documentation

Arthur Bit-Monnot 5 months ago
parent
commit
27a970026f

+ 11
- 6
src/main/java/jobshop/Instance.java View File

@@ -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
             }

+ 1
- 1
src/main/java/jobshop/encodings/JobNumbers.java View File

@@ -8,7 +8,7 @@ import java.util.Arrays;
8 8
 import java.util.Comparator;
9 9
 import java.util.stream.IntStream;
10 10
 
11
-/** Représentation par numéro de job. */
11
+/** Encoding of the solution of a jobshop problem by job numbers. */
12 12
 public class JobNumbers extends Encoding {
13 13
 
14 14
     /** A numJobs * numTasks array containing the representation by job numbers. */

+ 4
- 4
src/main/java/jobshop/encodings/ResourceOrder.java View File

@@ -14,7 +14,7 @@ public class ResourceOrder extends Encoding {
14 14
     // executed on this machine in the same order
15 15
     public final Task[][] tasksByMachine;
16 16
 
17
-    // for each machine, indicate on many tasks have been initialized
17
+    // for each machine, indicate how many tasks have been initialized
18 18
     public final int[] nextFreeSlot;
19 19
 
20 20
     /** Creates a new empty resource order. */
@@ -71,10 +71,10 @@ public class ResourceOrder extends Encoding {
71 71
         // loop while there remains a job that has unscheduled tasks
72 72
         while(IntStream.range(0, instance.numJobs).anyMatch(m -> nextToScheduleByJob[m] < instance.numTasks)) {
73 73
 
74
-            // selects a task that has noun scheduled predecessor on its job and machine :
74
+            // selects a task that has no unscheduled predecessor on its job and machine :
75 75
             //  - it is the next to be schedule on a machine
76 76
             //  - it is the next to be scheduled on its job
77
-            // if there is no such task, we have cyclic dependency and the solution is invalid
77
+            // If there is no such task, we have cyclic dependency and the solution is invalid.
78 78
             Optional<Task> schedulable =
79 79
                     IntStream.range(0, instance.numMachines) // all machines ...
80 80
                     .filter(m -> nextToScheduleByMachine[m] < instance.numJobs) // ... with unscheduled jobs
@@ -83,7 +83,7 @@ public class ResourceOrder extends Encoding {
83 83
                     .findFirst(); // select the first one if any
84 84
 
85 85
             if(schedulable.isPresent()) {
86
-                // we found a schedulable task, lets call it t
86
+                // we have a schedulable task, lets call it t
87 87
                 Task t = schedulable.get();
88 88
                 int machine = instance.machine(t.job, t.task);
89 89
 

+ 4
- 0
src/main/java/jobshop/solvers/BasicSolver.java View File

@@ -5,6 +5,10 @@ import jobshop.Result;
5 5
 import jobshop.Solver;
6 6
 import jobshop.encodings.JobNumbers;
7 7
 
8
+/**
9
+ * A very naïve solver that first schedules
10
+ *
11
+ **/
8 12
 public class BasicSolver implements Solver {
9 13
     @Override
10 14
     public Result solve(Instance instance, long deadline) {

Loading…
Cancel
Save