solverforge_solver/heuristic/move/traits.rs
1// Move trait definition.
2
3use std::fmt::Debug;
4
5use solverforge_core::domain::PlanningSolution;
6use solverforge_scoring::Director;
7
8/// A move that modifies one or more planning variables.
9///
10/// Moves are fully typed for maximum performance - no boxing, no virtual dispatch.
11/// Undo is handled by `RecordingDirector`, not by move return values.
12///
13/// # Type Parameters
14/// * `S` - The planning solution type
15///
16/// # Implementation Notes
17/// - Moves should be lightweight
18/// - Use `RecordingDirector` to wrap the score director for automatic undo
19/// - Moves are NEVER cloned - ownership transfers via arena indices
20/// - Methods are generic over D to allow use with both concrete directors and RecordingDirector
21pub trait Move<S: PlanningSolution>: Send + Sync + Debug {
22 /* Returns true if this move can be executed in the current state.
23
24 A move is not doable if:
25 - The source value equals the destination value (no change)
26 - Required entities are pinned
27 - The move would violate hard constraints that can be detected early
28 */
29 fn is_doable<D: Director<S>>(&self, score_director: &D) -> bool;
30
31 /* Executes this move, modifying the working solution.
32
33 This method modifies the planning variables through the score director.
34 Use `RecordingDirector` to enable automatic undo via `undo_changes()`.
35 */
36 fn do_move<D: Director<S>>(&self, score_director: &mut D);
37
38 fn descriptor_index(&self) -> usize;
39
40 fn entity_indices(&self) -> &[usize];
41
42 fn variable_name(&self) -> &str;
43}