SPT almost finished
This commit is contained in:
parent
2494bafd79
commit
26a5ad00fe
1 changed files with 78 additions and 3 deletions
|
@ -2,8 +2,11 @@ package jobshop.solvers;
|
||||||
|
|
||||||
import jobshop.Instance;
|
import jobshop.Instance;
|
||||||
import jobshop.encodings.Schedule;
|
import jobshop.encodings.Schedule;
|
||||||
|
import jobshop.encodings.Task;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/** 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 {
|
||||||
|
@ -15,14 +18,86 @@ public class GreedySolver implements Solver {
|
||||||
|
|
||||||
/** Priority that the solver should use. */
|
/** Priority that the solver should use. */
|
||||||
final Priority priority;
|
final Priority priority;
|
||||||
|
|
||||||
/** 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Integer heuristiqueSPT(Task t, Instance instance){
|
||||||
|
return instance.duration(t);
|
||||||
|
}
|
||||||
|
private Integer heuristiqueLPT(Task t, Instance instance){
|
||||||
|
return instance.duration(t);
|
||||||
|
}
|
||||||
|
private Integer heuristiqueSRPT(Task t, Instance instance){
|
||||||
|
return instance.duration(t);
|
||||||
|
}
|
||||||
|
private Integer heuristiqueLRPT(Task t, Instance instance){
|
||||||
|
return instance.duration(t);
|
||||||
|
}
|
||||||
|
private Integer heuristiqueEST_SPT(Task t, Instance instance){
|
||||||
|
return instance.duration(t);
|
||||||
|
}
|
||||||
|
private Integer heuristiqueEST_LPT(Task t, Instance instance){
|
||||||
|
return instance.duration(t);
|
||||||
|
}
|
||||||
|
private Integer heuristiqueEST_SRPT(Task t, Instance instance){
|
||||||
|
return instance.duration(t);
|
||||||
|
}
|
||||||
|
private Integer heuristiqueEST_LRPT(Task t, Instance instance){
|
||||||
|
return instance.duration(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Task min(ArrayList<Task> lTask, Instance instance){
|
||||||
|
switch (priority) {
|
||||||
|
case SPT:
|
||||||
|
return(
|
||||||
|
lTask.stream()
|
||||||
|
.sorted(Comparator.comparing(e -> heuristiqueSPT(e, instance)))
|
||||||
|
.toArray(Task[]::new)[0]
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case LPT:
|
||||||
|
break;
|
||||||
|
case SRPT:
|
||||||
|
break;
|
||||||
|
case LRPT:
|
||||||
|
break;
|
||||||
|
case EST_SPT:
|
||||||
|
break;
|
||||||
|
case EST_LPT:
|
||||||
|
break;
|
||||||
|
case EST_SRPT:
|
||||||
|
break;
|
||||||
|
case EST_LRPT:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Schedule> solve(Instance instance, long deadline) {
|
public Optional<Schedule> solve(Instance instance, long deadline) {
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
|
ArrayList<Task> possibleTasks = new ArrayList<>();
|
||||||
|
/* Initialization */
|
||||||
|
for (int i = 0; i < instance.numJobs; i++){
|
||||||
|
possibleTasks.add(new Task(i, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Main Loop*/
|
||||||
|
while(possibleTasks.size() > 0){
|
||||||
|
Task task = min(possibleTasks,instance);
|
||||||
|
possibleTasks.remove(task);
|
||||||
|
// TODO : Add task to the solution
|
||||||
|
if ((task.task + 1) < instance.numTasks){
|
||||||
|
possibleTasks.add(new Task(task.job, task.task+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue