From 74543116ebf37aad5ee525a48cc9f2f3257d7f19 Mon Sep 17 00:00:00 2001 From: Faure Paul Date: Wed, 14 Apr 2021 12:12:24 +0200 Subject: [PATCH] =?UTF-8?q?Impl=C3=A9mentation=20heuristique=20gloutonne?= =?UTF-8?q?=20en=20cours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/jobshop/solvers/GreedySolver.java | 90 ++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) 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