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
;
;
;
;
6. solve (Optional GLPK Feature)
;
Solves integer linear programming problems using GLPK. Takes multiple objective functions, fixed variable assumptions, and returns optimal assignments.
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!;
3. Solving with GLPK (Optional Feature)
When the glpk feature is enabled, you can solve optimization problems directly:
use HashMap;
use ;
// Build a simple problem: maximize x + 2y + 3z subject to x ∨ y ∨ z
let mut pldag = new;
pldag.set_primitive;
pldag.set_primitive;
pldag.set_primitive;
let root = pldag.set_or;
// Set up the objective function: maximize x + 2y + 3z
let mut objective = new;
objective.insert;
objective.insert;
objective.insert;
// Constraints: require that the OR constraint is satisfied
let mut assumptions = new;
assumptions.insert; // root must be true
// Solve the optimization problem
let solutions = pldag.solve;
if let Some = &solutions else
This example demonstrates:
- Problem setup: Creating boolean variables and logical constraints
- Objective function: Defining what to optimize (maximize x + 2y + 3z)
- Assumptions: Fixing certain variables or constraints (root must be true)
- Solving: Using GLPK to find the optimal solution
- Result interpretation: Extracting variable values from the solution
Notes
- Please note that when a composite is either a tautology (always true) or a contradition (always false), these are automatically transformed into a primitive with fixed bounds set to (0,0) if contradition and (1,1) if tautology.
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! 🎉