pub struct Pldag {
pub storage: Arc<dyn NodeStoreTrait>,
/* private fields */
}Expand description
A Primitive Logic Directed Acyclic Graph (PL-DAG).
The PL-DAG represents a logical system where:
- Primitive nodes are leaf variables with bounds
- Composite nodes represent logical constraints over other nodes
- Each node has an associated coefficient for accumulation operations
The DAG structure ensures no cycles and enables efficient bottom-up propagation.
Fields§
§storage: Arc<dyn NodeStoreTrait>Store for mapping node IDs to their corresponding nodes, supporting multiple access patterns
Implementations§
Source§impl Pldag
impl Pldag
Sourcepub fn new() -> Pldag
pub fn new() -> Pldag
Examples found in repository?
4fn main() {
5 // Build your PL-DAG
6 // For example, we create a model of three boolean variables x, y and z.
7 // We bind them to an OR constraint.
8 let mut pldag: Pldag = Pldag::new();
9
10 // First setup the primitive variables
11 pldag.set_primitive("x", (0, 1));
12 pldag.set_primitive("y", (0, 1));
13 pldag.set_primitive("z", (0, 1));
14
15 // A reference ID is returned
16 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
17
18 // Export a sub dag
19 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
20
21 // 1. Validate a combination:
22 let mut inputs: HashMap<&str, Bound> = HashMap::new();
23 let validated = Pldag::propagate_dag(&mut dag, inputs.clone()).unwrap();
24 // Since nothing is given, and all other variables implicitly have bounds (0, 1) from the pldag model,
25 // the root will be (0,1) since there's not enough information to evaluate the root `or` node.
26 println!("Root valid? {}", *validated.get(&root).unwrap() == (1, 1)); // This will be false
27
28 // If we however fix x to be zero, then we can check the result
29 inputs.insert("x", (0, 0));
30 let revalidated = pldag.propagate(inputs.clone()).unwrap();
31 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be false
32
33 // However, fixing y and z to 1 will yield the root node to be true (since the root will be true if any of x, y or z is true).
34 inputs.insert("y", (1, 1));
35 inputs.insert("z", (1, 1));
36 let revalidated = pldag.propagate(inputs.clone()).unwrap();
37 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be true
38
39 // Build a simple OR‑of‑three model
40 let mut pldag = Pldag::new();
41 pldag.set_primitive("x", (0, 1));
42 pldag.set_primitive("y", (0, 1));
43 pldag.set_primitive("z", (0, 1));
44 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
45 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
46
47 // 1. Validate a combination
48 let validated = dag.propagate(inputs).unwrap();
49 println!("root bound = {:?}", validated[&root]);
50}pub fn new_custom(storage: Arc<dyn NodeStoreTrait>) -> Pldag
Sourcepub fn set_validate_coeffs(self, validate_coeffs: bool) -> Self
pub fn set_validate_coeffs(self, validate_coeffs: bool) -> Self
Sets whether to validate that coefficients exists on insertion, guaranteeing a valid DAG, at the cost of extra lookups on insertion. Default value is true.
Sourcepub fn tighten(
dag: &CompiledDag,
assumptions: &HashMap<String, Bound>,
) -> Result<HashMap<String, Bound>>
pub fn tighten( dag: &CompiledDag, assumptions: &HashMap<String, Bound>, ) -> Result<HashMap<String, Bound>>
Full tightening over the DAG given initial assumptions.
dag: mapping from node name to Node (Primitive / Composite)assumptions: mapping from node name to assumed bound, e.g. “A” -> (1,1) means boolean node A is TRUE.
Returns an HashMap of final bounds for all nodes (primitives + composite booleans).
pub fn reduce( dag: &CompiledDag, fixed: &HashMap<String, i32>, ) -> Result<CompiledDag>
Sourcepub fn propagate_dag<K>(
dag: &mut CompiledDag,
assignments: impl IntoIterator<Item = (K, Bound)>,
) -> Result<HashMap<ID, Bound>>where
K: ToString,
pub fn propagate_dag<K>(
dag: &mut CompiledDag,
assignments: impl IntoIterator<Item = (K, Bound)>,
) -> Result<HashMap<ID, Bound>>where
K: ToString,
Static propagation function that works on any DAG without requiring storage.
This is useful when you need to propagate bounds through a sub-DAG or a DAG that is not stored in the main Pldag storage.
§Arguments
dag- HashMap mapping node IDs to their corresponding nodesassignments- Initial assignment of bounds to variables
§Returns
Complete assignment including bounds for all reachable nodes
Examples found in repository?
4fn main() {
5 // Build your PL-DAG
6 // For example, we create a model of three boolean variables x, y and z.
7 // We bind them to an OR constraint.
8 let mut pldag: Pldag = Pldag::new();
9
10 // First setup the primitive variables
11 pldag.set_primitive("x", (0, 1));
12 pldag.set_primitive("y", (0, 1));
13 pldag.set_primitive("z", (0, 1));
14
15 // A reference ID is returned
16 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
17
18 // Export a sub dag
19 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
20
21 // 1. Validate a combination:
22 let mut inputs: HashMap<&str, Bound> = HashMap::new();
23 let validated = Pldag::propagate_dag(&mut dag, inputs.clone()).unwrap();
24 // Since nothing is given, and all other variables implicitly have bounds (0, 1) from the pldag model,
25 // the root will be (0,1) since there's not enough information to evaluate the root `or` node.
26 println!("Root valid? {}", *validated.get(&root).unwrap() == (1, 1)); // This will be false
27
28 // If we however fix x to be zero, then we can check the result
29 inputs.insert("x", (0, 0));
30 let revalidated = pldag.propagate(inputs.clone()).unwrap();
31 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be false
32
33 // However, fixing y and z to 1 will yield the root node to be true (since the root will be true if any of x, y or z is true).
34 inputs.insert("y", (1, 1));
35 inputs.insert("z", (1, 1));
36 let revalidated = pldag.propagate(inputs.clone()).unwrap();
37 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be true
38
39 // Build a simple OR‑of‑three model
40 let mut pldag = Pldag::new();
41 pldag.set_primitive("x", (0, 1));
42 pldag.set_primitive("y", (0, 1));
43 pldag.set_primitive("z", (0, 1));
44 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
45 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
46
47 // 1. Validate a combination
48 let validated = dag.propagate(inputs).unwrap();
49 println!("root bound = {:?}", validated[&root]);
50}Sourcepub fn propagate<K>(
&self,
assignments: impl IntoIterator<Item = (K, Bound)>,
) -> Result<HashMap<ID, Bound>>where
K: ToString,
pub fn propagate<K>(
&self,
assignments: impl IntoIterator<Item = (K, Bound)>,
) -> Result<HashMap<ID, Bound>>where
K: ToString,
Propagates bounds through the DAG bottom-up.
Starting from the given variable assignments, this method computes bounds for all composite nodes by propagating constraints upward through the DAG.
§Arguments
assignment- Initial assignment of bounds to variablesto_root- Optional root node to end propagation at
§Returns
Complete assignment including bounds for all reachable nodes
Examples found in repository?
4fn main() {
5 // Build your PL-DAG
6 // For example, we create a model of three boolean variables x, y and z.
7 // We bind them to an OR constraint.
8 let mut pldag: Pldag = Pldag::new();
9
10 // First setup the primitive variables
11 pldag.set_primitive("x", (0, 1));
12 pldag.set_primitive("y", (0, 1));
13 pldag.set_primitive("z", (0, 1));
14
15 // A reference ID is returned
16 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
17
18 // Export a sub dag
19 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
20
21 // 1. Validate a combination:
22 let mut inputs: HashMap<&str, Bound> = HashMap::new();
23 let validated = Pldag::propagate_dag(&mut dag, inputs.clone()).unwrap();
24 // Since nothing is given, and all other variables implicitly have bounds (0, 1) from the pldag model,
25 // the root will be (0,1) since there's not enough information to evaluate the root `or` node.
26 println!("Root valid? {}", *validated.get(&root).unwrap() == (1, 1)); // This will be false
27
28 // If we however fix x to be zero, then we can check the result
29 inputs.insert("x", (0, 0));
30 let revalidated = pldag.propagate(inputs.clone()).unwrap();
31 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be false
32
33 // However, fixing y and z to 1 will yield the root node to be true (since the root will be true if any of x, y or z is true).
34 inputs.insert("y", (1, 1));
35 inputs.insert("z", (1, 1));
36 let revalidated = pldag.propagate(inputs.clone()).unwrap();
37 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be true
38
39 // Build a simple OR‑of‑three model
40 let mut pldag = Pldag::new();
41 pldag.set_primitive("x", (0, 1));
42 pldag.set_primitive("y", (0, 1));
43 pldag.set_primitive("z", (0, 1));
44 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
45 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
46
47 // 1. Validate a combination
48 let validated = dag.propagate(inputs).unwrap();
49 println!("root bound = {:?}", validated[&root]);
50}Sourcepub fn ranks(cd: &CompiledDag) -> Result<HashMap<ID, usize>>
pub fn ranks(cd: &CompiledDag) -> Result<HashMap<ID, usize>>
Computes ranks for all nodes in the DAG. Ranks represent the longest distance from any root node to each node.
dag- mapping from node name to Node (Primitive / Composite)
§Returns
A HashMap of node IDs to their corresponding ranks
pub fn topological_sort( dag: &HashMap<ID, Node>, dependency_map: &HashMap<ID, Vec<ID>>, ) -> Result<Vec<ID>>
pub fn dependency_map(dag: &HashMap<ID, Node>) -> HashMap<ID, Vec<ID>>
Sourcepub fn sub_dag(&self, roots: Vec<ID>) -> Result<CompiledDag>
pub fn sub_dag(&self, roots: Vec<ID>) -> Result<CompiledDag>
Extracts a sub-DAG containing all nodes reachable from the given roots. NOTE: if roots is empty, returns the entire DAG.
§Arguments
roots- Vector of root node IDs to start the sub-DAG extraction
§Returns
A HashMap of node IDs to their corresponding nodes in the sub-DAG
Examples found in repository?
4fn main() {
5 // Build your PL-DAG
6 // For example, we create a model of three boolean variables x, y and z.
7 // We bind them to an OR constraint.
8 let mut pldag: Pldag = Pldag::new();
9
10 // First setup the primitive variables
11 pldag.set_primitive("x", (0, 1));
12 pldag.set_primitive("y", (0, 1));
13 pldag.set_primitive("z", (0, 1));
14
15 // A reference ID is returned
16 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
17
18 // Export a sub dag
19 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
20
21 // 1. Validate a combination:
22 let mut inputs: HashMap<&str, Bound> = HashMap::new();
23 let validated = Pldag::propagate_dag(&mut dag, inputs.clone()).unwrap();
24 // Since nothing is given, and all other variables implicitly have bounds (0, 1) from the pldag model,
25 // the root will be (0,1) since there's not enough information to evaluate the root `or` node.
26 println!("Root valid? {}", *validated.get(&root).unwrap() == (1, 1)); // This will be false
27
28 // If we however fix x to be zero, then we can check the result
29 inputs.insert("x", (0, 0));
30 let revalidated = pldag.propagate(inputs.clone()).unwrap();
31 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be false
32
33 // However, fixing y and z to 1 will yield the root node to be true (since the root will be true if any of x, y or z is true).
34 inputs.insert("y", (1, 1));
35 inputs.insert("z", (1, 1));
36 let revalidated = pldag.propagate(inputs.clone()).unwrap();
37 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be true
38
39 // Build a simple OR‑of‑three model
40 let mut pldag = Pldag::new();
41 pldag.set_primitive("x", (0, 1));
42 pldag.set_primitive("y", (0, 1));
43 pldag.set_primitive("z", (0, 1));
44 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
45 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
46
47 // 1. Validate a combination
48 let validated = dag.propagate(inputs).unwrap();
49 println!("root bound = {:?}", validated[&root]);
50}pub fn dag(&self) -> CompiledDag
Sourcepub fn to_sparse_polyhedron(
cd: &CompiledDag,
double_binding: bool,
) -> Result<SparsePolyhedron>
pub fn to_sparse_polyhedron( cd: &CompiledDag, double_binding: bool, ) -> Result<SparsePolyhedron>
Converts the PL-DAG to a sparse polyhedron for ILP solving.
Transforms the logical constraints in the DAG into a system of linear inequalities suitable for integer linear programming solvers.
§Arguments
dag- mapping from node ID to Node (Primitive / Composite)double_binding- If true, creates bidirectional implications for composite nodes
§Returns
A SparsePolyhedron representing the DAG constraints
Sourcepub fn to_sparse_polyhedron_default(
cd: &CompiledDag,
) -> Result<SparsePolyhedron>
pub fn to_sparse_polyhedron_default( cd: &CompiledDag, ) -> Result<SparsePolyhedron>
Converts the PL-DAG to a sparse polyhedron with default settings.
Convenience method that calls to_sparse_polyhedron with all options enabled:
double_binding=true, integer_constraints=true, fixed_constraints=true.
§Returns
A SparsePolyhedron with full constraint encoding
Sourcepub fn to_dense_polyhedron(
cd: &CompiledDag,
double_binding: bool,
) -> Result<DensePolyhedron>
pub fn to_dense_polyhedron( cd: &CompiledDag, double_binding: bool, ) -> Result<DensePolyhedron>
Sourcepub fn to_dense_polyhedron_default(cd: &CompiledDag) -> Result<DensePolyhedron>
pub fn to_dense_polyhedron_default(cd: &CompiledDag) -> Result<DensePolyhedron>
Converts the PL-DAG to a dense polyhedron with default settings.
§Returns
A DensePolyhedron with all constraint options enabled
Sourcepub fn get_primitives(dag: &CompiledDag) -> Vec<String>
pub fn get_primitives(dag: &CompiledDag) -> Vec<String>
Retrieves all primitive variables from the given PL-DAG roots.
§Returns
An HashMap mapping variable IDs to their corresponding Bound objects
Sourcepub fn get_composites(dag: &CompiledDag) -> Vec<String>
pub fn get_composites(dag: &CompiledDag) -> Vec<String>
Retrieves all composite constraints from the PL-DAG.
§Returns
An HashMap mapping constraint IDs to their corresponding Constraint objects
Sourcepub fn delete_node(&mut self, id: &str) -> Result<()>
pub fn delete_node(&mut self, id: &str) -> Result<()>
Deletes a node from the PL-DAG by its ID.
§Arguments
id- The unique identifier of the node to delete
Note:
Returns nothing.
Sourcepub fn set_primitive(&mut self, id: &str, bound: Bound) -> Result<ID>
pub fn set_primitive(&mut self, id: &str, bound: Bound) -> Result<ID>
Creates a primitive (leaf) variable with the specified bounds.
Primitive variables represent the base variables in the DAG and have no dependencies on other nodes.
§Arguments
id- Unique identifier for the variablebound- The allowed range (min, max) for this variable
Examples found in repository?
4fn main() {
5 // Build your PL-DAG
6 // For example, we create a model of three boolean variables x, y and z.
7 // We bind them to an OR constraint.
8 let mut pldag: Pldag = Pldag::new();
9
10 // First setup the primitive variables
11 pldag.set_primitive("x", (0, 1));
12 pldag.set_primitive("y", (0, 1));
13 pldag.set_primitive("z", (0, 1));
14
15 // A reference ID is returned
16 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
17
18 // Export a sub dag
19 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
20
21 // 1. Validate a combination:
22 let mut inputs: HashMap<&str, Bound> = HashMap::new();
23 let validated = Pldag::propagate_dag(&mut dag, inputs.clone()).unwrap();
24 // Since nothing is given, and all other variables implicitly have bounds (0, 1) from the pldag model,
25 // the root will be (0,1) since there's not enough information to evaluate the root `or` node.
26 println!("Root valid? {}", *validated.get(&root).unwrap() == (1, 1)); // This will be false
27
28 // If we however fix x to be zero, then we can check the result
29 inputs.insert("x", (0, 0));
30 let revalidated = pldag.propagate(inputs.clone()).unwrap();
31 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be false
32
33 // However, fixing y and z to 1 will yield the root node to be true (since the root will be true if any of x, y or z is true).
34 inputs.insert("y", (1, 1));
35 inputs.insert("z", (1, 1));
36 let revalidated = pldag.propagate(inputs.clone()).unwrap();
37 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be true
38
39 // Build a simple OR‑of‑three model
40 let mut pldag = Pldag::new();
41 pldag.set_primitive("x", (0, 1));
42 pldag.set_primitive("y", (0, 1));
43 pldag.set_primitive("z", (0, 1));
44 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
45 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
46
47 // 1. Validate a combination
48 let validated = dag.propagate(inputs).unwrap();
49 println!("root bound = {:?}", validated[&root]);
50}Sourcepub fn set_primitives<K>(
&mut self,
ids: impl IntoIterator<Item = K>,
bound: Bound,
) -> Result<Vec<ID>>where
K: ToString,
pub fn set_primitives<K>(
&mut self,
ids: impl IntoIterator<Item = K>,
bound: Bound,
) -> Result<Vec<ID>>where
K: ToString,
Creates multiple primitive variables with the same bounds.
Convenience method to create several primitive variables at once. Duplicate IDs are automatically filtered out.
§Arguments
ids- Iterator of unique identifiers for the variablesbound- The common bound to apply to all variables
Sourcepub fn set_gelineq<K>(
&mut self,
coefficient_variables: impl IntoIterator<Item = (K, i32)>,
bias: i32,
) -> Result<ID>where
K: ToString,
pub fn set_gelineq<K>(
&mut self,
coefficient_variables: impl IntoIterator<Item = (K, i32)>,
bias: i32,
) -> Result<ID>where
K: ToString,
Creates a general linear inequality constraint.
Creates a constraint of the form: sum(coeff_i * var_i) + bias >= 0. The constraint is automatically assigned a unique ID based on its content.
§Arguments
coefficient_variables- Iterator of (variable_id, coefficient) pairsbias- Constant bias term
§Returns
The unique ID assigned to this constraint, or an error if any coefficient ID doesn’t exist
Sourcepub fn set_atleast<K>(
&mut self,
references: impl IntoIterator<Item = K>,
value: i32,
) -> Result<ID>where
K: ToString,
pub fn set_atleast<K>(
&mut self,
references: impl IntoIterator<Item = K>,
value: i32,
) -> Result<ID>where
K: ToString,
pub fn set_atleast_ref<K, V>( &mut self, references: impl IntoIterator<Item = K>, value: V, ) -> Result<ID>
Sourcepub fn set_atmost<K>(
&mut self,
references: impl IntoIterator<Item = K>,
value: i32,
) -> Result<ID>where
K: ToString,
pub fn set_atmost<K>(
&mut self,
references: impl IntoIterator<Item = K>,
value: i32,
) -> Result<ID>where
K: ToString,
pub fn set_atmost_ref<K, V>( &mut self, references: impl IntoIterator<Item = K>, value: V, ) -> Result<ID>
Sourcepub fn set_equal<K, I>(&mut self, references: I, value: i32) -> Result<ID>
pub fn set_equal<K, I>(&mut self, references: I, value: i32) -> Result<ID>
Creates an equality constraint: sum(variables) == value.
Implemented as the conjunction of “at least” and “at most” constraints.
§Arguments
references- Iterator of variable IDs to sum (must be clonable)value- Required exact sum
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
pub fn set_equal_ref<K, V, I>(&mut self, references: I, value: V) -> Result<ID>
Sourcepub fn set_and<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
pub fn set_and<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
Creates a logical AND constraint.
Returns true if and only if ALL referenced variables are true. Implemented as: sum(variables) >= count(variables).
§Arguments
references- Iterator of variable IDs to AND together
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
Sourcepub fn set_or<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
pub fn set_or<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
Creates a logical OR constraint.
Returns true if AT LEAST ONE of the referenced variables is true. Implemented as: sum(variables) >= 1.
§Arguments
references- Iterator of variable IDs to OR together
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
Examples found in repository?
4fn main() {
5 // Build your PL-DAG
6 // For example, we create a model of three boolean variables x, y and z.
7 // We bind them to an OR constraint.
8 let mut pldag: Pldag = Pldag::new();
9
10 // First setup the primitive variables
11 pldag.set_primitive("x", (0, 1));
12 pldag.set_primitive("y", (0, 1));
13 pldag.set_primitive("z", (0, 1));
14
15 // A reference ID is returned
16 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
17
18 // Export a sub dag
19 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
20
21 // 1. Validate a combination:
22 let mut inputs: HashMap<&str, Bound> = HashMap::new();
23 let validated = Pldag::propagate_dag(&mut dag, inputs.clone()).unwrap();
24 // Since nothing is given, and all other variables implicitly have bounds (0, 1) from the pldag model,
25 // the root will be (0,1) since there's not enough information to evaluate the root `or` node.
26 println!("Root valid? {}", *validated.get(&root).unwrap() == (1, 1)); // This will be false
27
28 // If we however fix x to be zero, then we can check the result
29 inputs.insert("x", (0, 0));
30 let revalidated = pldag.propagate(inputs.clone()).unwrap();
31 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be false
32
33 // However, fixing y and z to 1 will yield the root node to be true (since the root will be true if any of x, y or z is true).
34 inputs.insert("y", (1, 1));
35 inputs.insert("z", (1, 1));
36 let revalidated = pldag.propagate(inputs.clone()).unwrap();
37 println!("Root valid? {}", *revalidated.get(&root).unwrap() == (1, 1)); // This will be true
38
39 // Build a simple OR‑of‑three model
40 let mut pldag = Pldag::new();
41 pldag.set_primitive("x", (0, 1));
42 pldag.set_primitive("y", (0, 1));
43 pldag.set_primitive("z", (0, 1));
44 let root = pldag.set_or(vec!["x", "y", "z"]).unwrap();
45 let mut dag = pldag.sub_dag(vec![root.clone()]).unwrap();
46
47 // 1. Validate a combination
48 let validated = dag.propagate(inputs).unwrap();
49 println!("root bound = {:?}", validated[&root]);
50}Sourcepub fn set_optional<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
pub fn set_optional<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
Creates a logical OPTIONAL constraint.
Returns true no matter the referenced variables are true or false. Implemented as: sum(references) <= len(references).
§Arguments
references- Variable IDs to make optional
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
Sourcepub fn set_nand<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
pub fn set_nand<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
Creates a logical NAND constraint.
Returns true if NOT ALL of the referenced variables are true. Implemented as: sum(variables) <= count(variables) - 1.
§Arguments
references- Iterator of variable IDs to NAND together
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
Sourcepub fn set_nor<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
pub fn set_nor<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
Sourcepub fn set_not<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
pub fn set_not<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
Creates a logical NOT constraint.
Returns true if NONE of the referenced variables are true. Functionally equivalent to NOR. Implemented as: sum(variables) <= 0.
§Arguments
references- Iterator of variable IDs to negate
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
Sourcepub fn set_xor<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
pub fn set_xor<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
Creates a logical XOR constraint.
Returns true if EXACTLY ONE of the referenced variables is true. Implemented as the conjunction of OR and “at most 1” constraints.
§Arguments
references- Iterator of variable IDs to XOR together
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
Sourcepub fn set_xnor<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
pub fn set_xnor<K>(
&mut self,
references: impl IntoIterator<Item = K>,
) -> Result<ID>where
K: ToString,
Creates a logical XNOR constraint.
Returns true if an EVEN NUMBER of the referenced variables are true (including zero). Implemented as: (sum >= 2) OR (sum <= 0).
§Arguments
references- Iterator of variable IDs to XNOR together
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
Sourcepub fn set_imply<C, Q>(&mut self, condition: C, consequence: Q) -> Result<ID>
pub fn set_imply<C, Q>(&mut self, condition: C, consequence: Q) -> Result<ID>
Creates a logical IMPLICATION constraint: condition -> consequence.
Returns true if the condition is false OR the consequence is true. Implemented as: NOT(condition) OR consequence.
§Arguments
condition- The condition variable IDconsequence- The consequence variable ID
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
Sourcepub fn set_equiv<L, R>(&mut self, lhs: L, rhs: R) -> Result<ID>
pub fn set_equiv<L, R>(&mut self, lhs: L, rhs: R) -> Result<ID>
Creates a logical EQUIVALENCE constraint: lhs <-> rhs.
Returns true if both variables have the same truth value. Implemented as: (lhs -> rhs) AND (rhs -> lhs).
§Arguments
lhs- The left-hand side variable IDrhs- The right-hand side variable ID
§Returns
The unique ID assigned to this constraint, or an error if any reference doesn’t exist
Auto Trait Implementations§
impl Freeze for Pldag
impl !RefUnwindSafe for Pldag
impl Send for Pldag
impl Sync for Pldag
impl Unpin for Pldag
impl UnsafeUnpin for Pldag
impl !UnwindSafe for Pldag
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more