Skip to main content

solverforge_solver/phase/partitioned/
child_phases.rs

1//! ChildPhases trait and tuple implementations.
2
3use solverforge_core::domain::PlanningSolution;
4use solverforge_scoring::Director;
5
6use crate::phase::Phase;
7use crate::scope::SolverScope;
8
9/// Trait for child phases that can solve a partition.
10///
11/// Implemented for tuples of phases via macro.
12pub trait ChildPhases<S, D>
13where
14    S: PlanningSolution,
15    D: Director<S>,
16{
17    /// Runs all child phases on the solver scope.
18    fn solve_all(&mut self, solver_scope: &mut SolverScope<S, D>);
19}
20
21// Implement ChildPhases for tuples using macro
22macro_rules! impl_child_phases_tuple {
23    ($($idx:tt: $P:ident),+) => {
24        impl<S, D, $($P),+> ChildPhases<S, D> for ($($P,)+)
25        where
26            S: PlanningSolution,
27            D: Director<S>,
28            $($P: Phase<S, D>,)+
29        {
30            fn solve_all(&mut self, solver_scope: &mut SolverScope<S, D>) {
31                $(
32                    self.$idx.solve(solver_scope);
33                )+
34            }
35        }
36    };
37}
38
39impl_child_phases_tuple!(0: P0);
40impl_child_phases_tuple!(0: P0, 1: P1);
41impl_child_phases_tuple!(0: P0, 1: P1, 2: P2);
42impl_child_phases_tuple!(0: P0, 1: P1, 2: P2, 3: P3);
43impl_child_phases_tuple!(0: P0, 1: P1, 2: P2, 3: P3, 4: P4);
44impl_child_phases_tuple!(0: P0, 1: P1, 2: P2, 3: P3, 4: P4, 5: P5);
45impl_child_phases_tuple!(0: P0, 1: P1, 2: P2, 3: P3, 4: P4, 5: P5, 6: P6);
46impl_child_phases_tuple!(0: P0, 1: P1, 2: P2, 3: P3, 4: P4, 5: P5, 6: P6, 7: P7);