Skip to main content

Pldag

Struct Pldag 

Source
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

Source

pub fn new() -> Pldag

Creates a new empty PL-DAG.

§Returns

A new Pldag instance with no nodes

Examples found in repository?
examples/readme_example.rs (line 8)
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}
Source

pub fn new_custom(storage: Arc<dyn NodeStoreTrait>) -> Pldag

Source

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.

Source

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).

Source

pub fn reduce( dag: &CompiledDag, fixed: &HashMap<String, i32>, ) -> Result<CompiledDag>

Source

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 nodes
  • assignments - Initial assignment of bounds to variables
§Returns

Complete assignment including bounds for all reachable nodes

Examples found in repository?
examples/readme_example.rs (line 23)
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}
Source

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 variables
  • to_root - Optional root node to end propagation at
§Returns

Complete assignment including bounds for all reachable nodes

Examples found in repository?
examples/readme_example.rs (line 30)
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}
Source

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

Source

pub fn topological_sort( dag: &HashMap<ID, Node>, dependency_map: &HashMap<ID, Vec<ID>>, ) -> Result<Vec<ID>>

Source

pub fn dependency_map(dag: &HashMap<ID, Node>) -> HashMap<ID, Vec<ID>>

Source

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?
examples/readme_example.rs (line 19)
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}
Source

pub fn dag(&self) -> CompiledDag

Source

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

Source

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

Source

pub fn to_dense_polyhedron( cd: &CompiledDag, double_binding: bool, ) -> Result<DensePolyhedron>

Converts the PL-DAG to a dense polyhedron.

§Arguments
  • double_binding - If true, creates bidirectional implications
§Returns

A DensePolyhedron representing the DAG constraints

Source

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

Source

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

Source

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

Source

pub fn get_node(&self, id: &str) -> Option<Node>

Retrieves a node by its ID.

§Arguments
  • id - The unique identifier of the node to retrieve
§Returns

An Option<Node> which is Some(Node) if found, or None if not found

Source

pub fn get_nodes(&self, ids: &[String]) -> HashMap<String, Node>

Retrieves multiple nodes by their IDs. If a requested ID does not exist, it will simply be omitted from the result.

§Arguments
  • ids - A slice of unique identifiers for the nodes to retrieve
§Returns

A HashMap<String, Node> mapping each requested ID to its corresponding Node.

Source

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.

Source

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 variable
  • bound - The allowed range (min, max) for this variable
Examples found in repository?
examples/readme_example.rs (line 11)
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}
Source

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 variables
  • bound - The common bound to apply to all variables
Source

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) pairs
  • bias - Constant bias term
§Returns

The unique ID assigned to this constraint, or an error if any coefficient ID doesn’t exist

Source

pub fn set_atleast<K>( &mut self, references: impl IntoIterator<Item = K>, value: i32, ) -> Result<ID>
where K: ToString,

Creates an “at least” constraint: sum(variables) >= value.

§Arguments
  • references - Iterator of variable IDs to sum
  • value - Minimum required sum
§Returns

The unique ID assigned to this constraint, or an error if any reference doesn’t exist

Source

pub fn set_atleast_ref<K, V>( &mut self, references: impl IntoIterator<Item = K>, value: V, ) -> Result<ID>
where K: ToString, V: ToString,

Source

pub fn set_atmost<K>( &mut self, references: impl IntoIterator<Item = K>, value: i32, ) -> Result<ID>
where K: ToString,

Creates an “at most” constraint: sum(variables) <= value.

§Arguments
  • references - Iterator of variable IDs to sum
  • value - Maximum allowed sum
§Returns

The unique ID assigned to this constraint, or an error if any reference doesn’t exist

Source

pub fn set_atmost_ref<K, V>( &mut self, references: impl IntoIterator<Item = K>, value: V, ) -> Result<ID>
where K: ToString, V: ToString,

Source

pub fn set_equal<K, I>(&mut self, references: I, value: i32) -> Result<ID>
where K: ToString, I: IntoIterator<Item = K> + Clone,

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

Source

pub fn set_equal_ref<K, V, I>(&mut self, references: I, value: V) -> Result<ID>
where K: ToString, V: ToString, I: IntoIterator<Item = K> + Clone,

Source

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

Source

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?
examples/readme_example.rs (line 16)
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}
Source

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

Source

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

Source

pub fn set_nor<K>( &mut self, references: impl IntoIterator<Item = K>, ) -> Result<ID>
where K: ToString,

Creates a logical NOR constraint.

Returns true if NONE of the referenced variables are true. Implemented as: sum(variables) <= 0.

§Arguments
  • references - Iterator of variable IDs to NOR together
§Returns

The unique ID assigned to this constraint, or an error if any reference doesn’t exist

Source

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

Source

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

Source

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

Source

pub fn set_imply<C, Q>(&mut self, condition: C, consequence: Q) -> Result<ID>
where C: ToString, Q: ToString,

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 ID
  • consequence - The consequence variable ID
§Returns

The unique ID assigned to this constraint, or an error if any reference doesn’t exist

Source

pub fn set_equiv<L, R>(&mut self, lhs: L, rhs: R) -> Result<ID>
where L: ToString, R: ToString,

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 ID
  • rhs - 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.