diff --git a/examples/jssp/problem/fitness.rs b/examples/jssp/problem/fitness.rs index f96bd10..7d02026 100644 --- a/examples/jssp/problem/fitness.rs +++ b/examples/jssp/problem/fitness.rs @@ -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 @@ -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() { @@ -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; @@ -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); } @@ -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,