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 {
|
||||
|
||||
/** Name of the instance. Same as the filename from which the instance is loaded. */
|
||||
public final String name;
|
||||
|
||||
/** Number of jobs in the instance */
|
||||
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
|
||||
* <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.numTasks = numTasks;
|
||||
this.numMachines = numTasks;
|
||||
|
@ -71,19 +75,20 @@ public class Instance {
|
|||
|
||||
/** Parses a instance from a file. */
|
||||
public static Instance fromFile(Path path) throws IOException {
|
||||
String name = path.getFileName().toString();
|
||||
Iterator<String> lines = Files.readAllLines(path).stream()
|
||||
.filter(l -> !l.startsWith("#"))
|
||||
.collect(Collectors.toList())
|
||||
.iterator();
|
||||
|
||||
Scanner header = new Scanner(lines.next());
|
||||
int num_jobs = header.nextInt();
|
||||
int num_tasks = header.nextInt();
|
||||
Instance pb = new Instance(num_jobs, num_tasks);
|
||||
int numJobs = header.nextInt();
|
||||
int numTasks = header.nextInt();
|
||||
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());
|
||||
for(int task = 0 ; task < num_tasks ; task++) {
|
||||
for(int task = 0 ; task < numTasks ; task++) {
|
||||
pb.machines[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.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 {
|
||||
|
||||
/** 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
|
||||
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;
|
||||
|
||||
/** 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
|
||||
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 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 =
|
||||
IntStream.range(0, instance.numMachines) // all machines ...
|
||||
.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
|
||||
|
||||
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();
|
||||
int machine = instance.machine(t.job, t.task);
|
||||
|
||||
|
|
|
@ -5,6 +5,10 @@ import jobshop.Result;
|
|||
import jobshop.Solver;
|
||||
import jobshop.encodings.JobNumbers;
|
||||
|
||||
/**
|
||||
* A very naïve solver that first schedules
|
||||
*
|
||||
**/
|
||||
public class BasicSolver implements Solver {
|
||||
@Override
|
||||
public Result solve(Instance instance, long deadline) {
|
||||
|
|
Loading…
Reference in a new issue