solverforge_solver/planning/
conflict_repair.rs1use crate::planning::ScalarEdit;
2
3#[derive(Debug, Clone, Copy)]
4pub struct RepairLimits {
5 pub max_matches_per_step: usize,
6 pub max_repairs_per_match: usize,
7 pub max_moves_per_step: usize,
8}
9
10#[derive(Debug)]
11pub struct RepairCandidate<S> {
12 reason: &'static str,
13 edits: Vec<ScalarEdit<S>>,
14}
15
16impl<S> Clone for RepairCandidate<S> {
17 fn clone(&self) -> Self {
18 Self {
19 reason: self.reason,
20 edits: self.edits.clone(),
21 }
22 }
23}
24
25impl<S> PartialEq for RepairCandidate<S> {
26 fn eq(&self, other: &Self) -> bool {
27 self.reason == other.reason && self.edits == other.edits
28 }
29}
30
31impl<S> Eq for RepairCandidate<S> {}
32
33impl<S> std::hash::Hash for RepairCandidate<S> {
34 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
35 self.reason.hash(state);
36 self.edits.hash(state);
37 }
38}
39
40impl<S> RepairCandidate<S> {
41 pub fn new(reason: &'static str, edits: Vec<ScalarEdit<S>>) -> Self {
42 Self { reason, edits }
43 }
44
45 #[doc(hidden)]
46 #[inline]
47 pub fn reason(&self) -> &'static str {
48 self.reason
49 }
50
51 #[doc(hidden)]
52 #[inline]
53 pub fn edits(&self) -> &[ScalarEdit<S>] {
54 &self.edits
55 }
56
57 #[doc(hidden)]
58 #[inline]
59 pub fn into_edits(self) -> Vec<ScalarEdit<S>> {
60 self.edits
61 }
62}
63
64pub type RepairProvider<S> = fn(&S, RepairLimits) -> Vec<RepairCandidate<S>>;
65
66pub struct ConflictRepair<S> {
67 constraint_name: &'static str,
68 provider: RepairProvider<S>,
69}
70
71impl<S> ConflictRepair<S> {
72 pub const fn new(constraint_name: &'static str, provider: RepairProvider<S>) -> Self {
73 Self {
74 constraint_name,
75 provider,
76 }
77 }
78
79 #[doc(hidden)]
80 #[inline]
81 pub fn constraint_name(&self) -> &'static str {
82 self.constraint_name
83 }
84
85 #[doc(hidden)]
86 #[inline]
87 pub fn provider(&self) -> RepairProvider<S> {
88 self.provider
89 }
90}
91
92impl<S> std::fmt::Debug for ConflictRepair<S> {
93 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
94 f.debug_struct("ConflictRepair")
95 .field("constraint_name", &self.constraint_name)
96 .finish_non_exhaustive()
97 }
98}
99
100impl<S> Clone for ConflictRepair<S> {
101 fn clone(&self) -> Self {
102 *self
103 }
104}
105
106impl<S> Copy for ConflictRepair<S> {}