123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- package jobshop.solvers;
-
- import jobshop.BestKnownResults;
- import jobshop.Instance;
- import jobshop.Result;
- import org.junit.Test;
-
- import java.io.IOException;
- import java.nio.file.Paths;
- import java.util.List;
- import java.util.stream.Collectors;
-
- import static jobshop.solvers.GreedySolver.Priority.*;
-
- public class GreedySolverTest {
- @Test
- public void testSPT() {
- List<String> instancesNames = BestKnownResults.instancesMatching("la");
- instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
-
- List<Instance> instances = instancesNames.stream().map(name -> {
- Instance instance = null;
- try {
- instance = Instance.fromFile(Paths.get("instances/", name));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return instance;
- }).collect(Collectors.toList());
-
- GreedySolver solver = new GreedySolver(SPT);
- Result result;
- for (int i = 0; i < instances.size(); i++) {
- result = solver.solve(instances.get(i), 100000).get(0);
- assert result.schedule.get().isValid();
- if (BestKnownResults.isKnown(instancesNames.get(i))) {
- assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
- }
- }
- }
-
- @Test
- public void testLPT() throws IOException {
- List<String> instancesNames = BestKnownResults.instancesMatching("la");
- instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
-
- List<Instance> instances = instancesNames.stream().map(name -> {
- Instance instance = null;
- try {
- instance = Instance.fromFile(Paths.get("instances/", name));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return instance;
- }).collect(Collectors.toList());
-
- GreedySolver solver = new GreedySolver(LPT);
- Result result;
- for (int i = 0; i < instances.size(); i++) {
- result = solver.solve(instances.get(i), 100000).get(0);
- assert result.schedule.get().isValid();
- if (BestKnownResults.isKnown(instancesNames.get(i))) {
- assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
- }
- }
- }
-
- @Test
- public void testSRPT() throws IOException {
- List<String> instancesNames = BestKnownResults.instancesMatching("la");
- instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
-
- List<Instance> instances = instancesNames.stream().map(name -> {
- Instance instance = null;
- try {
- instance = Instance.fromFile(Paths.get("instances/", name));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return instance;
- }).collect(Collectors.toList());
-
- GreedySolver solver = new GreedySolver(SRPT);
- Result result;
- for (int i = 0; i < instances.size(); i++) {
- result = solver.solve(instances.get(i), 100000).get(0);
- assert result.schedule.get().isValid();
- if (BestKnownResults.isKnown(instancesNames.get(i))) {
- assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
- }
- }
- }
-
- @Test
- public void testLRPT() throws IOException {
- List<String> instancesNames = BestKnownResults.instancesMatching("la");
- instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
-
- List<Instance> instances = instancesNames.stream().map(name -> {
- Instance instance = null;
- try {
- instance = Instance.fromFile(Paths.get("instances/", name));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return instance;
- }).collect(Collectors.toList());
-
- GreedySolver solver = new GreedySolver(LRPT);
- Result result;
- for (int i = 0; i < instances.size(); i++) {
- result = solver.solve(instances.get(i), 100000).get(0);
- assert result.schedule.get().isValid();
- if (BestKnownResults.isKnown(instancesNames.get(i))) {
- assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
- }
- }
- }
-
- @Test
- public void testEST_SPT() {
- List<String> instancesNames = BestKnownResults.instancesMatching("la");
- instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
-
- List<Instance> instances = instancesNames.stream().map(name -> {
- Instance instance = null;
- try {
- instance = Instance.fromFile(Paths.get("instances/", name));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return instance;
- }).collect(Collectors.toList());
-
- GreedySolver solver = new GreedySolver(EST_SPT);
- Result result;
- for (int i = 0; i < instances.size(); i++) {
- result = solver.solve(instances.get(i), 100000).get(0);
- assert result.schedule.get().isValid();
- if (BestKnownResults.isKnown(instancesNames.get(i))) {
- assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
- }
- }
- }
-
- @Test
- public void testEST_LPT() throws IOException {
- List<String> instancesNames = BestKnownResults.instancesMatching("la");
- instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
-
- List<Instance> instances = instancesNames.stream().map(name -> {
- Instance instance = null;
- try {
- instance = Instance.fromFile(Paths.get("instances/", name));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return instance;
- }).collect(Collectors.toList());
-
- GreedySolver solver = new GreedySolver(EST_LPT);
- Result result;
- for (int i = 0; i < instances.size(); i++) {
- result = solver.solve(instances.get(i), 100000).get(0);
- assert result.schedule.get().isValid();
- if (BestKnownResults.isKnown(instancesNames.get(i))) {
- assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
- }
- }
- }
-
- @Test
- public void testEST_SRPT() throws IOException {
- List<String> instancesNames = BestKnownResults.instancesMatching("la");
- instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
-
- List<Instance> instances = instancesNames.stream().map(name -> {
- Instance instance = null;
- try {
- instance = Instance.fromFile(Paths.get("instances/", name));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return instance;
- }).collect(Collectors.toList());
-
- GreedySolver solver = new GreedySolver(EST_SRPT);
- Result result;
- for (int i = 0; i < instances.size(); i++) {
- result = solver.solve(instances.get(i), 100000).get(0);
- assert result.schedule.get().isValid();
- if (BestKnownResults.isKnown(instancesNames.get(i))) {
- assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
- }
- }
- }
-
- @Test
- public void testEST_LRPT() throws IOException {
- List<String> instancesNames = BestKnownResults.instancesMatching("la");
- instancesNames.addAll(BestKnownResults.instancesMatching("ft"));
-
- List<Instance> instances = instancesNames.stream().map(name -> {
- Instance instance = null;
- try {
- instance = Instance.fromFile(Paths.get("instances/", name));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return instance;
- }).collect(Collectors.toList());
-
- GreedySolver solver = new GreedySolver(EST_LRPT);
- Result result;
- for (int i = 0; i < instances.size(); i++) {
- result = solver.solve(instances.get(i), 100000).get(0);
- assert result.schedule.get().isValid();
- if (BestKnownResults.isKnown(instancesNames.get(i))) {
- assert result.schedule.get().makespan() >= BestKnownResults.of(instancesNames.get(i));
- }
- }
- }
-
- @Test
- public void testSusucre() throws IOException {
-
- Instance instance = Instance.fromFile(Paths.get("instances/aaa3"));
-
- GreedySolver solver = new GreedySolver(EST_LRPT);
- Result result = solver.solve(instance, 100000).get(0);
- System.out.println("SCHEDULE EST_LRPT: " + result.schedule.get().toString());
- solver = new GreedySolver(EST_SPT);
- result = solver.solve(instance, 100000).get(0);
- System.out.println("SCHEDULE EST_SPT: " + result.schedule.get().toString());
- }
- }
|