|
@@ -9,7 +9,7 @@ import java.util.List;
|
9
|
9
|
*
|
10
|
10
|
* It works on the ResourceOrder encoding by generating two neighbors for each block
|
11
|
11
|
* of the critical path.
|
12
|
|
- * For each block, two neighbors should be generated that respectivly swap the first two and
|
|
12
|
+ * For each block, two neighbors should be generated that respectively swap the first two and
|
13
|
13
|
* last two tasks of the block.
|
14
|
14
|
*/
|
15
|
15
|
public class Nowicki extends Neighborhood<ResourceOrder> {
|
|
@@ -34,6 +34,7 @@ public class Nowicki extends Neighborhood<ResourceOrder> {
|
34
|
34
|
/** index of the last task of the block */
|
35
|
35
|
public final int lastTask;
|
36
|
36
|
|
|
37
|
+ /** Creates a new block. */
|
37
|
38
|
Block(int machine, int firstTask, int lastTask) {
|
38
|
39
|
this.machine = machine;
|
39
|
40
|
this.firstTask = firstTask;
|
|
@@ -57,13 +58,16 @@ public class Nowicki extends Neighborhood<ResourceOrder> {
|
57
|
58
|
* machine 2 : ...
|
58
|
59
|
*/
|
59
|
60
|
public static class Swap extends Neighbor<ResourceOrder> {
|
60
|
|
- // machine on which to perform the swap
|
|
61
|
+ /** machine on which to perform the swap */
|
61
|
62
|
public final int machine;
|
62
|
|
- // index of one task to be swapped
|
|
63
|
+
|
|
64
|
+ /** index of one task to be swapped (in the resource order encoding) */
|
63
|
65
|
public final int t1;
|
64
|
|
- // index of the other task to be swapped
|
|
66
|
+
|
|
67
|
+ /** index of the other task to be swapped (in the resource order encoding) */
|
65
|
68
|
public final int t2;
|
66
|
69
|
|
|
70
|
+ /** Creates a new swap of two tasks. */
|
67
|
71
|
Swap(int machine, int t1, int t2) {
|
68
|
72
|
this.machine = machine;
|
69
|
73
|
this.t1 = t1;
|
|
@@ -71,12 +75,13 @@ public class Nowicki extends Neighborhood<ResourceOrder> {
|
71
|
75
|
}
|
72
|
76
|
|
73
|
77
|
|
74
|
|
- /** Apply this swap on the given resource order, transforming it into a new solution. */
|
|
78
|
+ /** Apply this swap on the given ResourceOrder, transforming it into a new solution. */
|
75
|
79
|
@Override
|
76
|
80
|
public void applyOn(ResourceOrder current) {
|
77
|
81
|
throw new UnsupportedOperationException();
|
78
|
82
|
}
|
79
|
83
|
|
|
84
|
+ /** Unapply this swap on the neighbor, transforming it back into the original solution. */
|
80
|
85
|
@Override
|
81
|
86
|
public void undoApplyOn(ResourceOrder current) {
|
82
|
87
|
throw new UnsupportedOperationException();
|
|
@@ -86,8 +91,15 @@ public class Nowicki extends Neighborhood<ResourceOrder> {
|
86
|
91
|
|
87
|
92
|
@Override
|
88
|
93
|
public List<Neighbor<ResourceOrder>> generateNeighbors(ResourceOrder current) {
|
89
|
|
- List<Neighbor<ResourceOrder>> neighbors = new ArrayList<>();
|
90
|
|
- // iterate over all blocks of the critical
|
|
94
|
+ // this simply converts the list of swaps into a list of neighbors
|
|
95
|
+ return new ArrayList<>(allSwaps(current));
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ /** Generates all swaps of the given ResourceOrder.
|
|
99
|
+ * This method can be used if one wants to access the inner fields of a neighbors. */
|
|
100
|
+ public List<Swap> allSwaps(ResourceOrder current) {
|
|
101
|
+ List<Swap> neighbors = new ArrayList<>();
|
|
102
|
+ // iterate over all blocks of the critical path
|
91
|
103
|
for(var block : blocksOfCriticalPath(current)) {
|
92
|
104
|
// for this block, compute all neighbors and add them to the list of neighbors
|
93
|
105
|
neighbors.addAll(neighbors(block));
|