solverforge_solver/heuristic/move/mod.rs
1/* Move system for modifying planning solutions.
2
3Moves are the fundamental operations that modify planning variables during
4solving. The solver explores the solution space by applying different moves
5and evaluating their impact on the score.
6
7# Architecture
8
9All moves are fully monomorphized with inline value storage for maximum performance:
10- `ChangeMove<S, V>` - assigns a value to a variable
11- `SwapMove<S, V>` - swaps values between two entities
12- `CompositeMove<'a, S, M1, M2>` - applies two moves by reference
13- `SequentialCompositeMove<S, M>` - applies two owned moves in sequence
14- `PillarChangeMove<S, V>` - changes multiple entities with same value
15- `PillarSwapMove<S, V>` - swaps between two pillars
16- `ListChangeMove<S, V>` - relocates an element in a list variable
17- `ListSwapMove<S, V>` - swaps two elements in list variables
18- `SublistChangeMove<S, V>` - relocates a contiguous sublist
19- `SublistSwapMove<S, V>` - swaps two contiguous sublists
20- `ListReverseMove<S, V>` - reverses a segment (2-opt for TSP)
21- `RuinMove<S, V>` - unassigns multiple entities (for Large Neighborhood Search)
22- `ListRuinMove<S, V>` - removes elements from a list (for LNS on list variables)
23
24Undo is handled by `RecordingDirector`, not by moves returning undo data.
25
26# Arena Allocation
27
28Use `MoveArena<M>` for O(1) per-step cleanup. Call `reset()` at each step
29instead of allocating a new Vec.
30
31# Zero-Erasure Design
32
33Moves are NEVER cloned. Ownership transfers via arena indices:
34
35```
36use solverforge_solver::heuristic::MoveArena;
37
38// Simple move type for demonstration
39struct SimpleMove { value: i32 }
40
41let mut arena: MoveArena<SimpleMove> = MoveArena::new();
42
43// Store moves - track indices manually
44arena.push(SimpleMove { value: 1 }); // index 0
45arena.push(SimpleMove { value: 2 }); // index 1
46
47// Take ownership from arena when picking
48let selected = arena.take(0);
49assert_eq!(selected.value, 1);
50
51// Reset clears arena for next step
52arena.reset();
53```
54*/
55
56mod arena;
57mod change;
58mod composite;
59mod compound_scalar;
60mod conflict_repair;
61mod k_opt;
62pub mod k_opt_reconnection;
63mod list_change;
64mod list_reverse;
65mod list_ruin;
66mod list_swap;
67mod list_union;
68pub(crate) mod metadata;
69mod pillar_change;
70mod pillar_swap;
71mod ruin;
72mod ruin_recreate;
73mod scalar_union;
74mod segment_layout;
75mod sublist_change;
76mod sublist_swap;
77mod swap;
78mod traits;
79
80#[cfg(test)]
81mod tests;
82
83pub use arena::MoveArena;
84pub use change::ChangeMove;
85pub use composite::CompositeMove;
86pub use composite::SequentialCompositeMove;
87pub(crate) use composite::SequentialCompositeMoveRef;
88pub(crate) use composite::SequentialPreviewDirector;
89pub use compound_scalar::{CompoundScalarEdit, CompoundScalarMove, COMPOUND_SCALAR_VARIABLE};
90pub use conflict_repair::{ConflictRepairMove, ConflictRepairScalarEdit};
91pub use k_opt::{CutPoint, KOptMove};
92pub use list_change::ListChangeMove;
93pub use list_reverse::ListReverseMove;
94pub use list_ruin::ListRuinMove;
95pub use list_swap::ListSwapMove;
96pub use list_union::ListMoveUnion;
97pub use metadata::MoveTabuSignature;
98pub use pillar_change::PillarChangeMove;
99pub use pillar_swap::PillarSwapMove;
100pub use ruin::RuinMove;
101pub use ruin_recreate::{RuinRecreateMove, ScalarRecreateValueSource};
102pub use scalar_union::ScalarMoveUnion;
103pub use sublist_change::SublistChangeMove;
104pub use sublist_swap::SublistSwapMove;
105pub use swap::SwapMove;
106pub use traits::{Move, MoveAffectedEntity};