Abstract
Backtracking search algorithms are often used to solve the Constraint Satisfaction Problem (CSP). The efficiency of backtracking search depends greatly on the variable ordering heuristics. Currently, the most commonly used heuristics are hand-crafted based on expert knowledge. In this paper, we propose a deep reinforcement learning based approach to automatically discover new variable ordering heuristics that are better adapted for a given class of CSP instances. We show that directly optimizing the search cost is hard for bootstrapping, and propose to optimize the expected cost of reaching a leaf node in the search tree. To capture the complex relations among the variables and constraints, we design a representation scheme based on Graph Neural Network that can process CSP instances with different sizes and constraint arities. Experimental results on random CSP instances show that the learned policies outperform classical hand-crafted heuristics in terms of minimizing the search tree size, and can effectively generalize to instances that are larger than those used in training.
Introduction
Constraint Satisfaction Problems (CSPs) are fundamental in artificial intelligence, appearing in diverse domains such as industrial scheduling and robotics. Solving these problems typically involves backtracking search, which incrementally builds a search tree by assigning values to variables. The efficiency of this process is highly sensitive to the variable ordering heuristic—the rule determining which variable to assign next. A strategic choice can prune vast sections of the search space, whereas a poor choice leads to exponential computational costs. Traditionally, these heuristics (e.g., MinDom, Impact) have been hand-crafted by experts. This paper explores replacing these static rules with a learned policy using deep reinforcement learning (DRL) to discover strategies tailored to specific problem structures.
Methods
The authors frame variable ordering as a Reinforcement Learning problem, introducing two key innovations to overcome the challenges of sparse rewards and varying problem sizes:
- A "Fail-First" Reward Function: Minimizing the total search tree size directly is difficult because the reward is only known at the end of the search. To enable efficient temporal difference (TD) learning, the authors propose optimizing the expected cost of reaching a leaf node. This allows for policy updates at every step of the search.
- GNN-based State Representation: To handle CSPs of varying sizes and complexities, a Graph Neural Network (GNN) is employed. The CSP is represented as a graph where variables are nodes and constraints are hyperedges. This architecture is size-agnostic, allowing models trained on small instances to generalize to much larger ones.
The agent is trained using a Double Deep Q-Network (DDQN) to estimate the Q-value (expected cost to a leaf) for each variable choice.
Experimental Results
The approach was evaluated on random CSP instances generated via Model RB, focusing on both binary and 3-ary constraints. While training occurred on small instances (15–25 variables), testing involved larger sets (up to 40 variables) to assess generalization.
Key Findings
- Efficiency and Generalization: The learned DRL policy reduced search tree sizes by up to 10.36% on medium instances compared to top hand-crafted heuristics like Dom/Tdeg. On larger, unseen instances, this reduction improved to 18.74%, demonstrating superior generalization.
- Alignment with Search Principles: The results validate the "fail-first" principle. By learning to reach leaf nodes (often dead-ends) quickly, the agent effectively minimizes the overall search tree.
- Robustness across Branching Strategies: The learned heuristics are effective regardless of the underlying branching method used in the solver.
Conclusion and Future Work
While the DRL policy significantly reduces search tree size, it introduces computational overhead due to GNN forward passes at each node. Future work aims to mitigate this through hybrid solvers that use the DRL policy only for critical high-level decisions. Additionally, extending the framework to handle more complex intensional constraints remains a key area for development.
Summary updated