diff --git a/crates/solverforge-scoring/src/director/score_director/list_shadows.rs b/crates/solverforge-scoring/src/director/score_director/list_shadows.rs index 75ea7e76..0e93a5c9 100644 --- a/crates/solverforge-scoring/src/director/score_director/list_shadows.rs +++ b/crates/solverforge-scoring/src/director/score_director/list_shadows.rs @@ -177,10 +177,11 @@ impl ListShadowRows { cascade.open_changes += 1; } - /// Refreshes one owner's list structure for a cascading move and inserts - /// the owner's row; element rows stay retracted until the move's last - /// owner is refreshed, when the cascading values are propagated and every - /// pending element is inserted once. + /// Retracts the owner's arrivals from no list, refreshes its list + /// structure for a cascading move and inserts the owner's row; element + /// rows stay retracted until the move's last owner is refreshed, when the + /// cascading values are propagated and every pending element is inserted + /// once. pub(super) fn refresh_cascading_owner( &mut self, solution: &mut S, @@ -193,8 +194,8 @@ impl ListShadowRows { C: RowDeltas, { let mut delta = S::Score::zero(); - solution.update_list_structure_shadows(owner_descriptor, owner_index); - delta = delta + constraints.insert_row(solution, owner_index, owner_descriptor); + // The list already holds its arrivals; their structure shadows are + // rewritten only below, so their rows are retracted first. if let Some((source, elements)) = solution.list_shadow_elements(owner_descriptor, owner_index) { @@ -222,6 +223,8 @@ impl ListShadowRows { } } } + solution.update_list_structure_shadows(owner_descriptor, owner_index); + delta = delta + constraints.insert_row(solution, owner_index, owner_descriptor); let cascade = self .cascade .as_mut() diff --git a/crates/solverforge-scoring/src/director/tests/cascading_shadows.rs b/crates/solverforge-scoring/src/director/tests/cascading_shadows.rs index 731c6aff..33b512f1 100644 --- a/crates/solverforge-scoring/src/director/tests/cascading_shadows.rs +++ b/crates/solverforge-scoring/src/director/tests/cascading_shadows.rs @@ -159,7 +159,9 @@ type StartCost = IncrementalUniConstraint< >; // Each task costs its start, with its position and machine folded in so a -// stale previous pointer would also show; an unset start costs 1000. +// stale previous pointer would also show. An unset start costs 1000 in no +// list and 5000 on a machine (a dependency cycle), so a row retracted after +// its machine was written would also show. fn start_cost() -> StartCost { fn tasks(shop: &Shop) -> &[Task] { &shop.tasks @@ -174,6 +176,7 @@ fn start_cost() -> StartCost { + task.machine.map_or(0, |machine| machine as i64 + 1) + task.previous.map_or(0, |previous| previous as i64 * 100), ), + None if task.machine.is_some() => SoftScore::of(5000), None => SoftScore::of(1000), } }