Skip to content

Thinklab-SJTU/ML4CO-Kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PyPi version PyPI pyversions Downloads Documentation Status GitHub stars

Combinatorial Optimization (CO) is a mathematical optimization area that involves finding the best solution from a large set of discrete possibilities, often under constraints. Widely applied in routing, logistics, hardware design, and biology, CO addresses NP-hard problems critical to computer science and industrial engineering.

ML4CO-Kit aims to provide foundational support for machine learning practices on CO problems. We have designed the ML4CO-Kit into five levels:

Organization

  • Task(Level 1): the smallest processing unit, where each task represents a problem instance. At the task level, it mainly involves the definition of CO problems, evaluation of solutions (including constraint checking), and problem visualization, etc.
  • Generator(Level 2): the generator creates task instances of a specific structure or distribution based on the set parameters.
  • Solver(Level 3): a variety of solvers. Different solvers, based on their scope of application, can solve specific types of task instances and can be combined with optimizers to further improve the solution results.
  • Optimizer(Level 4): to further optimize the initial solution obtained by the solver.
  • Wrapper(Level 5): user-friendly wrappers, used for handling data reading and writing, task storage, as well as parallelized generation and solving.

Additionally, for higher-level ML4CO (see ML4CO-Bench-101) services, we also provide learning base classes (see ml4co_kit/learning) based on the PyTorch-Lightning framework, including BaseEnv, BaseModel, Trainer. The following figure illustrates the relationship between the ML4CO-Kit and ML4CO-Bench-101.

Relation

We are still enriching the library and we welcome any contributions/ideas/suggestions from the community.

⭐ Official Documentation: https://ml4co-kit.readthedocs.io/en/latest/

⭐ Source Code: https://github.com/Thinklab-SJTU/ML4CO-Kit

Installation

You can install the stable release on PyPI:

$ pip install ml4co-kit

pip

or get the latest version by running:

$ pip install -U https://github.com/Thinklab-SJTU/ML4CO-Kit/archive/master.zip # with --user for user install (no root)

The following packages are required and shall be automatically installed by pip:

Python>=3.8
numpy>=1.24.4
networkx>=2.8.8
tqdm>=4.66.3
pulp>=2.8.0, 
pandas>=2.0.0,
scipy>=1.10.1
aiohttp>=3.10.11
requests>=2.32.0
async_timeout>=4.0.3
pyvrp>=0.6.3
cython>=3.0.8
gurobipy>=11.0.3
scikit-learn>=1.3.0
matplotlib>=3.7.4

To ensure you have access to all functions, such as visualization, you'll need to install the following packages using pip:

pytorch_lightning

ML4CO-Kit Development status

We will present the development progress of ML4CO-Kit in the above 5 levels.

Graph: MCl & MCut & MIS & MVC; βœ”: Supported; πŸ“†: Planned for future versions (contributions welcomed!).

Task (Level 1)

Task Definition Check Constraint Evaluation Render Special R/O
Asymmetric TSP (ATSP) βœ” βœ” βœ” πŸ“† tsplib
Capacitated Vehicle Routing Problem (CVRP) βœ” βœ” βœ” βœ” vrplib
Orienteering Problem (OP) βœ” βœ” βœ” πŸ“†
Prize Collection TSP (PCTSP) βœ” βœ” βœ” πŸ“†
Stochastic PCTSP (SPCTSP) βœ” βœ” βœ” πŸ“†
Traveling Salesman Problem (TSP) βœ” βœ” βœ” βœ” tsplib
Maximum Clique (MCl) βœ” βœ” βœ” βœ” gpickle, adj_matrix, networkx, csr
Maximum Cut (MCut) βœ” βœ” βœ” βœ” gpickle, adj_matrix, networkx, csr
Maximum Independent Set (MIS) βœ” βœ” βœ” βœ” gpickle, adj_matrix, networkx, csr
Minimum Vertex Cover (MVC) βœ” βœ” βœ” βœ” gpickle, adj_matrix, networkx, csr

Generator (Level 2)

Task Distribution Brief Intro. State
ATSP Uniform Random distance matrix with triangle inequality βœ”
SAT SAT problem transformed to ATSP βœ”
HCP Hamiltonian Cycle Problem transformed to ATSP βœ”
CVRP Uniform Random coordinates with uniform distribution βœ”
Gaussian Random coordinates with Gaussian distribution βœ”
OP Uniform Random prizes with uniform distribution βœ”
Constant All prizes are constant βœ”
Distance Prizes based on distance from depot βœ”
PCTSP Uniform Random prizes with uniform distribution βœ”
SPCTSP Uniform Random prizes with uniform distribution βœ”
TSP Uniform Random coordinates with uniform distribution βœ”
Gaussian Random coordinates with Gaussian distribution βœ”
Cluster Coordinates clustered around random centers βœ”
(Graph) ER (structure) Erdos-Renyi random graph βœ”
BA (structure) Barabasi-Albert scale-free graph βœ”
HK (structure) Holme-Kim small-world graph βœ”
WS (structure) Watts-Strogatz small-world graph βœ”
RB (structure) RB-Model graph βœ”
Uniform (weighted) Weights with Uniform distribution βœ”
Gaussian (weighted) Weights with Gaussian distribution βœ”
Poisson (weighted) Weights with Poisson distribution βœ”
Exponential (weighted) Weights with Exponential distribution βœ”
Lognormal (weighted) Weights with Lognormal distribution βœ”
Powerlaw (weighted) Weights with Powerlaw distribution βœ”
Binomial (weighted) Weights with Binomial distribution βœ”

Solver (Level 3)

Solver Support Task Language Source Ref. / Implementation State
BeamSolver MCl Python ML4CO-Kit ML4CO-Kit βœ”
MIS Python ML4CO-Kit ML4CO-Kit βœ”
ConcordeSolver TSP C/C++ Concorde PyConcorde βœ”
GAEAXSolver TSP C/C++ GA-EAX GA-EAX βœ”
GpDegreeSolver MCl Python ML4CO-Kit ML4CO-Kit βœ”
MIS Python ML4CO-Kit ML4CO-Kit βœ”
MVC Python ML4CO-Kit ML4CO-Kit βœ”
GreedySolver ATSP C/C++ ML4CO-Kit ML4CO-Kit βœ”
CVRP Python ML4CO-Kit ML4CO-Kit βœ”
TSP Cython DIFUSCO DIFUSCO βœ”
MCl Python ML4CO-Kit ML4CO-Kit βœ”
MCut Python ML4CO-Kit ML4CO-Kit βœ”
MIS Python ML4CO-Kit ML4CO-Kit βœ”
MVC Python ML4CO-Kit ML4CO-Kit βœ”
GurobiSolver ATSP C/C++ Gurobi ML4CO-Kit βœ”
CVRP C/C++ Gurobi ML4CO-Kit βœ”
TSP C/C++ Gurobi ML4CO-Kit βœ”
MCl C/C++ Gurobi DIffUCO βœ”
MCut C/C++ Gurobi DIffUCO βœ”
MIS C/C++ Gurobi DIffUCO βœ”
MVC C/C++ Gurobi DIffUCO βœ”
HGSSolver CVRP C/C++ HGS-CVRP HGS-CVRP βœ”
ILSSolver PCTSP Python PCTSP PCTSP βœ”
InsertionSolver TSP Python GLOP GLOP βœ”
KaMISSolver MIS Python KaMIS MIS-Bench βœ”
LcDegreeSolver MCl Python ML4CO-Kit ML4CO-Kit βœ”
MCut Python ML4CO-Kit ML4CO-Kit βœ”
MIS Python ML4CO-Kit ML4CO-Kit βœ”
MVC Python ML4CO-Kit ML4CO-Kit βœ”
LKHSolver TSP C/C++ LKH ML4CO-Kit βœ”
ATSP C/C++ LKH ML4CO-Kit βœ”
CVRP C/C++ LKH ML4CO-Kit βœ”
MCTSSolver TSP Python Att-GCRN ML4CO-Kit βœ”
NeuroLKHSolver TSP Python NeuroLKH ML4CO-Kit βœ”
ORSolver ATSP C/C++ OR-Tools ML4CO-Kit βœ”
PCTSP C/C++ OR-Tools ML4CO-Kit βœ”
TSP C/C++ OR-Tools ML4CO-Kit βœ”
MCl C/C++ OR-Tools ML4CO-Kit βœ”
MIS C/C++ OR-Tools ML4CO-Kit βœ”
MVC C/C++ OR-Tools ML4CO-Kit βœ”
RLSASolver MCl Python RLSA ML4CO-Kit βœ”
MCut Python RLSA ML4CO-Kit βœ”
MIS Python RLSA ML4CO-Kit βœ”
MVC Python RLSA ML4CO-Kit βœ”

Optimizer (Level 4)

Optimizer Support Task Language Source Reference State
CVRPLSOptimizer CVRP C/C++ HGS-CVRP ML4CO-Kit βœ”
MCTSOptimizer TSP C/C++ Att-GCRN ML4CO-Kit βœ”
RLSAOptimizer MCl Python RLSA ML4CO-Kit βœ”
MCut Python RLSA ML4CO-Kit βœ”
MIS Python RLSA ML4CO-Kit βœ”
MVC Python RLSA ML4CO-Kit βœ”
TwoOptOptimizer ATSP C/C++ ML4CO-Kit ML4CO-Kit βœ”
TSP Python DIFUSCO ML4CO-Kit βœ”

Wrapper (Level 5)

Wrapper TXT Other R&W
ATSPWrapper "[dists] output [sol]" tsplib
CVRPWrapper "depots [depots] points [points] demands [demands] capacity [capacity] output [sol]" vrplib
ORWrapper "depots [depots] points [points] prizes [prizes] max_length [max_length] output [sol]"
PCTSPWrapper "depots [depots] points [points] penalties [penalties] prizes [prizes] required_prize [required_prize] output [sol]"
SPCTSPWrapper "depots [depots] points [points] penalties [penalties] expected_prizes [expected_prizes] actual_prizes [actual_prizes] required_prize [required_prize] output [sol]"
TSPWrapper "[points] output [sol]" tsplib
(Graph)Wrapper "[edge_index] label [sol]" gpickle
(Graph)Wrapper [weighted] "[edge_index] weights [weights] label [sol]" gpickle

Our Systematic Benchmark Works

We are systematically building a foundational framework for ML4CO with a collection of resources that complement each other in a cohesive manner.

  • Awesome-ML4CO, a curated collection of literature in the ML4CO field, organized to support researchers in accessing both foundational and recent developments.

  • ML4CO-Kit, a general-purpose toolkit that provides implementations of common algorithms used in ML4CO, along with basic training frameworks, traditional solvers and data generation tools. It aims to simplify the implementation of key techniques and offer a solid base for developing machine learning models for COPs.

  • ML4TSPBench: a benchmark focusing on exploring the TSP for representativeness. It advances a unified modular streamline incorporating existing tens of technologies in both learning and search for transparent ablation, aiming to reassess the role of learning and to discern which parts of existing techniques are genuinely beneficial and which are not. It offers a deep dive into various methodology designs, enabling comparisons and the development of specialized algorithms.

  • ML4CO-Bench-101: a benchmark that categorizes neural combinatorial optimization (NCO) solvers by solving paradigms, model designs, and learning strategies. It evaluates applicability and generalization of different NCO approaches across a broad range of combinatorial optimization problems to uncover universal insights that can be transferred across various domains of ML4CO.

  • PredictiveCO-Benchmark: a benchmark for decision-focused learning (DFL) approaches on predictive combinatorial optimization problems.

Citation

If you find our code helpful in your research, please cite

@inproceedings{
    ma2025mlcobench,
    title={ML4CO-Bench-101: Benchmark Machine Learning for Classic Combinatorial Problems on Graphs},
    author={Jiale Ma and Wenzheng Pan and Yang Li and Junchi Yan},
    booktitle={The Thirty-ninth Annual Conference on Neural Information Processing Systems Datasets and Benchmarks Track},
    year={2025},
    url={https://openreview.net/forum?id=ye4ntB1Kzi}
}

@inproceedings{li2025unify,
  title={Unify ml4tsp: Drawing methodological principles for tsp and beyond from streamlined design space of learning and search},
  author={Li, Yang and Ma, Jiale and Pan, Wenzheng and Wang, Runzhong and Geng, Haoyu and Yang, Nianzu and Yan, Junchi},
  booktitle={The Thirteenth International Conference on Learning Representations},
  year={2025}
}

About

A Python toolkit for Machine Learning (ML) practices for Combinatorial Optimization (CO).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 7