No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GreedySolverTest.java 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package jobshop.solvers;
  2. import jobshop.BestKnownResults;
  3. import jobshop.Instance;
  4. import jobshop.Result;
  5. import org.junit.Test;
  6. import java.io.IOException;
  7. import java.nio.file.Paths;
  8. import java.util.List;
  9. import java.util.stream.Collectors;
  10. import static jobshop.solvers.GreedySolver.Priority.*;
  11. public class GreedySolverTest {
  12. @Test
  13. public void testSPT() {
  14. List<String> instancesNames = BestKnownResults.instancesMatching("la");
  15. instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
  16. List<Instance> instances = instancesNames.stream().map(name -> {
  17. Instance instance = null;
  18. try {
  19. instance = Instance.fromFile(Paths.get("instances/", name));
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. return instance;
  24. }).collect(Collectors.toList());
  25. GreedySolver solver = new GreedySolver(SPT);
  26. Result result;
  27. for (int i = 0; i < instances.size(); i++) {
  28. result = solver.solve(instances.get(i), 100000).get(0);
  29. assert result.schedule.get().isValid();
  30. if (BestKnownResults.isKnown(instancesNames.get(i))) {
  31. assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
  32. }
  33. }
  34. }
  35. @Test
  36. public void testLPT() throws IOException {
  37. List<String> instancesNames = BestKnownResults.instancesMatching("la");
  38. instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
  39. List<Instance> instances = instancesNames.stream().map(name -> {
  40. Instance instance = null;
  41. try {
  42. instance = Instance.fromFile(Paths.get("instances/", name));
  43. } catch (IOException e) {
  44. e.printStackTrace();
  45. }
  46. return instance;
  47. }).collect(Collectors.toList());
  48. GreedySolver solver = new GreedySolver(LPT);
  49. Result result;
  50. for (int i = 0; i < instances.size(); i++) {
  51. result = solver.solve(instances.get(i), 100000).get(0);
  52. assert result.schedule.get().isValid();
  53. if (BestKnownResults.isKnown(instancesNames.get(i))) {
  54. assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
  55. }
  56. }
  57. }
  58. @Test
  59. public void testSRPT() throws IOException {
  60. List<String> instancesNames = BestKnownResults.instancesMatching("la");
  61. instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
  62. List<Instance> instances = instancesNames.stream().map(name -> {
  63. Instance instance = null;
  64. try {
  65. instance = Instance.fromFile(Paths.get("instances/", name));
  66. } catch (IOException e) {
  67. e.printStackTrace();
  68. }
  69. return instance;
  70. }).collect(Collectors.toList());
  71. GreedySolver solver = new GreedySolver(SRPT);
  72. Result result;
  73. for (int i = 0; i < instances.size(); i++) {
  74. result = solver.solve(instances.get(i), 100000).get(0);
  75. assert result.schedule.get().isValid();
  76. if (BestKnownResults.isKnown(instancesNames.get(i))) {
  77. assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
  78. }
  79. }
  80. }
  81. @Test
  82. public void testLRPT() throws IOException {
  83. List<String> instancesNames = BestKnownResults.instancesMatching("la");
  84. instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
  85. List<Instance> instances = instancesNames.stream().map(name -> {
  86. Instance instance = null;
  87. try {
  88. instance = Instance.fromFile(Paths.get("instances/", name));
  89. } catch (IOException e) {
  90. e.printStackTrace();
  91. }
  92. return instance;
  93. }).collect(Collectors.toList());
  94. GreedySolver solver = new GreedySolver(LRPT);
  95. Result result;
  96. for (int i = 0; i < instances.size(); i++) {
  97. result = solver.solve(instances.get(i), 100000).get(0);
  98. assert result.schedule.get().isValid();
  99. if (BestKnownResults.isKnown(instancesNames.get(i))) {
  100. assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
  101. }
  102. }
  103. }
  104. @Test
  105. public void testEST_SPT() {
  106. List<String> instancesNames = BestKnownResults.instancesMatching("la");
  107. instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
  108. List<Instance> instances = instancesNames.stream().map(name -> {
  109. Instance instance = null;
  110. try {
  111. instance = Instance.fromFile(Paths.get("instances/", name));
  112. } catch (IOException e) {
  113. e.printStackTrace();
  114. }
  115. return instance;
  116. }).collect(Collectors.toList());
  117. GreedySolver solver = new GreedySolver(EST_SPT);
  118. Result result;
  119. for (int i = 0; i < instances.size(); i++) {
  120. result = solver.solve(instances.get(i), 100000).get(0);
  121. assert result.schedule.get().isValid();
  122. if (BestKnownResults.isKnown(instancesNames.get(i))) {
  123. assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
  124. }
  125. }
  126. }
  127. @Test
  128. public void testEST_LPT() throws IOException {
  129. List<String> instancesNames = BestKnownResults.instancesMatching("la");
  130. instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
  131. List<Instance> instances = instancesNames.stream().map(name -> {
  132. Instance instance = null;
  133. try {
  134. instance = Instance.fromFile(Paths.get("instances/", name));
  135. } catch (IOException e) {
  136. e.printStackTrace();
  137. }
  138. return instance;
  139. }).collect(Collectors.toList());
  140. GreedySolver solver = new GreedySolver(EST_LPT);
  141. Result result;
  142. for (int i = 0; i < instances.size(); i++) {
  143. result = solver.solve(instances.get(i), 100000).get(0);
  144. assert result.schedule.get().isValid();
  145. if (BestKnownResults.isKnown(instancesNames.get(i))) {
  146. assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
  147. }
  148. }
  149. }
  150. @Test
  151. public void testEST_SRPT() throws IOException {
  152. List<String> instancesNames = BestKnownResults.instancesMatching("la");
  153. instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
  154. List<Instance> instances = instancesNames.stream().map(name -> {
  155. Instance instance = null;
  156. try {
  157. instance = Instance.fromFile(Paths.get("instances/", name));
  158. } catch (IOException e) {
  159. e.printStackTrace();
  160. }
  161. return instance;
  162. }).collect(Collectors.toList());
  163. GreedySolver solver = new GreedySolver(EST_SRPT);
  164. Result result;
  165. for (int i = 0; i < instances.size(); i++) {
  166. result = solver.solve(instances.get(i), 100000).get(0);
  167. assert result.schedule.get().isValid();
  168. if (BestKnownResults.isKnown(instancesNames.get(i))) {
  169. assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
  170. }
  171. }
  172. }
  173. @Test
  174. public void testEST_LRPT() throws IOException {
  175. List<String> instancesNames = BestKnownResults.instancesMatching("la");
  176. instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
  177. List<Instance> instances = instancesNames.stream().map(name -> {
  178. Instance instance = null;
  179. try {
  180. instance = Instance.fromFile(Paths.get("instances/", name));
  181. } catch (IOException e) {
  182. e.printStackTrace();
  183. }
  184. return instance;
  185. }).collect(Collectors.toList());
  186. GreedySolver solver = new GreedySolver(EST_LRPT);
  187. Result result;
  188. for (int i = 0; i < instances.size(); i++) {
  189. result = solver.solve(instances.get(i), 100000).get(0);
  190. assert result.schedule.get().isValid();
  191. if (BestKnownResults.isKnown(instancesNames.get(i))) {
  192. assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
  193. }
  194. }
  195. }
  196. @Test
  197. public void testSusucre() throws IOException {
  198. Instance instance = Instance.fromFile(Paths.get("instances/aaa3"));
  199. GreedySolver solver = new GreedySolver(EST_LRPT);
  200. Result result = solver.solve(instance, 100000).get(0);
  201. System.out.println("SCHEDULE EST_LRPT: " + result.schedule.get().toString());
  202. solver = new GreedySolver(EST_SPT);
  203. result = solver.solve(instance, 100000).get(0);
  204. System.out.println("SCHEDULE EST_SPT: " + result.schedule.get().toString());
  205. }
  206. }