solverforge_solver/scope/
step.rs1use solverforge_core::domain::PlanningSolution;
4use solverforge_scoring::Director;
5
6use super::solver::ProgressCallback;
7use super::PhaseScope;
8
9pub struct StepScope<'t, 'a, 'b, S: PlanningSolution, D: Director<S>, BestCb = ()> {
19 phase_scope: &'a mut PhaseScope<'t, 'b, S, D, BestCb>,
21 step_index: u64,
23 step_score: Option<S::Score>,
25}
26
27impl<'t, 'a, 'b, S: PlanningSolution, D: Director<S>, BestCb: ProgressCallback<S>>
28 StepScope<'t, 'a, 'b, S, D, BestCb>
29{
30 pub fn new(phase_scope: &'a mut PhaseScope<'t, 'b, S, D, BestCb>) -> Self {
31 let step_index = phase_scope.step_count();
32 Self {
33 phase_scope,
34 step_index,
35 step_score: None,
36 }
37 }
38
39 pub fn step_index(&self) -> u64 {
40 self.step_index
41 }
42
43 pub fn step_score(&self) -> Option<&S::Score> {
44 self.step_score.as_ref()
45 }
46
47 pub fn set_step_score(&mut self, score: S::Score)
48 where
49 S::Score: Copy,
50 {
51 self.phase_scope.solver_scope_mut().set_current_score(score);
52 self.step_score = Some(score);
53 }
54
55 pub fn complete(&mut self) {
57 self.phase_scope.increment_step_count();
58 }
59
60 pub fn phase_scope(&self) -> &PhaseScope<'t, 'b, S, D, BestCb> {
61 self.phase_scope
62 }
63
64 pub fn phase_scope_mut(&mut self) -> &mut PhaseScope<'t, 'b, S, D, BestCb> {
65 self.phase_scope
66 }
67
68 pub fn score_director(&self) -> &D {
69 self.phase_scope.score_director()
70 }
71
72 pub fn score_director_mut(&mut self) -> &mut D {
73 self.phase_scope.score_director_mut()
74 }
75
76 pub fn calculate_score(&mut self) -> S::Score {
78 self.phase_scope.calculate_score()
79 }
80}