Graph-first constraint modeling. The property graph is the system of record; FlatZinc is a compilation target.
Constraint problems are written as .csp.gram files using Gram notation. Variables, domains, and constraints are graph nodes; relationships wire them together. The zebra CLI compiles a gram file to FlatZinc or solves it in-process using the Huub CP+SAT solver.
cargo install zebraTo install from source:
cargo install --path crates/zebraGiven a .csp.gram file:
{kind: "csp", name: "two-integers"}
(x:Variable {name: "x"}) (dx:Domain {range: 1..3})
(y:Variable {name: "y"}) (dy:Domain {range: 1..3})
(c1:Constraint {kind: "int_lt"})
(x)-[:HAS_DOMAIN]->(dx)
(y)-[:HAS_DOMAIN]->(dy)
(c1)-[:ARG {pos: 0}]->(x)
(c1)-[:ARG {pos: 1}]->(y)
Solve (in-process, no external tools required):
zebra solve scenarios/two-integers/two-integers.csp.gram
# x = 2;
# y = 3;Emit FlatZinc (for use with any FlatZinc-compatible solver):
zebra emit scenarios/two-integers/two-integers.csp.gram
# var 1..3: x;
# var 1..3: y;
# constraint int_lt(x, y);
# solve satisfy;| Node label | Key properties | Meaning |
|---|---|---|
Variable |
name |
Decision variable |
Domain |
range |
Variable domain (gram range, e.g. 1..10) |
Constraint |
kind |
CP constraint atom (int_lt, int_eq, int_lin_eq, all_different) |
| Relationship | Properties | Meaning |
|---|---|---|
HAS_DOMAIN |
— | Binds a variable to its domain |
ARG |
pos |
Positional argument to a constraint |