solverforge_solver/builder/context/
conflict_repair.rs1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
4pub struct ConflictRepairEdit {
5 pub descriptor_index: usize,
6 pub entity_index: usize,
7 pub variable_name: &'static str,
8 pub to_value: Option<usize>,
9}
10
11impl ConflictRepairEdit {
12 pub fn set_scalar(
13 descriptor_index: usize,
14 entity_index: usize,
15 variable_name: &'static str,
16 to_value: Option<usize>,
17 ) -> Self {
18 Self {
19 descriptor_index,
20 entity_index,
21 variable_name,
22 to_value,
23 }
24 }
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28pub struct ConflictRepairSpec {
29 pub reason: &'static str,
30 pub edits: Vec<ConflictRepairEdit>,
31}
32
33impl ConflictRepairSpec {
34 pub fn new(reason: &'static str, edits: Vec<ConflictRepairEdit>) -> Self {
35 Self { reason, edits }
36 }
37}
38
39#[derive(Debug, Clone, Copy)]
40pub struct ConflictRepairLimits {
41 pub max_matches_per_step: usize,
42 pub max_repairs_per_match: usize,
43 pub max_moves_per_step: usize,
44}
45
46pub type ConflictRepairProvider<S> = fn(&S, ConflictRepairLimits) -> Vec<ConflictRepairSpec>;
47
48pub struct ConflictRepairProviderEntry<S> {
49 pub constraint_name: &'static str,
50 pub provider: ConflictRepairProvider<S>,
51}
52
53impl<S> ConflictRepairProviderEntry<S> {
54 pub const fn new(constraint_name: &'static str, provider: ConflictRepairProvider<S>) -> Self {
55 Self {
56 constraint_name,
57 provider,
58 }
59 }
60}
61
62impl<S> fmt::Debug for ConflictRepairProviderEntry<S> {
63 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64 f.debug_struct("ConflictRepairProviderEntry")
65 .field("constraint_name", &self.constraint_name)
66 .finish_non_exhaustive()
67 }
68}
69
70impl<S> Clone for ConflictRepairProviderEntry<S> {
71 fn clone(&self) -> Self {
72 *self
73 }
74}
75
76impl<S> Copy for ConflictRepairProviderEntry<S> {}