Add a formulation¶
The catalog lives in formulations/. Adding a new
formulation is the single most useful contribution.
Checklist¶
- Create a file
formulations/<group>/<id>.jsonwhere<group>isconstraints/orobjectives/and<id>matches theidfield inside the document. - Set
schema_versionto the current value ("0.1.0"). - Declare every index family before referencing it.
- Declare parameters and variable templates with their full shape.
- For each constraint:
- quantifiers reference declared indices, with restrictions if needed
(
ne_other,lt_other,ordered_pair, …). - terms have one
bindingper shape slot of the referenced template. roleis set on every term (lhs,rhs,objective,slack,aux).- aggregations use
operatorandoperator_over.
- quantifiers reference declared indices, with restrictions if needed
(
- If the formulation has an objective, set
sense,name, optionallycombination, and a list of terms. - Run
lp2graph validate formulations/.../<id>.json— both the JSON Schema and semantic validators must pass. - Run
lp2graph render formulations/.../<id>.json --view hybrid --output preview.svgand look at the result. The structure should match what you intended. - Add the file to the catalog table in
docs/index.md. - Open a PR using the
new-formulationtemplate.
What to avoid¶
- Hidden indices. If a constraint applies "for all i", that
imust be a quantifier with anover. Never let an index be implicit in a string. - Embedded coefficients. A term's coefficient lives in the
coefficientfield, not concatenated into the variable name. - Multi-purpose variables. If
x[I]means two different things in two different parts of the model, declare two templates. - Fragile references to
one. Use{"ref": "one", "ref_kind": "literal", "coefficient": <number>, "role": "rhs"}for constant RHS terms;coefficientis where the value goes.
Example diff¶
+ formulations/constraints/lp_1_3_station_specific.json
+ docs/index.md # add a row in the catalog table
Tests¶
Schema validation runs over every file in the catalog automatically:
pytest tests/test_schema.py. View derivation and metrics tests are
parameterized over the catalog where it makes sense; if your new
formulation exercises a new schema feature, add a targeted test in
tests/test_views.py or tests/test_metrics.py to lock the behavior.