Primitive Logic Directed Acyclic Graph (PL‑DAG)
A Primitive Logic Directed Acyclic Graph (PL‑DAG) is a DAG in which every node encodes a logical operation and every leaf represents a literal. Interior nodes freely express arbitrary Boolean combinations of their predecessors—for example, an AND‑node evaluates to true only if all of its incoming nodes (or leaves) evaluate to true. This flexibility makes the PL‑DAG both powerful and easy to work with.
✨ Key Features
| Area | What you get |
|---|---|
| Modelling | Build Boolean/linear constraint systems in a single graph representation. |
| Analysis | Fast bound‑propagation (propagate*) and coefficient accumulation (propagate_coefs*). |
| Export | to_sparse_polyhedron() generates a polyhedral ILP model ready for any solver. |
| 🧩 Optional solver | Turn on the glpk feature to link against GLPK and solve in‑process. |
Install
1 — Modelling‑only (MIT licence)
This pulls no GPL code; you can ship the resulting binary under any licence compatible with MIT.
2 — Modelling + in‑process GLPK solver (GPL v3+ applies)
Enabling the glpk feature links to the GNU Linear Programming Kit (GLPK). If you distribute a binary built with this feature you must meet the requirements of the GPL‑3.0‑or‑later.
Heads‑up: Leaving the feature off keeps all code MIT‑licensed. The choice is completely under your control at
cargo buildtime.
Core Routines
1. propagate
;
Propagates bounds bottom‑up through the DAG and returns a map of node → bound ((min, max)).
2. propagate_coefs
; // IndexMap<String, MultiBound>
Propagates both bounds and linear coefficients (MultiBound = (Bound, VBound)).
3. Convenience variants
;
;
4. to_sparse_polyhedron
;
Emits a sparse polyhedral representation suitable for ILP solvers (GLPK, CPLEX, Gurobi, …).
SparsePolyhedron implements serde::Serialize, so you can also ship it over HTTP to a remote solver service if you prefer.
5. Node management helpers
;
;
;
;
Quick Example
use IndexMap;
use ;
// Build a simple OR‑of‑three model
let mut pldag = new;
pldag.set_primitive;
pldag.set_primitive;
pldag.set_primitive;
let root = pldag.set_or;
// 1. Validate a combination
let validated = pldag.propagate_default;
println!;
// 2. Optimise with coefficients
pldag.set_coef;
pldag.set_coef;
pldag.set_coef;
pldag.set_coef;
let scored = pldag.propagate_coefs_default;
println!;
License
- Library code: MIT (permissive).
- Optional solver: If you build with
--features glpk, you link against GLPK, which is GPL‑3.0‑or‑later. Distributing such a binary triggers the GPL’s obligations.
You choose the trade‑off: leave the feature off for a fully permissive dependency tree, or enable it for a batteries‑included ILP solver.
Enjoy building and evaluating logical models with PL‑DAG! 🎉