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