Skip to main content

Crate pldag

Crate pldag 

Source
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 async NodeStoreTrait so the same model can live in memory or in a database.
  • CompiledDag — a compact, immutable, indexed snapshot of a Pldag, produced by Pldag::dag. Optimised for fast propagation.
  • Propagation — given assignments for some variables, CompiledDag::propagate tightens the bounds of every reachable node. For hot loops, CompiledDag::propagate_with_scratch reuses buffers via a Scratch.
  • Polyhedra — SparsePolyhedron and DensePolyhedron turn 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:

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.
CompiledDag
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.
DensePolyhedron
Dense representation of a polyhedron defined by linear constraints.
InMemoryStore
In-memory storage implementation (for testing/development).
NodeStore
Default NodeStoreTrait implementation, layered on top of any KeyValueStore.
Pldag
A Primitive Logic Directed Acyclic Graph (PL-DAG).
Scratch
Reusable scratch buffers for CompiledDag::propagate_with_scratch.
SparsePolyhedron
Sparse representation of a polyhedron defined by linear constraints.

Enums§

ComputeError
Errors raised by pure-compute operations on a crate::CompiledDag.
Kind
The kind of a node in a CompiledDag.
ModelError
Errors raised by operations that touch the model’s storage.
Node
Represents different types of boolean expressions in the DAG.
StorageError
Errors raised by storage backend implementations.

Traits§

KeyValueStore
Abstract interface for key-value storage backends.
NodeStoreTrait
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.
ComputeResult
Result alias for pure-compute operations on a crate::CompiledDag.
ID
Type alias for node identifiers in the DAG.
ModelResult
Result alias for operations that touch the model’s storage.
StorageResult
Result alias used by storage backends.