Learning to Sample Hard Instances for Graph Algorithms

Ryoma Sato, Makoto Yamada, Hisashi Kashima

Abstract

Evaluating algorithms on average-case data often fails to reveal vulnerabilities to worst-case scenarios. Traditionally, finding "hard" instances—inputs that trigger extreme runtimes—required manual hand-crafting or limited evolutionary searches. We present HiSampler, a reinforcement learning-based framework that automatically learns to generate distributions of hard graph instances. By optimizing a generative neural network via the REINFORCE algorithm, HiSampler produces instances significantly more difficult than those from standard methods, enabling robust benchmarking and structural analysis of algorithmic bottlenecks.

Introduction

The reliability of graph algorithms in real-world applications often hinges on their performance under adversarial or rare conditions. While random graph generators provide a baseline for average performance, they rarely produce the "hard instances" necessary to stress-test solvers. Existing approaches to generating these instances typically rely on deep domain expertise to create specific rules or evolutionary algorithms that find isolated examples rather than a diverse distribution.

HiSampler addresses this gap by treating hard instance generation as a distribution learning problem. By modeling the distribution of difficult inputs, researchers can sample an infinite variety of cases, facilitating better benchmarking and the extraction of structural patterns that cause algorithmic failure.

Methodology

HiSampler employs a black-box reinforcement learning (RL) approach to generate hard instances without requiring internal knowledge of the target algorithm.

The Generative Process

The core of HiSampler is a fully connected neural network that maps random noise to a probabilistic adjacency matrix $P$. A concrete graph instance $A$ is then sampled from $P$ using a Bernoulli distribution. This allows the model to explore a wide space of potential graph structures with a complexity of $O(n^2)$ relative to the number of nodes.

The HiSampler framework architecture, utilizing the REINFORCE algorithm to optimize a generative neural network for producing hard graph instances.

Optimization via Reinforcement Learning

Since the "hardness" of a graph (e.g., runtime or number of recursive calls) is non-differentiable, HiSampler uses the REINFORCE algorithm. The network receives a reward proportional to the difficulty the generated graph poses to a target solver. To handle the "needle in a haystack" nature of hard instances, the framework incorporates Prioritized Experience Replay (PER), maintaining a pool of the most difficult instances found to date to prevent the model from forgetting rare, complex structures.

Experimental Evaluation

HiSampler was evaluated against several NP-hard graph problems and state-of-the-art solvers:

  • 3-Coloring: Tested against DSATUR (backtracking) and MiniSat (SAT-based).
  • Minimum Vertex Cover: Evaluated using a Branch & Bound (B&B) algorithm.
  • Maximum Clique: Tested against BK, MCS, and FMC solvers.
  • Graph Isomorphism: Evaluated against the famous Nauty solver.

Results and Discussion

HiSampler demonstrates significant advantages over traditional methods in terms of effectiveness, diversity, and flexibility.

Comparison of HiSampler against traditional instance generation methods across key performance and flexibility metrics.

Performance Gains

For the DSATUR algorithm in 3-coloring, HiSampler generated instances requiring over 600 million recursive calls—orders of magnitude more than the ~400 calls required by standard random graphs. It consistently outperformed existing rule-based generators and even found challenging instances for the highly optimized Nauty solver. High Jaccard distance between the edges of generated graphs confirmed that the model maintains high structural diversity rather than simply replicating a single hard instance.

Structural Insights

A key benefit of learning a distribution is the ability to perform knowledge extraction. By applying frequent subgraph mining to the generated instances, the authors identified specific "bottlenecks." In 3-coloring, for instance, the model learned to generate 4-cliques (uncolorable with 3 colors) connected to large components via narrow paths, a structure that effectively "traps" backtracking solvers in unproductive search spaces.

Conclusion

HiSampler represents a significant step forward in automated algorithm analysis. By shifting the focus from finding individual hard instances to learning their underlying distribution, it provides a scalable, problem-agnostic tool for building robust benchmarks. Future work may address current limitations, such as sensitivity to node ordering (isomorphism) and expansion to directed or weighted graph structures.

Summary updated

BibTeX
@inproceedings{sato2019learning,
  author = {Ryoma Sato and Makoto Yamada and Hisashi Kashima},
  title = {{Learning to Sample Hard Instances for Graph Algorithms}},
  booktitle = {ACML},
  year = {2019},
}
Figure