solverforge_solver/manager/phase_factory/
construction.rs1use std::marker::PhantomData;
4
5use solverforge_core::domain::PlanningSolution;
6use solverforge_scoring::ScoreDirector;
7
8use crate::heuristic::Move;
9use crate::phase::construction::{
10 BestFitForager, ConstructionForager, ConstructionHeuristicPhase, EntityPlacer, FirstFitForager,
11};
12
13use super::super::PhaseFactory;
14
15pub struct ConstructionPhaseFactory<S, M, P, Fo>
26where
27 S: PlanningSolution,
28 M: Move<S>,
29 P: EntityPlacer<S, M>,
30 Fo: ConstructionForager<S, M>,
31{
32 placer: P,
33 forager: Fo,
34 _marker: PhantomData<fn() -> (S, M)>,
35}
36
37impl<S, M, P, Fo> ConstructionPhaseFactory<S, M, P, Fo>
38where
39 S: PlanningSolution,
40 M: Move<S>,
41 P: EntityPlacer<S, M>,
42 Fo: ConstructionForager<S, M>,
43{
44 pub fn new(placer: P, forager: Fo) -> Self {
46 Self {
47 placer,
48 forager,
49 _marker: PhantomData,
50 }
51 }
52}
53
54impl<S, M, P> ConstructionPhaseFactory<S, M, P, FirstFitForager<S, M>>
55where
56 S: PlanningSolution,
57 M: Move<S>,
58 P: EntityPlacer<S, M>,
59{
60 pub fn first_fit(placer: P) -> Self {
62 Self::new(placer, FirstFitForager::new())
63 }
64}
65
66impl<S, M, P> ConstructionPhaseFactory<S, M, P, BestFitForager<S, M>>
67where
68 S: PlanningSolution,
69 M: Move<S>,
70 P: EntityPlacer<S, M>,
71{
72 pub fn best_fit(placer: P) -> Self {
74 Self::new(placer, BestFitForager::new())
75 }
76}
77
78impl<S, D, M, P, Fo> PhaseFactory<S, D> for ConstructionPhaseFactory<S, M, P, Fo>
79where
80 S: PlanningSolution,
81 D: ScoreDirector<S>,
82 M: Move<S> + Clone + Send + Sync + 'static,
83 P: EntityPlacer<S, M> + Clone + Send + Sync + 'static,
84 Fo: ConstructionForager<S, M> + Clone + Send + Sync + 'static,
85{
86 type Phase = ConstructionHeuristicPhase<S, M, P, Fo>;
87
88 fn create(&self) -> Self::Phase {
89 ConstructionHeuristicPhase::new(self.placer.clone(), self.forager.clone())
90 }
91}