Implémentation heuristique gloutonne en cours
This commit is contained in:
		
							parent
							
								
									9bc6dfdec3
								
							
						
					
					
						commit
						74543116eb
					
				
					 1 changed files with 89 additions and 1 deletions
				
			
		|  | @ -2,6 +2,10 @@ package jobshop.solvers; | ||||||
| 
 | 
 | ||||||
| import jobshop.Instance; | import jobshop.Instance; | ||||||
| import jobshop.Result; | import jobshop.Result; | ||||||
|  | import jobshop.encodings.Task; | ||||||
|  | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Iterator; | ||||||
| 
 | 
 | ||||||
| /** An empty shell to implement a greedy solver. */ | /** An empty shell to implement a greedy solver. */ | ||||||
| public class GreedySolver implements Solver { | public class GreedySolver implements Solver { | ||||||
|  | @ -14,13 +18,97 @@ public class GreedySolver implements Solver { | ||||||
|     /** Priority that the solver should use. */ |     /** Priority that the solver should use. */ | ||||||
|     final Priority priority; |     final Priority priority; | ||||||
| 
 | 
 | ||||||
|  |     final ArrayList<Task> tachesRestantes; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     /** Creates a new greedy solver that will use the given priority. */ |     /** Creates a new greedy solver that will use the given priority. */ | ||||||
|     public GreedySolver(Priority p) { |     public GreedySolver(Priority p) { | ||||||
|         this.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<instance.numTasks; i++) { | ||||||
|  |                     sigmaT1 += instance.duration(t1.job, i); | ||||||
|  |                 } | ||||||
|  |                 for (i=t2.task; i<instance.numTasks; i++) { | ||||||
|  |                     sigmaT2 += instance.duration(t2.job, i); | ||||||
|  |                 } | ||||||
|  |                 rt = sigmaT1 <= sigmaT2; | ||||||
|  |                 break; | ||||||
|  |             case LRPT: | ||||||
|  |                 sigmaT1 = 0; | ||||||
|  |                 sigmaT2 = 0; | ||||||
|  |                 for (i=t1.task; i<instance.numTasks; i++) { | ||||||
|  |                     sigmaT1 += instance.duration(t1.job, i); | ||||||
|  |                 } | ||||||
|  |                 for (i=t2.task; i<instance.numTasks; i++) { | ||||||
|  |                     sigmaT2 += instance.duration(t2.job, i); | ||||||
|  |                 } | ||||||
|  |                 rt = sigmaT1 >= 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<Task> 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 |     @Override | ||||||
|     public Result solve(Instance instance, long deadline) { |     public Result solve(Instance instance, long deadline) { | ||||||
|         throw new UnsupportedOperationException(); |         //Initialisation | ||||||
|  |         int i; | ||||||
|  |         for (i=0; i<instance.numJobs; i++) { | ||||||
|  |             try { | ||||||
|  |                 addTask(instance, new Task(i,0)); | ||||||
|  |             } catch (Exception e) { | ||||||
|  |                 System.out.println("ERREUR POLITIQUE DE PRIORITE INCONNUE"); | ||||||
|  |                 System.exit(2); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         Result result = null; | ||||||
|  | 
 | ||||||
|  |         //Itérations | ||||||
|  |         while (!this.tachesRestantes.isEmpty()) { | ||||||
|  |             //TAF | ||||||
|  |         } | ||||||
|  |         return result; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue