Constrained Goal-directed Planar Graph Generation with Grammar-based Reinforcement Learning

Nicolas Hochuli, Lorenzo Miele, Kristina Shea, Tino StankovicNeurIPS 2026

TL;DR

Whether you are designing an urban road network, a power grid, or an origami crease pattern, you often need a 2D graph where edges never cross, geometry obeys strict physical bounds, and the overall layout optimizes specific goals. Existing generative models struggle to satisfy hard geometric rules while optimizing multiple objectives. This paper introduces a dataset-free method that pairs graph-rewriting grammars with safe reinforcement learning to grow valid, custom-tailored planar graphs from scratch—guaranteeing zero constraint violations at every single step.

What Problem Does This Paper Address?

Many real-world engineering problems rely on planar graph embeddings—networks drawn on a flat plane with explicit 2D node coordinates and zero intersecting edges. Beyond just avoiding crossed lines, real systems have hard rules: road intersections need minimum angles, structural beams have min/max length limits, and power substations can only handle so many connections (node degree limits). Furthermore, engineers usually want an exact number of nodes optimized for competing goals, like high connectivity alongside uniform edge lengths.

Current tools fall short here. Classical random graph generators can guarantee abstract planarity, but they aren't built for multi-objective optimization or geometric constraints. Deep generative models (like graph diffusion) can be nudged toward desired properties, but they require training datasets (inheriting their biases), struggle to produce an exact node count, and treat hard geometric rules as "soft" suggestions—relying on messy post-processing or throwing away invalid samples. Meanwhile, reinforcement learning (RL) has succeeded in molecular design, where rules are mostly discrete and chemical, leaving larger-scale, continuous 2D geometric construction an open challenge.

Methods

The authors frame graph construction as a sequential game—specifically, a Constrained Markov Decision Process (CMDP)—played without any training dataset.

Figure 1: Sequential planar graph generation. Starting from an initial graph G0, a policy samples rule-based actions at ∼π(at | Gt) from a safe action space, enabling valid graph generation at each step. Actions modify graphs topologically and geometrically based on a predefined graph grammar.

Starting from a single edge ($G_0$), an RL agent (trained via standard Proximal Policy Optimization, or PPO) builds the graph step-by-step using a parametric graph grammar: a set of seven predefined rewriting rules that add nodes and edges along the outer "generative frontier" of the graph.

What makes this tricky—and novel—is the hybrid discrete-continuous action space combined with strict safety guarantees:

Figure 2: Illustration of the proposed Actor-Critic architecture.
  1. Geometry-Aware Encoding: Both the actor and critic read the current 2D graph using standard E(2)-Equivariant Graph Neural Networks (EGNNs), capturing topology, node coordinates, and sector angles.
  2. Autoregressive Decisions: At each step, the agent picks where to build (a boundary node), what rule to apply (discrete topology), and how to draw it (continuous edge lengths and angles). Rare topological mistakes (like exceeding max node degree) are caught via simple rejection sampling.
  3. Differentiable Action Projection (The Secret Sauce): Picking continuous angles and lengths that don't cause edges to cross is like threading a needle; naive rejection sampling fails constantly. The authors introduce a learned neural "safety layer" (modeled as a one-step normalizing flow) that warps the agent's raw continuous guesses directly into a state-dependent safe set. During training, if a projected action still violates a geometric rule, a classical evolutionary optimizer (CMA-ES) steps in inside the environment to find the closest valid geometry, and its fix is used to supervise and improve the projector network.

Datasets

  • Training: None! The proposed method is completely dataset-free, learning purely by interacting with the grammar environment.
  • Baselines: Deep generative baselines (DiGress, GDSS, and MuDiff) were trained on the House of Graphs (HOG) dataset, containing over 4,000 abstract planar graphs (up to 250 nodes), embedded in 2D using a force-directed spring layout.
  • New Benchmark Suite: Because no standard testbed existed for this problem, the authors introduced a four-task benchmark suite evaluating competing geometric, topological, and spectral objectives across varying constraint tightnesses: (1) a 50-node resilient power grid, (2) an 80-node urban road grid, (3) a 100-node strongly connected square mesh, and (4) a 60-node circular mesh containing exactly 40 triangles.

Key Insights and Ideas

  • Separate topological rules from geometric ones: Topological violations (like adding too many connections to a node) are rare and discrete, making simple rejection sampling totally fine. Geometric violations (like edge crossings) happen constantly in continuous space, demanding an active projection mechanism rather than blind trial-and-error.
  • Teach the safety net to fade away: Using CMA-ES to fix bad geometric guesses on the fly gives the action projector exact supervision. Over time, the neural projector learns the shape of the safe space so well that expensive CMA-ES fallbacks become infrequent, cutting constraint violations by 15x compared to a projection-free ablation.
  • Data-driven diffusion struggles with hard geometry: Even when evaluating 1,000 candidates per diffusion baseline and ignoring geometric constraints during candidate selection just to give them a fair shot at high rewards, diffusion models rarely satisfied the hard constraints and frequently missed target node counts.

Key Results

Across all four benchmarks, the grammar-RL method achieved the highest multi-objective rewards, hit the exact prescribed node counts, and satisfied 4/4 hard constraints every time:

  • Resilient Power Grid (50 nodes): Achieved a 0.76 reward (4/4 constraints), beating the best classical baseline, Delaunay triangulation (0.69, 2/4 constraints), and GDSS (0.56, 2/4 constraints).
  • Urban Road Grid (80 nodes): Scored 0.94 (4/4 constraints) vs. Delaunay's 0.91 (which struggled on angular resolution and passed only 2/4 constraints) and MuDiff's 0.53 (1/4 constraints).
  • Strongly Connected Mesh (100 nodes): Reached 0.65 (4/4 constraints), outperforming specialized square Lattice generators (0.59, 4/4) and GDSS (0.39, 3/4).
  • Exact 40-Triangle Graph (60 nodes): Averaged 39.91 triangles for a 0.98 reward (4/4 constraints), whereas HOG overshot to 64 triangles (0.86) and DiGress collapsed to 10-node graphs with 15 triangles (0.57).
  • Scalability: Successfully generated valid, constrained graphs up to 150 nodes (compared to typical planar diffusion benchmarks that cap out around 64 nodes), with training times ranging from 10 minutes to 2 hours on a single workstation GPU/CPU setup.

Limitations and Future Work

  • Horizon Scalability: Beyond ~150 nodes, the combinatorial design space and long sequence of steps make RL exploration tough. The authors suggest hierarchical RL—where a high-level policy plans coarse structural regions and a low-level policy fills in grammar details—to scale up to large computational meshes.
  • Grammar Expressiveness: Because the agent can only build graphs reachable via its seven hand-crafted rewriting rules, it cannot generate every mathematically possible planar graph. Designing grammars with broader formal coverage is left for future work.

Summary updated

Abstract

Planar graphs are central to applications across science and engineering, yet existing generators provide limited support for goal-directed generation under hard structural and geometric feasibility constraints. We propose a dataset-free method for generating planar graph embeddings by combining parametric graph grammars with safe reinforcement learning to optimize generic task-specific objectives while satisfying constraints during construction. We formulate the generation process as a constrained Markov decision process, where the graph grammar defines the state and action spaces. We further introduce an action projection that maps sampled actions toward state-dependent safe sets, improving constraint satisfaction during training. In contrast to classical graph generators and deep generative models, which typically offer limited goal-directed control or rely on weak constraint satisfaction, our method constructs feasible planar graph embeddings directly during generation. We also introduce a benchmark suite for constrained and goal-directed planar graph generation, together with classical and deep generative baselines. Across all benchmark tasks, our method consistently outperforms baselines while satisfying the formulated constraints.
BibTeX
@inproceedings{hochuli2026constrained,
  author = {Nicolas Hochuli and Lorenzo Miele and Kristina Shea and Tino Stankovic},
  title = {{Constrained Goal-directed Planar Graph Generation with Grammar-based Reinforcement Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=9Sh3SI4EF1},
}
Figure