Expand description
§pldag — Primitive Logic Directed Acyclic Graphs
pldag lets you build, evaluate, and reason about boolean logic expressed
as a DAG of primitive variables and linear-combination constraints.
It is useful for modelling configuration rules, feature flags with dependencies, product configurators, or any domain where the question “given these inputs, which outputs are forced to true / false / unknown?” must be answered repeatedly and quickly.
§Concepts
Pldag— the editable model. Add primitive variables and logical constraints (AND, OR, XOR, NOT, at-least, at-most, equal, …). Backed by a pluggable asyncNodeStoreTraitso the same model can live in memory or in a database.CompiledDag— a compact, immutable, indexed snapshot of aPldag, produced byPldag::dag. Optimised for fast propagation.- Propagation — given assignments for some variables,
CompiledDag::propagatetightens the bounds of every reachable node. For hot loops,CompiledDag::propagate_with_scratchreuses buffers via aScratch. - Polyhedra —
SparsePolyhedronandDensePolyhedronturn the DAG into a system of linear inequalities suitable for ILP solvers.
§Quick start
use pldag::{Pldag, Scratch};
let model = Pldag::new();
model.set_primitive("a", (0, 1)).await?;
model.set_primitive("b", (0, 1)).await?;
let root = model.set_and(vec!["a", "b"]).await?;
// Compile once, propagate many times.
let dag = model.dag().await?;
let mut scratch = Scratch::new();
let result = dag.propagate_with_scratch(
[("a", (1, 1)), ("b", (1, 1))],
&mut scratch,
)?;
assert_eq!(result.get(&root).unwrap(), &(1, 1));§Errors
Fallible operations return one of two precise result types:
ComputeResult<T>— pure in-memory operations on aCompiledDag(propagation, tightening, ranks, polyhedron conversion). Errors are modelled byComputeError.ModelResult<T>— operations that read or mutate the model’s storage (set_*,delete_node,dag,sub_dag,get_node). Errors are modelled byModelError, which wraps backend-levelStorageErrors.
The two enums are disjoint: no variant is shared, so each function signature precisely describes its failure modes.
Structs§
- Coef
- A single
(input_index, coefficient)term inside a composite constraint. - Compiled
Dag - A compact, indexed snapshot of a
Pldag, optimised for fast propagation. - Constraint
- Represents a linear constraint in the form: sum(coeff_i * var_i) + bias >= 0.
- Dense
Polyhedron - Dense representation of a polyhedron defined by linear constraints.
- InMemory
Store - In-memory storage implementation (for testing/development).
- Node
Store - Default
NodeStoreTraitimplementation, layered on top of anyKeyValueStore. - Pldag
- A Primitive Logic Directed Acyclic Graph (PL-DAG).
- Scratch
- Reusable scratch buffers for
CompiledDag::propagate_with_scratch. - Sparse
Polyhedron - Sparse representation of a polyhedron defined by linear constraints.
Enums§
- Compute
Error - Errors raised by pure-compute operations on a
crate::CompiledDag. - Kind
- The kind of a node in a
CompiledDag. - Model
Error - Errors raised by operations that touch the model’s storage.
- Node
- Represents different types of boolean expressions in the DAG.
- Storage
Error - Errors raised by storage backend implementations.
Traits§
- KeyValue
Store - Abstract interface for key-value storage backends.
- Node
Store Trait - Abstract interface for node storage, layered on top of a
KeyValueStore.
Type Aliases§
- Bound
- Represents a bound with minimum and maximum values. Used to specify the allowed range for variables and constraints.
- Compute
Result - Result alias for pure-compute operations on a
crate::CompiledDag. - ID
- Type alias for node identifiers in the DAG.
- Model
Result - Result alias for operations that touch the model’s storage.
- Storage
Result - Result alias used by storage backends.