-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathOptimalJobSchedulingTest.java
98 lines (65 loc) · 2.46 KB
/
OptimalJobSchedulingTest.java
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.thealgorithms.dynamicprogramming;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
/**
* @author [email protected]
*/
public class OptimalJobSchedulingTest {
@Test
public void testOptimalJobScheduling1() {
int numberProcesses = 5;
int numberMachines = 4;
int[][] run = {{5, 1, 3, 2}, {4, 2, 1, 3}, {1, 5, 2, 1}, {2, 3, 4, 2}, {1, 1, 3, 1}};
int[][] transfer = {{0, 1, 2, 4}, {1, 0, 2, 3}, {2, 2, 0, 1}, {4, 3, 1, 0}};
OptimalJobScheduling opt = new OptimalJobScheduling(numberProcesses, numberMachines, run, transfer);
opt.execute();
int[][] costs = {{5, 1, 3, 2}, {6, 3, 4, 5}, {5, 8, 6, 6}, {7, 9, 10, 8}, {8, 9, 12, 9}};
for (int i = 0; i < numberProcesses; i++) {
for (int j = 0; j < numberMachines; j++) {
assertEquals(costs[i][j], opt.getCost(i, j));
}
}
}
@Test
public void testOptimalJobScheduling2() {
int numberProcesses = 3;
int numberMachines = 3;
int[][] run = {{5, 1, 3}, {4, 2, 1}, {1, 5, 2}};
int[][] transfer = {{0, 1, 2}, {1, 0, 2}, {2, 2, 0}};
OptimalJobScheduling opt = new OptimalJobScheduling(numberProcesses, numberMachines, run, transfer);
opt.execute();
int[][] costs = {{5, 1, 3}, {6, 3, 4}, {5, 8, 6}};
for (int i = 0; i < numberProcesses; i++) {
for (int j = 0; j < numberMachines; j++) {
assertEquals(costs[i][j], opt.getCost(i, j));
}
}
}
@Test
public void testOptimalJobScheduling3() {
int numberProcesses = 6;
int numberMachines = 4;
int[][] run = {
{5, 1, 3, 2},
{4, 2, 1, 1},
{1, 5, 2, 6},
{1, 1, 2, 3},
{2, 1, 4, 6},
{3, 2, 2, 3},
};
int[][] transfer = {
{0, 1, 2, 1},
{1, 0, 2, 3},
{2, 2, 0, 2},
{1, 3, 2, 0},
};
OptimalJobScheduling opt = new OptimalJobScheduling(numberProcesses, numberMachines, run, transfer);
opt.execute();
int[][] costs = {{5, 1, 3, 2}, {6, 3, 4, 3}, {5, 8, 6, 9}, {6, 7, 8, 9}, {8, 8, 12, 13}, {11, 10, 12, 12}};
for (int i = 0; i < numberProcesses; i++) {
for (int j = 0; j < numberMachines; j++) {
assertEquals(costs[i][j], opt.getCost(i, j));
}
}
}
}