solverforge_solver/scope/
step.rs

1//! Step-level scope.
2
3use solverforge_core::domain::PlanningSolution;
4use solverforge_scoring::ScoreDirector;
5
6use super::PhaseScope;
7
8/// Scope for a single step within a phase.
9pub struct StepScope<'a, 'b, S: PlanningSolution> {
10    /// Reference to the parent phase scope.
11    phase_scope: &'a mut PhaseScope<'b, S>,
12    /// Index of this step within the phase (0-based).
13    step_index: u64,
14    /// Score after this step.
15    step_score: Option<S::Score>,
16}
17
18impl<'a, 'b, S: PlanningSolution> StepScope<'a, 'b, S> {
19    /// Creates a new step scope.
20    pub fn new(phase_scope: &'a mut PhaseScope<'b, S>) -> Self {
21        let step_index = phase_scope.step_count();
22        Self {
23            phase_scope,
24            step_index,
25            step_score: None,
26        }
27    }
28
29    /// Returns the step index within the phase.
30    pub fn step_index(&self) -> u64 {
31        self.step_index
32    }
33
34    /// Returns the step score.
35    pub fn step_score(&self) -> Option<&S::Score> {
36        self.step_score.as_ref()
37    }
38
39    /// Sets the step score.
40    pub fn set_step_score(&mut self, score: S::Score) {
41        self.step_score = Some(score);
42    }
43
44    /// Marks this step as complete and increments counters.
45    pub fn complete(&mut self) {
46        self.phase_scope.increment_step_count();
47    }
48
49    /// Returns a reference to the phase scope.
50    pub fn phase_scope(&self) -> &PhaseScope<'b, S> {
51        self.phase_scope
52    }
53
54    /// Returns a mutable reference to the phase scope.
55    pub fn phase_scope_mut(&mut self) -> &mut PhaseScope<'b, S> {
56        self.phase_scope
57    }
58
59    /// Convenience: returns the score director.
60    pub fn score_director(&self) -> &dyn ScoreDirector<S> {
61        self.phase_scope.score_director()
62    }
63
64    /// Convenience: returns a mutable score director.
65    pub fn score_director_mut(&mut self) -> &mut dyn ScoreDirector<S> {
66        self.phase_scope.score_director_mut()
67    }
68
69    /// Convenience: calculates the current score.
70    pub fn calculate_score(&mut self) -> S::Score {
71        self.phase_scope.calculate_score()
72    }
73}