1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* K-opt move selector for tour optimization.
Generates k-opt moves by enumerating all valid cut point combinations
within selected entities and applying reconnection patterns.
# Complexity
For a route of length n and k-opt:
- Full enumeration: O(n^k) cut combinations × reconnection patterns
- Use `NearbyKOptMoveSelector` to reduce to O(n × m^(k-1)) with nearby selection
# Example
```
use solverforge_solver::heuristic::selector::k_opt::{KOptMoveSelector, KOptConfig};
use solverforge_solver::heuristic::selector::entity::FromSolutionEntitySelector;
use solverforge_core::domain::PlanningSolution;
use solverforge_core::score::SoftScore;
#[derive(Clone, Debug)]
struct Tour { cities: Vec<i32>, score: Option<SoftScore> }
impl PlanningSolution for Tour {
type Score = SoftScore;
fn score(&self) -> Option<Self::Score> { self.score }
fn set_score(&mut self, score: Option<Self::Score>) { self.score = score; }
}
fn list_len(s: &Tour, _: usize) -> usize { s.cities.len() }
fn sublist_remove(s: &mut Tour, _: usize, start: usize, end: usize) -> Vec<i32> {
s.cities.drain(start..end).collect()
}
fn sublist_insert(s: &mut Tour, _: usize, pos: usize, items: Vec<i32>) {
for (i, item) in items.into_iter().enumerate() {
s.cities.insert(pos + i, item);
}
}
let config = KOptConfig::new(3); // 3-opt
let selector = KOptMoveSelector::<Tour, i32, _>::new(
FromSolutionEntitySelector::new(0),
config,
list_len,
sublist_remove,
sublist_insert,
"cities",
0,
);
```
*/
pub use KOptConfig;
pub use ;
pub use ;
pub use NearbyKOptMoveSelector;
pub use KOptMoveSelector;