1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Stateless score analysis for planning solutions.
use PlanningSolution;
use Score;
// Analysis of a single constraint's contribution to the score.
// Result of analyzing a solution's constraints.
/// Trait for solutions that can be analyzed for constraint violations.
///
/// This trait is implemented by the `#[planning_solution]` macro when
/// `constraints` is specified. It provides constraint analysis without
/// knowing the concrete solution type.
///
/// # Example
///
/// ```
/// use solverforge_core::domain::PlanningSolution;
/// use solverforge_core::score::SoftScore;
/// use solverforge_solver::manager::{Analyzable, ScoreAnalysis, ConstraintAnalysis};
///
/// #[derive(Clone)]
/// struct Schedule {
/// score: Option<SoftScore>,
/// }
///
/// impl PlanningSolution for Schedule {
/// type Score = SoftScore;
/// fn score(&self) -> Option<Self::Score> { self.score }
/// fn set_score(&mut self, score: Option<Self::Score>) { self.score = score; }
/// }
///
/// impl Analyzable for Schedule {
/// fn analyze(&self) -> ScoreAnalysis<SoftScore> {
/// ScoreAnalysis {
/// score: SoftScore::of(0),
/// constraints: vec![],
/// }
/// }
/// }
///
/// let schedule = Schedule { score: Some(SoftScore::of(0)) };
/// let analysis = schedule.analyze();
/// assert_eq!(analysis.score, SoftScore::of(0));
/// ```
/// Analyzes a solution for constraint violations.
///
/// Returns a breakdown of each constraint's contribution to the score.
///
/// # Example
///
/// ```
/// use solverforge_core::domain::PlanningSolution;
/// use solverforge_core::score::SoftScore;
/// use solverforge_solver::manager::{analyze, Analyzable, ScoreAnalysis};
///
/// #[derive(Clone)]
/// struct Schedule { score: Option<SoftScore> }
///
/// impl PlanningSolution for Schedule {
/// type Score = SoftScore;
/// fn score(&self) -> Option<Self::Score> { self.score }
/// fn set_score(&mut self, score: Option<Self::Score>) { self.score = score; }
/// }
///
/// impl Analyzable for Schedule {
/// fn analyze(&self) -> ScoreAnalysis<SoftScore> {
/// ScoreAnalysis { score: SoftScore::of(0), constraints: vec![] }
/// }
/// }
///
/// let schedule = Schedule { score: Some(SoftScore::of(0)) };
/// let result = analyze(&schedule);
/// assert_eq!(result.score, SoftScore::of(0));
/// ```