NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Self-Supervised Transformers as Iterative Solution Improvers for Constraint Satisfaction

Yudong Xu, Wenhao Li, Scott Sanner, Elias Boutros Khalil

Abstract

Constraint Satisfaction Problems (CSPs) are fundamental to logistics, engineering, and computer science, yet they remain computationally intensive due to their NP-complete nature. Traditional machine learning approaches to CSPs are often hindered by the "label bottleneck" of supervised learning or the complex reward engineering required for reinforcement learning. This paper introduces ConsFormer, a self-supervised Transformer framework that treats CSP solving as an iterative refinement process. By utilizing differentiable penalty functions as continuous relaxations of discrete constraints, ConsFormer learns to improve candidate solutions without ground-truth labels. Our results demonstrate that ConsFormer achieves state-of-the-art generalization on out-of-distribution tasks, such as solving Sudoku puzzles significantly more complex than those encountered during training, by simply increasing the number of iterations at test time.

1. Introduction

CSPs, including scheduling, graph coloring, and Sudoku, require finding assignments for variables that satisfy a set of predefined constraints. While traditional backtracking solvers are reliable, they scale poorly with problem size. Recent neural solvers attempt to accelerate this process but face two primary challenges: the high cost of generating labeled datasets and the difficulty of designing effective reward signals for reinforcement learning.

ConsFormer addresses these challenges by asking: Can a model learn to solve these problems using only the rules of the game? By framing the problem as iterative local search, ConsFormer learns to refine an initial random assignment into a valid solution through self-supervision.

2. Methodology

ConsFormer operates as a neural iterative refiner. Unlike models that attempt to predict a solution in a single forward pass, ConsFormer performs a sequence of updates to a candidate solution.

2.1 Self-Supervised Loss via Continuous Relaxations

To enable gradient-based learning without labels, the authors replace discrete "True/False" constraint checks with differentiable penalty functions. For instance, an ALLDIFFERENT constraint is approximated by a function that penalizes overlapping values. This allows the model to minimize a loss function that directly represents the degree of constraint violation.

2.2 Stochastic Variable Selection and Gumbel-Softmax

Updating every variable simultaneously often leads to local optima. ConsFormer employs stochastic variable selection, randomly choosing a subset of variables to update in each step. This stochasticity encourages exploration of the solution space. To maintain differentiability while sampling discrete assignments (e.g., choosing a digit 1-9), the model utilizes the Gumbel-Softmax trick at the output layer.

2.3 Structural Embeddings

The architecture incorporates domain-specific structural information:

  • Absolute Positional Encodings (APE): Used for grid-based structures like Sudoku.
  • Relative Positional Encodings (RPE): Used to represent the underlying constraint graph in unstructured problems like graph coloring, ensuring the Transformer understands which variables are mutually constrained.

3. Experimental Evaluation

The model was evaluated across four diverse domains to test its robustness and generalization capabilities.

3.1 Sudoku and Out-of-Distribution Generalization

ConsFormer was trained on the SATNet dataset (31-42 clues) and evaluated on the significantly harder RRN dataset (17-34 clues). While previous neural state-of-the-art (SOTA) methods like RRN and SATNet struggled with this distribution shift (achieving 28.6% and 3.2% respectively), ConsFormer reached 77.74% accuracy by running 10,000 iterations at test time. This demonstrates that the model learns a generalizable improvement heuristic rather than just memorizing patterns.

3.2 Graph Coloring and MAXCUT

In graph coloring tasks ($k=10$), ConsFormer outperformed the industry-standard OR-Tools within a 10-second time limit (52.6% vs 52.41%). On the GSET benchmark for MAXCUT, the model scaled to graphs with thousands of vertices, maintaining a relative gap of only 0.31% to 1.27% from the best-known solutions.

4. Key Insights

  • Iterative Refinement: The ability to apply the model recursively at test time allows it to solve problems of greater complexity than those seen during training.
  • The Role of Stochasticity: Ablation studies confirmed that deterministic updates (100% variable updates) are inferior to stochastic subsets, as the latter prevents the model from falling into local traps.
  • Feasibility without Labels: The differentiable penalty signal provides sufficient guidance for the Transformer to discover feasible solutions for NP-complete problems autonomously.

5. Conclusion and Future Work

ConsFormer represents a significant step toward self-supervised neural combinatorial optimization. While currently limited by fixed constraint logic, future iterations could incorporate "parametric" constraints to handle dynamic SAT formulas. Furthermore, integrating ConsFormer into neuro-symbolic solvers—where the Transformer provides local search intuition and symbolic solvers ensure global consistency—presents a promising avenue for industrial-scale optimization.

Summary updated

BibTeX
@inproceedings{xu2025self,
  author = {Yudong Xu and Wenhao Li and Scott Sanner and Elias Boutros Khalil},
  title = {{Self-Supervised Transformers as Iterative Solution Improvers for Constraint Satisfaction}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=IQN6ID0snT},
}
Figure