solverforge_solver/manager/phase_factory/
construction.rs1use std::marker::PhantomData;
4
5use solverforge_core::domain::PlanningSolution;
6use solverforge_scoring::Director;
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 {
45 Self {
46 placer,
47 forager,
48 _marker: PhantomData,
49 }
50 }
51}
52
53impl<S, M, P> ConstructionPhaseFactory<S, M, P, FirstFitForager<S, M>>
54where
55 S: PlanningSolution,
56 M: Move<S>,
57 P: EntityPlacer<S, M>,
58{
59 pub fn first_fit(placer: P) -> Self {
60 Self::new(placer, FirstFitForager::new())
61 }
62}
63
64impl<S, M, P> ConstructionPhaseFactory<S, M, P, BestFitForager<S, M>>
65where
66 S: PlanningSolution,
67 M: Move<S>,
68 P: EntityPlacer<S, M>,
69{
70 pub fn best_fit(placer: P) -> Self {
71 Self::new(placer, BestFitForager::new())
72 }
73}
74
75impl<S, D, M, P, Fo> PhaseFactory<S, D> for ConstructionPhaseFactory<S, M, P, Fo>
76where
77 S: PlanningSolution,
78 D: Director<S>,
79 M: Move<S> + Clone + Send + Sync + 'static,
80 P: EntityPlacer<S, M> + Clone + Send + Sync + 'static,
81 Fo: ConstructionForager<S, M> + Clone + Send + Sync + 'static,
82{
83 type Phase = ConstructionHeuristicPhase<S, M, P, Fo>;
84
85 fn create(&self) -> Self::Phase {
86 ConstructionHeuristicPhase::new(self.placer.clone(), self.forager.clone())
87 }
88}