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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Problem change trait for real-time planning.
use Debug;
use PlanningSolution;
use Director;
/// A change to the problem that can be applied during solving.
///
/// Problem changes allow modifying the solution while the solver is running.
/// Changes are queued and processed at step boundaries to maintain consistency.
///
/// # Implementation Notes
///
/// When implementing `ProblemChange`:
/// - Use `score_director.working_solution_mut()` to access and modify the solution
/// - Changes should be idempotent when possible
/// - Avoid holding references to entities across changes
///
/// # Example
///
/// ```
/// use solverforge_solver::realtime::ProblemChange;
/// use solverforge_scoring::Director;
/// use solverforge_core::domain::PlanningSolution;
/// use solverforge_core::score::SoftScore;
///
/// #[derive(Clone, Debug)]
/// struct Employee { id: usize, shift: Option<i32> }
///
/// #[derive(Clone, Debug)]
/// struct Schedule {
/// employees: Vec<Employee>,
/// 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; }
/// }
///
// /// Adds a new employee to the schedule.
/// #[derive(Debug)]
/// struct AddEmployee {
/// employee_id: usize,
/// }
///
/// impl ProblemChange<Schedule> for AddEmployee {
/// fn apply(&self, score_director: &mut dyn Director<Schedule>) {
/// // Add the new employee
/// score_director.working_solution_mut().employees.push(Employee {
/// id: self.employee_id,
/// shift: None,
/// });
///
/// }
/// }
///
/// /// Removes an employee from the schedule.
/// #[derive(Debug)]
/// struct RemoveEmployee {
/// employee_id: usize,
/// }
///
/// impl ProblemChange<Schedule> for RemoveEmployee {
/// fn apply(&self, score_director: &mut dyn Director<Schedule>) {
/// // Remove the employee
/// let id = self.employee_id;
/// score_director.working_solution_mut().employees.retain(|e| e.id != id);
/// }
/// }
/// ```
/// A boxed problem change for type-erased storage.
pub type BoxedProblemChange<S> = ;
/// A problem change implemented as a closure.
///
/// This is a convenience wrapper for simple changes that don't need
/// a dedicated struct.
///
/// # Example
///
/// ```
/// use solverforge_solver::realtime::ClosureProblemChange;
/// use solverforge_scoring::Director;
/// use solverforge_core::domain::PlanningSolution;
/// use solverforge_core::score::SoftScore;
///
/// #[derive(Clone, Debug)]
/// struct Task { id: usize, done: bool }
///
/// #[derive(Clone, Debug)]
/// struct Solution {
/// tasks: Vec<Task>,
/// score: Option<SoftScore>,
/// }
///
/// impl PlanningSolution for Solution {
/// type Score = SoftScore;
/// fn score(&self) -> Option<Self::Score> { self.score }
/// fn set_score(&mut self, score: Option<Self::Score>) { self.score = score; }
/// }
///
/// // Mark task 0 as done
/// let change = ClosureProblemChange::<Solution, _>::new("mark_task_done", |sd| {
/// if let Some(task) = sd.working_solution_mut().tasks.get_mut(0) {
/// task.done = true;
/// }
/// });
/// ```
+ Send,