solverforge_solver/heuristic/selector/k_opt/config.rs
1//! Configuration for k-opt move generation.
2
3/// Configuration for k-opt move generation.
4#[derive(Debug, Clone)]
5pub struct KOptConfig {
6 /// The k value (2-5).
7 pub k: usize,
8 /// Minimum segment length between cuts (default: 1).
9 pub min_segment_len: usize,
10 /// Whether to use only a subset of reconnection patterns.
11 pub limited_patterns: bool,
12}
13
14impl KOptConfig {
15 /// Creates a new k-opt configuration.
16 ///
17 /// # Panics
18 ///
19 /// Panics if k < 2 or k > 5.
20 pub fn new(k: usize) -> Self {
21 assert!((2..=5).contains(&k), "k must be between 2 and 5");
22 Self {
23 k,
24 min_segment_len: 1,
25 limited_patterns: false,
26 }
27 }
28
29 /// Sets minimum segment length between cuts.
30 pub fn with_min_segment_len(mut self, len: usize) -> Self {
31 self.min_segment_len = len;
32 self
33 }
34
35 /// Enables limited pattern mode (faster but less thorough).
36 pub fn with_limited_patterns(mut self, limited: bool) -> Self {
37 self.limited_patterns = limited;
38 self
39 }
40}