Improve documentation
This commit is contained in:
parent
dce9b786e9
commit
27a970026f
4 changed files with 20 additions and 11 deletions
|
@ -11,6 +11,9 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Instance {
|
public class Instance {
|
||||||
|
|
||||||
|
/** Name of the instance. Same as the filename from which the instance is loaded. */
|
||||||
|
public final String name;
|
||||||
|
|
||||||
/** Number of jobs in the instance */
|
/** Number of jobs in the instance */
|
||||||
public final int numJobs;
|
public final int numJobs;
|
||||||
|
|
||||||
|
@ -60,7 +63,8 @@ public class Instance {
|
||||||
* This should no be called directly. Instead, Instance objects should be created with the
|
* This should no be called directly. Instead, Instance objects should be created with the
|
||||||
* <code>Instance.fromFile()</code> static method.
|
* <code>Instance.fromFile()</code> static method.
|
||||||
*/
|
*/
|
||||||
Instance(int numJobs, int numTasks) {
|
Instance(String name, int numJobs, int numTasks) {
|
||||||
|
this.name = name;
|
||||||
this.numJobs = numJobs;
|
this.numJobs = numJobs;
|
||||||
this.numTasks = numTasks;
|
this.numTasks = numTasks;
|
||||||
this.numMachines = numTasks;
|
this.numMachines = numTasks;
|
||||||
|
@ -71,19 +75,20 @@ public class Instance {
|
||||||
|
|
||||||
/** Parses a instance from a file. */
|
/** Parses a instance from a file. */
|
||||||
public static Instance fromFile(Path path) throws IOException {
|
public static Instance fromFile(Path path) throws IOException {
|
||||||
|
String name = path.getFileName().toString();
|
||||||
Iterator<String> lines = Files.readAllLines(path).stream()
|
Iterator<String> lines = Files.readAllLines(path).stream()
|
||||||
.filter(l -> !l.startsWith("#"))
|
.filter(l -> !l.startsWith("#"))
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
.iterator();
|
.iterator();
|
||||||
|
|
||||||
Scanner header = new Scanner(lines.next());
|
Scanner header = new Scanner(lines.next());
|
||||||
int num_jobs = header.nextInt();
|
int numJobs = header.nextInt();
|
||||||
int num_tasks = header.nextInt();
|
int numTasks = header.nextInt();
|
||||||
Instance pb = new Instance(num_jobs, num_tasks);
|
Instance pb = new Instance(name, numJobs, numTasks);
|
||||||
|
|
||||||
for(int job = 0 ; job<num_jobs ; job++) {
|
for(int job = 0 ; job<numJobs ; job++) {
|
||||||
Scanner line = new Scanner(lines.next());
|
Scanner line = new Scanner(lines.next());
|
||||||
for(int task = 0 ; task < num_tasks ; task++) {
|
for(int task = 0 ; task < numTasks ; task++) {
|
||||||
pb.machines[job][task] = line.nextInt();
|
pb.machines[job][task] = line.nextInt();
|
||||||
pb.durations[job][task] = line.nextInt();
|
pb.durations[job][task] = line.nextInt();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
/** Représentation par numéro de job. */
|
/** Encoding of the solution of a jobshop problem by job numbers. */
|
||||||
public class JobNumbers extends Encoding {
|
public class JobNumbers extends Encoding {
|
||||||
|
|
||||||
/** A numJobs * numTasks array containing the representation by job numbers. */
|
/** A numJobs * numTasks array containing the representation by job numbers. */
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class ResourceOrder extends Encoding {
|
||||||
// executed on this machine in the same order
|
// executed on this machine in the same order
|
||||||
public final Task[][] tasksByMachine;
|
public final Task[][] tasksByMachine;
|
||||||
|
|
||||||
// for each machine, indicate on many tasks have been initialized
|
// for each machine, indicate how many tasks have been initialized
|
||||||
public final int[] nextFreeSlot;
|
public final int[] nextFreeSlot;
|
||||||
|
|
||||||
/** Creates a new empty resource order. */
|
/** Creates a new empty resource order. */
|
||||||
|
@ -71,10 +71,10 @@ public class ResourceOrder extends Encoding {
|
||||||
// loop while there remains a job that has unscheduled tasks
|
// loop while there remains a job that has unscheduled tasks
|
||||||
while(IntStream.range(0, instance.numJobs).anyMatch(m -> nextToScheduleByJob[m] < instance.numTasks)) {
|
while(IntStream.range(0, instance.numJobs).anyMatch(m -> nextToScheduleByJob[m] < instance.numTasks)) {
|
||||||
|
|
||||||
// selects a task that has noun scheduled predecessor on its job and machine :
|
// selects a task that has no unscheduled predecessor on its job and machine :
|
||||||
// - it is the next to be schedule on a machine
|
// - it is the next to be schedule on a machine
|
||||||
// - it is the next to be scheduled on its job
|
// - it is the next to be scheduled on its job
|
||||||
// if there is no such task, we have cyclic dependency and the solution is invalid
|
// If there is no such task, we have cyclic dependency and the solution is invalid.
|
||||||
Optional<Task> schedulable =
|
Optional<Task> schedulable =
|
||||||
IntStream.range(0, instance.numMachines) // all machines ...
|
IntStream.range(0, instance.numMachines) // all machines ...
|
||||||
.filter(m -> nextToScheduleByMachine[m] < instance.numJobs) // ... with unscheduled jobs
|
.filter(m -> nextToScheduleByMachine[m] < instance.numJobs) // ... with unscheduled jobs
|
||||||
|
@ -83,7 +83,7 @@ public class ResourceOrder extends Encoding {
|
||||||
.findFirst(); // select the first one if any
|
.findFirst(); // select the first one if any
|
||||||
|
|
||||||
if(schedulable.isPresent()) {
|
if(schedulable.isPresent()) {
|
||||||
// we found a schedulable task, lets call it t
|
// we have a schedulable task, lets call it t
|
||||||
Task t = schedulable.get();
|
Task t = schedulable.get();
|
||||||
int machine = instance.machine(t.job, t.task);
|
int machine = instance.machine(t.job, t.task);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,10 @@ import jobshop.Result;
|
||||||
import jobshop.Solver;
|
import jobshop.Solver;
|
||||||
import jobshop.encodings.JobNumbers;
|
import jobshop.encodings.JobNumbers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A very naïve solver that first schedules
|
||||||
|
*
|
||||||
|
**/
|
||||||
public class BasicSolver implements Solver {
|
public class BasicSolver implements Solver {
|
||||||
@Override
|
@Override
|
||||||
public Result solve(Instance instance, long deadline) {
|
public Result solve(Instance instance, long deadline) {
|
||||||
|
|
Loading…
Reference in a new issue