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 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 dynamic_scalar_swap;
65mod k_opt;
66pub mod k_opt_reconnection;
67mod list_change;
68pub(crate) mod list_kernel;
69mod list_multi_swap;
70mod list_permute;
71mod list_reverse;
72mod list_ruin;
73mod list_swap;
74mod list_union;
75pub(crate) mod metadata;
76mod pillar_change;
77mod pillar_swap;
78mod ruin;
79mod ruin_recreate;
80mod runtime_compound;
81mod scalar_union;
82mod segment_layout;
83mod sublist_change;
84mod sublist_swap;
85mod swap;
86mod traits;
87
88#[cfg(test)]
89mod tests;
90
91pub use arena::MoveArena;
92pub use change::ChangeMove;
93pub use composite::CompositeMove;
94pub use composite::SequentialCompositeMove;
95pub(crate) use composite::SequentialCompositeMoveRef;
96pub(crate) use composite::SequentialPreviewDirector;
97pub use compound_scalar::{CompoundScalarEdit, CompoundScalarMove, COMPOUND_SCALAR_VARIABLE};
98pub use conflict_repair::{ConflictRepairMove, ConflictRepairScalarEdit};
99pub use dynamic_list_change::DynamicListChangeMove;
100pub use dynamic_scalar_change::DynamicScalarChangeMove;
101pub use dynamic_scalar_swap::DynamicScalarSwapMove;
102pub use k_opt::{CutPoint, KOptMove};
103pub use list_change::ListChangeMove;
104pub use list_multi_swap::ListMultiSwapMove;
105pub use list_permute::{ListPermuteMove, MAX_LIST_PERMUTE_WINDOW_SIZE};
106pub use list_reverse::ListReverseMove;
107pub use list_ruin::ListRuinMove;
108pub use list_swap::ListSwapMove;
109pub use list_union::ListMoveUnion;
110pub use metadata::MoveTabuSignature;
111pub use pillar_change::PillarChangeMove;
112pub use pillar_swap::PillarSwapMove;
113pub use ruin::RuinMove;
114pub use ruin_recreate::{RuinRecreateMove, ScalarRecreateValueSource};
115#[cfg(test)]
116pub(crate) use runtime_compound::{
117    reset_runtime_compound_move_clone_count, runtime_compound_move_clone_count,
118};
119pub use runtime_compound::{RuntimeCompoundMove, RuntimeCompoundMoveKind};
120pub use scalar_union::ScalarMoveUnion;
121pub(crate) use segment_layout::{SegmentRelocationCoords, SegmentSwapCoords};
122pub use sublist_change::SublistChangeMove;
123pub use sublist_swap::SublistSwapMove;
124pub use swap::SwapMove;
125pub use traits::{Move, MoveAffectedEntity};