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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/// The encoder for at-most-one and exactly-one constraints.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum AmoEncoder {
/// Pure encoding.
Pure,
/// Ladder encoding.
Ladder,
/// Product encoding.
Product {
/// Recursive bound for encoding.
recursive_bound: usize,
},
/// Nested encoding.
Nested {
/// Group size for encoding.
group_size: usize,
},
/// Commander encoding.
Commander {
/// Group size for encoding.
group_size: usize,
},
/// Binary encoding.
Binary,
/// Bimander encoding.
Bimander {
/// Group size for encoding.
group_size: BimanderGroupSize,
},
/// Best encoding algorithm.
Best,
}
/// The encoder for at-most-k constraints.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum AmkEncoder {
/// Totalizer encoding.
Totalizer,
/// Modular totalizer encoding.
ModularTotalizer,
/// Cardinality network.
CardinalityNetwork,
/// Best encoding.
Best,
}
/// The encoder for at-least-k constraints.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum AlkEncoder {
/// Totalizer encoding.
Totalizer,
/// Modular totalizer encoding.
ModularTotalizer,
/// Cardinality network.
CardinalityNetwork,
/// Best encoding.
Best,
}
/// The encoder for exactly-k constraints.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum ExkEncoder {
/// Totalizer encoding.
Totalizer,
/// Cardinality network.
CardinalityNetwork,
/// Best encoding.
Best,
}
/// The group size for the Bimander encoding.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum BimanderGroupSize {
/// Half.
Half,
/// Square root.
Sqrt,
/// Fixed size.
Fixed(usize),
}
/// Configuration for the [`CcEncoder`](`crate::cardinality_constraints::CcEncoder`).
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct CcConfig {
/// Encoder for at-most-one constraints.
pub amo_encoder: AmoEncoder,
/// Encoder for at-most-k constraints.
pub amk_encoder: AmkEncoder,
/// Encoder for at-least-k constraints.
pub alk_encoder: AlkEncoder,
/// Encoder for exactly-k constraints.
pub exk_encoder: ExkEncoder,
}
impl Default for CcConfig {
fn default() -> Self {
Self::new()
}
}
impl CcConfig {
/// Default size for `Bimander` encoding.
pub const DEFAULT_BIMANDER_GROUP_SIZE: usize = 3;
/// Default size for `Nested` encoding.
pub const DEFAULT_NESTING_GROUP_SIZE: usize = 4;
/// Default recursive bound for `Product` encoding.
pub const DEFAULT_PRODUCT_RECURSIVE_BOUND: usize = 20;
/// Default size for `Commander` encoding.
pub const DEFAULT_COMMANDER_GROUP_SIZE: usize = 3;
/// Creates a new configuration.
pub const fn new() -> Self {
Self { amo_encoder: AmoEncoder::Best, amk_encoder: AmkEncoder::Best, alk_encoder: AlkEncoder::Best, exk_encoder: ExkEncoder::Best }
}
/// Sets the encoder for at-most-one constraints.
#[must_use]
pub const fn amo_encoder(mut self, amo_encoder: AmoEncoder) -> Self {
self.amo_encoder = amo_encoder;
self
}
/// Sets the encoder for at-most-k constraints.
#[must_use]
pub const fn amk_encoder(mut self, amk_encoder: AmkEncoder) -> Self {
self.amk_encoder = amk_encoder;
self
}
/// Sets the encoder for at-least-k constraints.
#[must_use]
pub const fn alk_encoder(mut self, alk_encoder: AlkEncoder) -> Self {
self.alk_encoder = alk_encoder;
self
}
/// Sets the encoder for exactly-k constraints.
#[must_use]
pub const fn exk_encoder(mut self, exk_encoder: ExkEncoder) -> Self {
self.exk_encoder = exk_encoder;
self
}
}