Skip to main content

solverforge_solver/phase/construction/
forager_impl.rs

1use solverforge_config::ConstructionObligation;
2use solverforge_core::domain::PlanningSolution;
3use solverforge_core::score::Score;
4use solverforge_scoring::Director;
5
6use super::forager::{
7    BestFitForager, ConstructionChoice, ConstructionForager, FirstFeasibleForager, FirstFitForager,
8    StrongestFitForager, WeakestFitForager,
9};
10use super::forager_step::{
11    select_best_fit_index, select_first_feasible_index, select_first_fit_index,
12    select_strongest_fit_index, select_weakest_fit_index,
13};
14use super::Placement;
15use crate::heuristic::r#move::Move;
16use crate::heuristic::selector::move_selector::MoveCursor;
17use crate::scope::{ProgressCallback, StepScope};
18
19impl<S, M> ConstructionForager<S, M> for FirstFitForager<S, M>
20where
21    S: PlanningSolution,
22    M: Move<S>,
23{
24    fn select_move_index<D, BestCb, C>(
25        &self,
26        placement: &mut Placement<S, M, C>,
27        construction_obligation: ConstructionObligation,
28        step_scope: &mut StepScope<'_, '_, '_, S, D, BestCb>,
29    ) -> Option<ConstructionChoice>
30    where
31        D: Director<S>,
32        BestCb: ProgressCallback<S>,
33        C: MoveCursor<S, M>,
34    {
35        select_first_fit_index(placement, construction_obligation, step_scope)
36    }
37}
38
39impl<S, M> ConstructionForager<S, M> for BestFitForager<S, M>
40where
41    S: PlanningSolution,
42    M: Move<S>,
43{
44    fn select_move_index<D, BestCb, C>(
45        &self,
46        placement: &mut Placement<S, M, C>,
47        construction_obligation: ConstructionObligation,
48        step_scope: &mut StepScope<'_, '_, '_, S, D, BestCb>,
49    ) -> Option<ConstructionChoice>
50    where
51        D: Director<S>,
52        BestCb: ProgressCallback<S>,
53        C: MoveCursor<S, M>,
54    {
55        select_best_fit_index(placement, construction_obligation, step_scope)
56    }
57}
58
59impl<S, M> ConstructionForager<S, M> for FirstFeasibleForager<S, M>
60where
61    S: PlanningSolution,
62    M: Move<S>,
63{
64    fn select_move_index<D, BestCb, C>(
65        &self,
66        placement: &mut Placement<S, M, C>,
67        construction_obligation: ConstructionObligation,
68        step_scope: &mut StepScope<'_, '_, '_, S, D, BestCb>,
69    ) -> Option<ConstructionChoice>
70    where
71        D: Director<S>,
72        BestCb: ProgressCallback<S>,
73        C: MoveCursor<S, M>,
74    {
75        select_first_feasible_index(placement, construction_obligation, step_scope)
76    }
77}
78
79impl<S, M> ConstructionForager<S, M> for WeakestFitForager<S, M>
80where
81    S: PlanningSolution,
82    S::Score: Score,
83    M: Move<S>,
84{
85    fn select_move_index<D, BestCb, C>(
86        &self,
87        placement: &mut Placement<S, M, C>,
88        construction_obligation: ConstructionObligation,
89        step_scope: &mut StepScope<'_, '_, '_, S, D, BestCb>,
90    ) -> Option<ConstructionChoice>
91    where
92        D: Director<S>,
93        BestCb: ProgressCallback<S>,
94        C: MoveCursor<S, M>,
95    {
96        select_weakest_fit_index(self, placement, construction_obligation, step_scope)
97    }
98}
99
100impl<S, M> ConstructionForager<S, M> for StrongestFitForager<S, M>
101where
102    S: PlanningSolution,
103    S::Score: Score,
104    M: Move<S>,
105{
106    fn select_move_index<D, BestCb, C>(
107        &self,
108        placement: &mut Placement<S, M, C>,
109        construction_obligation: ConstructionObligation,
110        step_scope: &mut StepScope<'_, '_, '_, S, D, BestCb>,
111    ) -> Option<ConstructionChoice>
112    where
113        D: Director<S>,
114        BestCb: ProgressCallback<S>,
115        C: MoveCursor<S, M>,
116    {
117        select_strongest_fit_index(self, placement, construction_obligation, step_scope)
118    }
119}