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
24Each move returns typed undo data from `do_move` and restores itself through
25`undo_move`; speculative evaluation does not use boxed callbacks.
26
27# Arena Allocation
28
29Use `MoveArena<M>` for O(1) per-step cleanup. Call `reset()` at each step
30instead of allocating a new Vec.
31
32# Zero-Erasure Design
33
34Moves are NEVER cloned. Ownership transfers via arena indices:
35
36```
37use solverforge_solver::heuristic::MoveArena;
38
39// Simple move type for demonstration
40struct SimpleMove { value: i32 }
41
42let mut arena: MoveArena<SimpleMove> = MoveArena::new();
43
44// Store moves - track indices manually
45arena.push(SimpleMove { value: 1 }); // index 0
46arena.push(SimpleMove { value: 2 }); // index 1
47
48// Take ownership from arena when picking
49let selected = arena.take(0);
50assert_eq!(selected.value, 1);
51
52// Reset clears arena for next step
53arena.reset();
54```
55*/
56
57mod arena;
58mod change;
59mod composite;
60mod compound_scalar;
61mod conflict_repair;
62mod dynamic_list_change;
63mod dynamic_scalar_change;
64mod k_opt;
65pub mod k_opt_reconnection;
66mod list_change;
67mod list_multi_swap;
68mod list_permute;
69mod list_reverse;
70mod list_ruin;
71mod list_swap;
72mod list_union;
73pub(crate) mod metadata;
74mod pillar_change;
75mod pillar_swap;
76mod ruin;
77mod ruin_recreate;
78mod scalar_union;
79mod segment_layout;
80mod sublist_change;
81mod sublist_swap;
82mod swap;
83mod traits;
84
85#[cfg(test)]
86mod tests;
87
88pub use arena::MoveArena;
89pub use change::ChangeMove;
90pub use composite::CompositeMove;
91pub use composite::SequentialCompositeMove;
92pub(crate) use composite::SequentialCompositeMoveRef;
93pub(crate) use composite::SequentialPreviewDirector;
94pub use compound_scalar::{CompoundScalarEdit, CompoundScalarMove, COMPOUND_SCALAR_VARIABLE};
95pub use conflict_repair::{ConflictRepairMove, ConflictRepairScalarEdit};
96pub use dynamic_list_change::DynamicListChangeMove;
97pub use dynamic_scalar_change::DynamicScalarChangeMove;
98pub use k_opt::{CutPoint, KOptMove};
99pub use list_change::ListChangeMove;
100pub use list_multi_swap::ListMultiSwapMove;
101pub use list_permute::{ListPermuteMove, MAX_LIST_PERMUTE_WINDOW_SIZE};
102pub use list_reverse::ListReverseMove;
103pub use list_ruin::ListRuinMove;
104pub use list_swap::ListSwapMove;
105pub use list_union::ListMoveUnion;
106pub use metadata::MoveTabuSignature;
107pub use pillar_change::PillarChangeMove;
108pub use pillar_swap::PillarSwapMove;
109pub use ruin::RuinMove;
110pub use ruin_recreate::{RuinRecreateMove, ScalarRecreateValueSource};
111pub use scalar_union::ScalarMoveUnion;
112pub use sublist_change::SublistChangeMove;
113pub use sublist_swap::SublistSwapMove;
114pub use swap::SwapMove;
115pub use traits::{Move, MoveAffectedEntity};