Added randomness input from arguments
This commit is contained in:
parent
08fb6be8bf
commit
c1b0b6e945
7 changed files with 7 additions and 26 deletions
|
@ -69,9 +69,7 @@ public class Main {
|
|||
List<String> solversToTest = ns.getList("solver");
|
||||
List<Solver> solvers = solversToTest.stream().map(Solver::getSolver).collect(Collectors.toList());
|
||||
|
||||
|
||||
// TODO : passer ca a la fonction
|
||||
//Integer randomness = (Integer) ns.getList("random").get(0);
|
||||
Integer randomness = ns.getInt("random");
|
||||
|
||||
// retrieve all instances on which we should run the solvers.
|
||||
List<String> instances = new ArrayList<>();
|
||||
|
@ -127,7 +125,7 @@ public class Main {
|
|||
long start = System.currentTimeMillis();
|
||||
long deadline = System.currentTimeMillis() + solveTimeMs;
|
||||
// run the solver on the current instance
|
||||
Optional<Schedule> result = solver.solve(instance, deadline);
|
||||
Optional<Schedule> result = solver.solve(instance, deadline,randomness);
|
||||
// measure elapsed time (in milliseconds)
|
||||
long runtime = System.currentTimeMillis() - start;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.Optional;
|
|||
**/
|
||||
public class BasicSolver implements Solver {
|
||||
@Override
|
||||
public Optional<Schedule> solve(Instance instance, long deadline) {
|
||||
public Optional<Schedule> solve(Instance instance, long deadline, int randomness) {
|
||||
|
||||
// resource order that will be populated (initially empty)
|
||||
ResourceOrder sol = new ResourceOrder(instance);
|
||||
|
|
|
@ -23,7 +23,7 @@ public class DescentSolver implements Solver {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Schedule> solve(Instance instance, long deadline) {
|
||||
public Optional<Schedule> solve(Instance instance, long deadline, int randomness) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,12 +27,6 @@ public class GreedySolver implements Solver {
|
|||
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){
|
||||
int sum = 0;
|
||||
// we sum all durations starting at the current tasks' in the job
|
||||
|
@ -44,13 +38,6 @@ public class GreedySolver implements Solver {
|
|||
private Integer heuristiqueEST(Task t, Instance instance, int[] machineStatus, int[] jobStatus){
|
||||
return Integer.max(machineStatus[instance.machine(t)], jobStatus[t.job]);
|
||||
}
|
||||
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 findNextTask(ArrayList<Task> lTask, Instance instance, int[] machineStatus, int[] jobStatus){
|
||||
switch (priority) {
|
||||
|
@ -140,10 +127,6 @@ public class GreedySolver implements Solver {
|
|||
|
||||
|
||||
@Override
|
||||
public Optional<Schedule> solve(Instance instance, long deadline) {
|
||||
return solve(instance,deadline,5);
|
||||
}
|
||||
|
||||
public Optional<Schedule> solve(Instance instance, long deadline, int percentRandom) {
|
||||
Random r = new Random();
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ public interface Solver {
|
|||
* This time is in milliseconds and can be compared with System.currentTimeMilliseconds()
|
||||
* @return An optional schedule that will be non empty if a solution was found.
|
||||
*/
|
||||
Optional<Schedule> solve(Instance instance, long deadline);
|
||||
Optional<Schedule> solve(Instance instance, long deadline, int randomness);
|
||||
|
||||
/** Static factory method to create a new solver based on its name. */
|
||||
static Solver getSolver(String name) {
|
||||
|
|
|
@ -16,7 +16,7 @@ public class BasicSolverTests {
|
|||
Instance instance = Instance.fromFile(Paths.get("instances/aaa1"));
|
||||
|
||||
Solver solver = new BasicSolver();
|
||||
Optional<Schedule> result = solver.solve(instance, System.currentTimeMillis() + 10);
|
||||
Optional<Schedule> result = solver.solve(instance, System.currentTimeMillis() + 10, 0);
|
||||
|
||||
assert result.isPresent() : "The solver did not find a solution";
|
||||
// extract the schedule associated to the solution
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ManualEncodingTests {
|
|||
this.instance = Instance.fromFile(Paths.get("instances/aaa1"));
|
||||
|
||||
Solver solver = new BasicSolver();
|
||||
Optional<Schedule> result = solver.solve(this.instance, System.currentTimeMillis() + 10);
|
||||
Optional<Schedule> result = solver.solve(this.instance, System.currentTimeMillis() + 10,0);
|
||||
|
||||
assert result.isPresent() : "The solver did not find a solution";
|
||||
// extract the schedule associated to the solution
|
||||
|
|
Loading…
Reference in a new issue