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
use std::{fmt::Debug, sync::Arc};
use crate::{
macros::{RawComponent, RawConstraint, RawMethod},
model::ConstraintSystem,
};
pub fn make_dense_cs<T>(_: usize, n_variables: usize) -> ConstraintSystem<T>
where
T: Debug + Clone + Default + Send + 'static,
{
let apply = Arc::new(Ok);
let variable_names: Vec<String> = (0..n_variables)
.map(|id| "var".to_string() + &id.to_string())
.collect();
let constraint_names: Vec<String> = (0..n_variables)
.map(|id| "constraint".to_string() + &id.to_string())
.collect();
let mut cs = ConstraintSystem::new();
let mut constraints = Vec::new();
const STEP_SIZE: usize = 4;
for from_idx in (0..n_variables.saturating_sub(STEP_SIZE)).step_by(STEP_SIZE) {
for offset in 1..=4 {
let from = &variable_names[from_idx];
let to = &variable_names[from_idx + offset];
let constraint: RawConstraint<T> = RawConstraint::new(
&constraint_names[from_idx + offset],
vec![
RawMethod::new("right", vec![from], vec![to], apply.clone()),
RawMethod::new("left", vec![to], vec![from], apply.clone()),
],
);
constraints.push(constraint);
}
}
let name = "0".to_string();
let comp = RawComponent::new(
name,
variable_names,
vec![T::default(); n_variables],
constraints,
);
cs.add_component(comp.into_component());
cs
}