Skip to content

Commit

Permalink
refact(jssp): extract delay_g computation to spearate function (#446)
Browse files Browse the repository at this point in the history
## Description

This will allow for parameterization
  • Loading branch information
kkafar authored Oct 22, 2023
1 parent 031a41a commit 0cbd1d8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions examples/jssp/problem/fitness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl JsspFitness {
indv.reset();
}

// Resolving problem size. -2 because zero & sing dummy operations
// Resolving problem size. -2 because zero & sink dummy operations
let n: usize = indv.operations.len() - 2;

// TODO: This state is not hoisted, as we do not know the number of operations
Expand All @@ -58,13 +58,13 @@ impl JsspFitness {
let mut t_g = 0;

// Longest duration of a single opration
let max_dur = indv.operations.iter().map(|op| op.duration).max().unwrap();
let maxdur = indv.operations.iter().map(|op| op.duration).max().unwrap();

let mut last_finish_time = 0;
while self.scheduled.len() < n + 1 {
// Calculate the delay. The formula is taken straight from the paper.
// TODO: Parameterize this & conduct experiments
let mut delay = indv.chromosome[n + g - 1] * 1.5 * (max_dur as f64);
let mut delay = self.delay_for_g(indv, n, g, maxdur);
self.update_delay_feasible_set(indv, &finish_times, delay, t_g);

while !self.delay_feasibles.is_empty() {
Expand Down Expand Up @@ -95,7 +95,7 @@ impl JsspFitness {
let finish_time_j = finish_times
.iter()
.filter(|&&t| t != usize::MAX && t >= pred_j_finish)
.filter(|&&t| indv.machines[op_j.machine].is_idle(t..=t + op_j_duration))
.filter(|&&t| indv.machines[op_j_machine].is_idle(t..=t + op_j_duration))
.min()
.unwrap()
+ op_j_duration;
Expand All @@ -120,7 +120,7 @@ impl JsspFitness {
break;
}

delay = indv.chromosome[n + g - 1] * 1.5 * (max_dur as f64);
delay = self.delay_for_g(indv, n, g, maxdur);

self.update_delay_feasible_set(indv, &finish_times, delay, t_g);
}
Expand All @@ -136,6 +136,11 @@ impl JsspFitness {
makespan
}

#[inline(always)]
fn delay_for_g(&self, indv: &JsspIndividual, n: usize, g: usize, maxdur: usize) -> f64 {
indv.chromosome[n + g - 1] * 1.5 * (maxdur as f64)
}

fn update_delay_feasible_set(
&mut self,
indv: &JsspIndividual,
Expand Down

0 comments on commit 0cbd1d8

Please sign in to comment.