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
use crate::{
macros::{RawComponent, RawConstraint},
model::{Component, ConstraintSystem},
};
use std::fmt::Debug;
pub fn make_component<T>(
n_variables: usize,
make_constraints: impl Fn(&[String], &[String]) -> Vec<RawConstraint<T>>,
) -> Component<T>
where
T: Debug + Clone + Default + 'static,
{
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 constraints: Vec<RawConstraint<T>> = make_constraints(&constraint_names, &variable_names);
let name = "0".to_string();
let comp = RawComponent::new(
name,
variable_names,
vec![T::default(); n_variables],
constraints,
);
comp.into_component()
}
pub fn make_cs<T>(
_: usize,
n_variables: usize,
make_constraints: impl Fn(&[String], &[String]) -> Vec<RawConstraint<T>>,
) -> ConstraintSystem<T>
where
T: Debug + Clone + Default + Send + 'static,
{
let component = make_component(n_variables, make_constraints);
let mut cs = ConstraintSystem::new();
cs.add_component(component);
cs
}