diff --git a/src/main/java/jobshop/solvers/GreedySolver.java b/src/main/java/jobshop/solvers/GreedySolver.java index 34076be..c3c20e4 100644 --- a/src/main/java/jobshop/solvers/GreedySolver.java +++ b/src/main/java/jobshop/solvers/GreedySolver.java @@ -2,6 +2,10 @@ package jobshop.solvers; import jobshop.Instance; import jobshop.Result; +import jobshop.encodings.Task; + +import java.util.ArrayList; +import java.util.Iterator; /** An empty shell to implement a greedy solver. */ public class GreedySolver implements Solver { @@ -14,13 +18,97 @@ public class GreedySolver implements Solver { /** Priority that the solver should use. */ final Priority priority; + final ArrayList tachesRestantes; + + /** Creates a new greedy solver that will use the given priority. */ public GreedySolver(Priority p) { this.priority = p; + this.tachesRestantes = new ArrayList<>(); + } + + /** return true if t1 est plus prioritaire que t1 **/ + private boolean prioritaire(Instance instance, Task t1, Task t2) throws Exception { + boolean rt = false; + switch(priority) { + case SPT: + rt = instance.duration(t1) <= instance.duration(t2); + break; + case LPT: + rt = instance.duration(t1) >= instance.duration(t2); + break; + case SRPT: + int i; + int sigmaT1 = 0; + int sigmaT2 = 0; + for (i=t1.task; i= sigmaT2; + break; + case EST_SPT: + throw new Exception("UNKNOWN PRIORITY"); + //break; + case EST_LPT: + throw new Exception("UNKNOWN PRIORITY"); + //break; + case EST_SRPT: + throw new Exception("UNKNOWN PRIORITY"); + //break; + case EST_LRPT: + throw new Exception("UNKNOWN PRIORITY"); + //break; + } + return rt; + } + + private void addTask(Instance instance, Task task) throws Exception { + Iterator iter = this.tachesRestantes.iterator(); + int index = 0; + boolean trouve = false; + while (iter.hasNext() && !trouve) { + Task current = iter.next(); + if (this.prioritaire(instance, task, current)) { + trouve = true; + this.tachesRestantes.add(index, task); + } else { + index++; + } + } } @Override public Result solve(Instance instance, long deadline) { - throw new UnsupportedOperationException(); + //Initialisation + int i; + for (i=0; i