Skip to main content

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 typed 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- `PillarChangeMove<S, V>` - changes multiple entities with same value
14- `PillarSwapMove<S, V>` - swaps between two pillars
15- `ListChangeMove<S, V>` - relocates an element in a list variable
16- `ListSwapMove<S, V>` - swaps two elements in list variables
17- `SubListChangeMove<S, V>` - relocates a contiguous sublist
18- `SubListSwapMove<S, V>` - swaps two contiguous sublists
19- `ListReverseMove<S, V>` - reverses a segment (2-opt for TSP)
20- `RuinMove<S, V>` - unassigns multiple entities (for Large Neighborhood Search)
21- `ListRuinMove<S, V>` - removes elements from a list (for LNS on list variables)
22
23Undo is handled by `RecordingDirector`, not by moves returning undo data.
24
25# Arena Allocation
26
27Use `MoveArena<M>` for O(1) per-step cleanup. Call `reset()` at each step
28instead of allocating a new Vec.
29
30# Zero-Erasure Design
31
32Moves are NEVER cloned. Ownership transfers via arena indices:
33
34```
35use solverforge_solver::heuristic::MoveArena;
36
37// Simple move type for demonstration
38struct SimpleMove { value: i32 }
39
40let mut arena: MoveArena<SimpleMove> = MoveArena::new();
41
42// Store moves - track indices manually
43arena.push(SimpleMove { value: 1 }); // index 0
44arena.push(SimpleMove { value: 2 }); // index 1
45
46// Take ownership from arena when picking
47let selected = arena.take(0);
48assert_eq!(selected.value, 1);
49
50// Reset clears arena for next step
51arena.reset();
52```
53*/
54
55mod arena;
56mod change;
57mod composite;
58mod either;
59mod k_opt;
60pub mod k_opt_reconnection;
61mod list_change;
62mod list_either;
63mod list_reverse;
64mod list_ruin;
65mod list_swap;
66mod pillar_change;
67mod pillar_swap;
68mod ruin;
69mod sublist_change;
70mod sublist_swap;
71mod swap;
72mod traits;
73
74#[cfg(test)]
75mod tests;
76
77pub use arena::MoveArena;
78pub use change::ChangeMove;
79pub use composite::CompositeMove;
80pub use either::EitherMove;
81pub use k_opt::{CutPoint, KOptMove};
82pub use list_change::ListChangeMove;
83pub use list_either::ListMoveImpl;
84pub use list_reverse::ListReverseMove;
85pub use list_ruin::ListRuinMove;
86pub use list_swap::ListSwapMove;
87pub use pillar_change::PillarChangeMove;
88pub use pillar_swap::PillarSwapMove;
89pub use ruin::RuinMove;
90pub use sublist_change::SubListChangeMove;
91pub use sublist_swap::SubListSwapMove;
92pub use swap::SwapMove;
93pub use traits::Move;