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 k_opt;
63pub mod k_opt_reconnection;
64mod list_change;
65mod list_reverse;
66mod list_ruin;
67mod list_swap;
68mod list_union;
69pub(crate) mod metadata;
70mod pillar_change;
71mod pillar_swap;
72mod ruin;
73mod ruin_recreate;
74mod scalar_union;
75mod segment_layout;
76mod sublist_change;
77mod sublist_swap;
78mod swap;
79mod traits;
80
81#[cfg(test)]
82mod tests;
83
84pub use arena::MoveArena;
85pub use change::ChangeMove;
86pub use composite::CompositeMove;
87pub use composite::SequentialCompositeMove;
88pub(crate) use composite::SequentialCompositeMoveRef;
89pub(crate) use composite::SequentialPreviewDirector;
90pub use compound_scalar::{CompoundScalarEdit, CompoundScalarMove, COMPOUND_SCALAR_VARIABLE};
91pub use conflict_repair::{ConflictRepairMove, ConflictRepairScalarEdit};
92pub use k_opt::{CutPoint, KOptMove};
93pub use list_change::ListChangeMove;
94pub use list_reverse::ListReverseMove;
95pub use list_ruin::ListRuinMove;
96pub use list_swap::ListSwapMove;
97pub use list_union::ListMoveUnion;
98pub use metadata::MoveTabuSignature;
99pub use pillar_change::PillarChangeMove;
100pub use pillar_swap::PillarSwapMove;
101pub use ruin::RuinMove;
102pub use ruin_recreate::{RuinRecreateMove, ScalarRecreateValueSource};
103pub use scalar_union::ScalarMoveUnion;
104pub use sublist_change::SublistChangeMove;
105pub use sublist_swap::SublistSwapMove;
106pub use swap::SwapMove;
107pub use traits::{Move, MoveAffectedEntity};