‹ demo hub
TU Dresden · LP2Graph

From formulas to typed graphs

LP2Graph turns LP / MIP / MILP formulations into deterministic typed graphs — so optimization models become data you can compare, measure, mine and learn from.
pip install lp2graph · Apache-2.0 · deterministic by design

The idea in one pipeline

Published formulation
LaTeX from a paper, or a JSON model — e.g. train timetabling, rescheduling
validate → canonical model
Canonical Formulation
one pydantic model, version-stable JSON schema — the single source of truth
derive (pure, reproducible)
Typed graph views
schema templates & indices · hybrid + offset edges · ground instances
analyze & export
Metrics · Mining · ML
structural metrics, isomorphism & clustering (taxonomy), PyG / DGL / NetworkX / Pyomo

Try it — tap the graph

This is a real LP2Graph output: the schema view of the PESP cyclic-timetabling MILP from the library's catalog (11 nodes, 18 typed edges), exactly as lp2graph.views.schema() derives it. Tap any node.

lhs term rhs term objective shape (indexing) dashed = negative sign
Tap a node interactive
Every node and edge is typed. Select a constraint, variable, parameter or the objective to see its role — and where it appears in the canonical LaTeX below.
The LaTeX is the library's own reversible canonical form (codec.to_canonical_latex) — graph ⇄ text round-trips losslessly.

Why graphs?

Comparable structure
Two papers, different symbols, same model? As typed graphs that's an isomorphism check, not a judgement call — the basis for a formulation taxonomy.
Deterministic
Same input → byte-identical graph, metrics and LaTeX. No LLM, no randomness from the validated model onward. Snapshot-tested.
Measurable
Structural metrics (density, diameter, degree profiles), modeling-idiom flags (big-M, modulo, slack), well-formedness checks — computed, not eyeballed.
ML-ready
One export call to PyG / DGL / NetworkX turns a century of published models into graph-learning datasets.
Solver-agnostic
The representation carries no solver dependency; grounding + a Pyomo/PuLP back-end are optional extras, not the core.
Scales to corpora
The mining extensions (M1–M6) ingest, homologize, cluster and label whole literatures of formulations with versioned, replayable resources.

Install & use

# core is just pydantic + jsonschema
pip install lp2graph
# extras: [networkx] [pyg] [all] …
from lp2graph import load
from lp2graph.views import schema, hybrid, ground
from lp2graph.metrics.structural import structural_summary

f = load("formulations/constraints/mip_2_8_pesp.json")
g = schema(f)                      # ← the graph you tapped above
print(structural_summary(g)["graph_diameter"].value)
open("pesp.svg","w").write(render_svg(hybrid(f)))

Full docs, data model and the formulation catalog: joernmht.github.io/lp2graph/docs.

Honest limitations

Linear world only
LP / MIP / MILP. General nonlinear programs, black-box objectives and constraint programming are out of scope by design.
Representable ≠ solvable
A valid typed graph proves structure, not feasibility or tractability. Solving needs grounding with instance data and an external solver.
Canonical input needed
The LaTeX ⇄ graph codec is deterministic and reversible on the canonical form. Arbitrary paper LaTeX first needs normalization and human review — extraction from PDFs is upstream of the determinism boundary.
Schema view abstracts size
Templates and index sets, not instances: a model over 10 or 10,000 trains has the same schema graph. Use the ground view (with cardinalities) when size matters.

Where this is going

🎛️ Model configurator (vision demo)
Try ›
Compose a rescheduling model on your phone: pick an objective, add constraint templates, and wire them to live data sources with your finger — LP2Graph checks the structure as you build. A UI vision of the road ahead, not yet wired to the library.