Home

Awesome

MCPG

MCPG is an efficient and stable framework for solving Binary Optimization problems based on a Monte Carlo Policy Gradient Method with Local Search:
$$\min_x \quad f(x), \quad\mathrm{s.t.}\quad x_i \in \{1,-1\}.$$

Algorithm

MCPG consists of the following main components:

The pipeline of MCPG is demonstrated in the next figure. In each iteration, MCPG starts from the best samples of the previous iteration and performs MCMC sampling in parallel. The algorithm strives to obtain the best solutions with the aid of the powerful probabilistic model. To improve the efficiency, a filter function is applied to compute a modified objective function. At the end of the iteration, the probabilistic model is updated using policy gradient, ensuring to push the boundaries of what is possible in the quest for optimal solutions.

algo

Code Structure

    ├── config         : Configuration files for various types of problems. 
    |                    See Examples for more details to use the configuration files.
    ├── data           : Problem instances selected for testing.
    |                    See Summary of Datasets to access the complete datasets presented
    ├── driver         : Scripts to reproduce the experiment results.
    |                    See Examples for more details to use the driver files
    └── src
        ├── mcpg.py          : Main file to run MCPG solver on specific problem data.
        ├── mcpg_solver.py   : Our MCPG solver. 
        ├── model.py         : The probabilistic model to output the mean-field distribution.
        ├── dataloader.py    : Data loader for MCPG to input the problem instance.
        └── sampling.py      : The sampling procedure combining with the local search 
                               algorithm in MCPG.

Requirements

The environment dependencies are exported in the form of "environment.yaml". For the most convenient installation of these environments, we highly recommend using conda.

conda env create -f environment.yaml

Quick Start

Run the following code with the default configuration to solve the selected instances.

# maxcut
python src/mcpg.py config/maxcut_default.yaml data/graph/G14.txt
# qubo on {-1,1}^n
python src/mcpg.py config/qubo_default.yaml data/nbiq/nbiq_500.npy
# qubo on {0,1}^n
python src/mcpg.py config/qubo_bin_default.yaml data/nbiq/nbiq_500.npy
# ratio Cheeger cut
python src/mcpg.py config/rcheegercut_default.yaml data/graph/G35.txt
# normal Cheeger cut
python src/mcpg.py config/ncheegercut_default.yaml data/graph/G35.txt
# maxsat
python src/mcpg.py config/maxsat_default.yaml data/sat/randu1.cnf
# partial maxsat
python src/mcpg.py config/pmaxsat_default.yaml data/partial_sat/clq1-cv160c800l2g1.wcnf
# MIMO
python src/simulation.py

Usage

usage: python mcpg.py [-h] config_file problem_instance

positional arguments:
  config_file       input the configuration file for the mcpg solver
  problem_instance  input the data file for the problem instance

The following codes demonstrate how to integrate the mcpg solver into your program

from mcpg_solver import mcpg_solver
# load the config file and problem_data file as shown in mcpg.py
config = ...
problem_data = ...
# use mcpg_solver to obtain the solution
max_res, solution, _, _ = mcpg_solver(config, problem_data)
# use the solution in the rest of the program

Although the experiments we show in the paper are running with GPU, the program automatically detects the devices and can also running on CPU without assistance of GPU device.

Examples

We first briefly introduce the problems tested in our paper, show how to use MCPG to solve the specific problems, and then present the partial results respectively for all the testing problems. The gap is defined as $$\mathrm{gap} = \frac{|\mathrm{UB} - \mathrm{obj}|}{\mathrm{UB}} \times 100 \%$$ where $\mathrm{obj}$ is the objective value achieved by MCPG and other comparison algorithms, and $\mathrm{UB}$ denotes the best-known results.

Prerequisites

To reproduce the experiments, please download the dataset referred in Summary of Datasets.

    ├── data
        ├── graph          : Gset datasets.
        ├── regular_graph  : Generated large regular graph datasets.
        ├── nbiq           : Generated nbiq datasets.
        ├── mimo           : MIMO Simulation files.
        ├── sat            : Generated MaxSAT files.
        └── partial_sat    : random track of Max-SAT Evaluation 2016

MaxCut

The MaxCut problem aims to divide a given weighted graph $G = (V,E)$ into two parts and maximize the total weight of the edges connecting two parts. This problem can be expressed as a binary programming problem: $$\max \quad \sum_{(i,j) \in E} w_{ij} (1-x_i x_j), \quad \mathrm{s.t.}\quad x\in \{-1, 1\}^n.$$

For solving maxcut problem using MCPG, run the following code

python driver/maxcut_gset.py

The following table shows the selected results for MaxCut on Gset datasets regardless of time limits. For BLS, DSDP, RUN-CSP and PI-GNN, we directly use the results presented in the referenced papers since their performance is highly dependent on the implementation.

GraphNodesEdgesMCPGBLSDSDPRUN-CSPPI-GNNEOEMADM
G148004,6943,0643,0642,9222,9433,02630473045
G158004,6613,0503,0502,9382,9282,99030283034
G222,00019,99013,35913,35912,96013,02813,1811321513297
G493,0006,0006,0006,0006,0006,0005,91860006000
G503,0006,0005,8805,8805,8805,8805,82058785870
G555,00012,46810,29610,2949,96010,11610,1381010710208
G7010,0009,99995959,5419,456-9,42185139557

The following table shows the detailed results for selected graphs of Gset within limited time.

ProblemMCPGMCPG-UEOEMADM
nameUBgaptimegaptimegaptimegaptime
G22133590.01550.01511.211160.4266
G23133440.02560.07510.951160.3966
G24133370.03560.04510.971160.3260
G25133400.07550.08510.951150.4566
G26133280.08550.10500.921150.3666
G4124050.00540.08504.461061.9384
G4224810.00540.28504.211062.7084
G4366600.00280.00260.96450.3224

Quadratic Unconstrained Binary Optimization

QUBO is to solve the following problem: $$\max \quad x^\mathrm{T} Q x,\quad\mathrm{s.t.}\quad x\in \{0, 1\}^n.$$ The sparsity of $Q$ in our experiments is greater than $0.5$, which fundamentally differs from instances derived from graphs such as Gset dataset, where the sparsity is less than $0.1$.

For solving QUBO problem using MCPG, run the following code

python driver/qubo.py

The following table shows the results for QUBO on the large instances of Biq Mac Library.

ProblemMCPGMCPG-UMCPG-PEMADM
NameUBgaptimegaptimegaptimegaptime
b2500.115159440.00000230.00000260.00482430.0000027
b2500.214713920.01183570.01604710.02827790.0188329
b2500.314141920.00106420.00198380.00438380.0178233
b2500.415077010.00000210.00000220.00000320.0000029
b2500.514918160.00000300.00000280.00684490.0162928
b2500.614691620.00000320.00000370.00776520.0000029
b2500.714790400.00000380.00000330.01643550.0283332
b2500.814841990.00000270.00000280.01159590.0153631
b2500.914824130.00000310.00000300.00492530.0016927
b2500.1014833550.01079530.01220520.01692720.0298627

The following table shows the selected results for QUBO on the generated NBIQ datasets.

ProblemMCPGMCPG-UMCPG-PEMADM
Namegaptimegaptimegaptimegaptime
nbiq.5000.10.423640.453610.633641.33356
nbiq.5000.20.503680.523641.083651.45361
nbiq.5000.30.563700.683690.973781.23357
nbiq.7000.10.395130.435100.605121.381132
nbiq.7000.20.445090.505070.755101.271147
nbiq.7000.30.615150.905101.245121.471139

Cheeger Cut

Cheeger cut is a kind of balanced graph cut, which are widely used in classification tasks and clustering. Given a graph $G = (V, E, w)$, the ratio Cheeger cut (RCC) and the normal Cheeger cut (NCC) are defined as $$\mathrm{RCC}(S, S^c) = \frac{\mathrm{cut}(S,S^c)}{\min\{|S|, |S^c|\}},\quad\mathrm{NCC}(S, S^c) = \frac{\mathrm{cut}(S,S^c)}{|S|} + \frac{\mathrm{cut}(S,S^c)}{|S^c|},$$ where $S$ is a subset of $V$ and $S^c$ is its complementary set. The task is to find the minimal ratio Cheeger cut or normal Cheeger cut, which can be converted into the following binary unconstrained programming: $$\min \quad \frac{\sum_{(i,j)\in E}w_{ij}(1-x_ix_j)}{\min \sum_{i=1:n} (1 + x_i), \sum_{i=1:n} (1 - x_i)},\quad \mathrm{s.t.} \quad x\in\{-1,1\}^n,$$ and $$\min\quad \frac{\sum_{(i,j)\in E}w_{ij}(1-x_ix_j)}{\sum_{i=1:n} (1 + x_i)} + \frac{\sum_{(i,j)\in E}w_{ij}(1-x_ix_j)}{\sum_{i=1:n} (1 - x_i)},\quad \mathrm{s.t.} \quad x\in\{-1,1\}^n.$$

For solving the Cheeger cut problem using MCPG, run the following code

python driver/rcheegercut.py
python driver/ncheegercut.py

The following table shows the selected results for ratio Cheeger cut on Gset dataset.

ProblemMCPGMCPG-UMCPG-PpSC
nameRCCtimeRCCtimeRCCtimeRCCtime
G353.039663.163653.216653.864127
G362.894672.982653.004683.794131
G372.89683.130693.173673.895134
G382.861672.897692.927683.544125
G480.085930.088930.085940.109184
G490.158960.159960.168940.188145
G500.034930.033950.035920.040140
G512.908332.960343.137313.99752
G522.990353.149373.364333.99353
G532.846332.896312.980343.44154
G542.918343.018323.016353.54857
G600.0002450.0002430.0002463.240410
G633.1642423.3582443.4812414.090373
G700.0003420.0003420.0003423.660570

MIMO

The MIMO problem is to recover $x_C \in \mathcal Q$ from the linear model $$y_C = H_Cx_C+\nu_C,$$ where $y_C\in \mathbb C^M$ denotes the received signal, $H_C\in \mathbb C^{M\times N}$ is the channel, $x_C$ denotes the sending signal, and $\nu_C\in \mathbb C^N\sim \mathcal N(0,\sigma^2I_N)$ is the Gaussian noise with known variance.

The problem can be reduced to a binary one and is equivalent to the following: $$\min_{x\in\mathbb{R}^{2N}}\quad|Hx-y|_2^2,\quad\mathrm{s.t.} \quad x\in \{-1, 1\}^{2N}.$$

For solving the MIMO problem using MCPG, run the following code

python driver/mimo.py
TypeLBMCPGHOTMLMMSE
BERBERtimeBERtimeBERtime
800-20.1037310.1746690.500.19298110.630.1771750.10
800-40.0563310.1266751.000.14644411.880.1405190.10
800-60.0231310.0690943.960.08206313.470.1054630.10
800-80.0063000.0121503.290.0121886.220.0749000.10
1200-20.1048830.1745881.000.19319282.460.1776750.45
1200-40.0564000.1270041.940.14581377.830.1405670.47
1200-60.0231790.0703466.470.08373873.940.1059790.47
1200-80.0061790.0125297.390.01265461.590.0755670.47

MaxSAT

The MaxSAT problem is to find an assignment of the variables that satisfies the maximum number of clauses in a boolean formula in conjunctive normal form (CNF). Given a formula in CNF consists of clause $c^1,c^2,\cdots,c^m$, we formulate the partial MaxSAT problem as a penalized binary programming problem: $$\max \quad \sum_{c^i \in C_1\cup C_2} w_i\max\{c_1^i x_1, c_2^i x_2,\cdots, c_n^i x_n , 0\},\quad \text{s.t.} \quad x \in \{-1,1\}^n,$$ where $w_i = 1$ for $c^i \in C_1$ and $w_i = |C_1| + 1$ for $c^i \in C_2$. $C_1$ represents the soft clauses that should be satisfied as much as possible and $C_2$ represents the hard clauses that have to be satisfied.

$c_j^i$ represents the sign of literal $j$ in clause $i$. $c_j^i = 1$ when $x_j$ appears in the clause $C_i$, $c_j^i = -1$ when $\neg x_j$ appears in the clause $C_i$ and otherwise $c_j^i = 0$.

For solving the MaxSAT problem using MCPG, run the following code

python driver/maxsat.py

For solving the partial maxsat problem using MCPG, run the following code

python driver/pmaxsat.py

The following table shows the selected results for MaxSAT without hard clauses on the generated difficult dataset.

ProblemMCPGWBOWBO-incSATLike
nvarnclauseUBgaptimegaptimegaptimegaptime
20001000089720.01396.88605.49600.1260
20001000089450.01396.47605.62600.1560
20001000089690.01397.08605.74600.1260
20001000089500.01386.74605.89600.1360
20001000089370.01396.22605.99600.1260

The following table shows the selected results for partial MaxSAT on MSE2016 random track. The time limits of WBO and WBO-inc are the same as SATlike.

ProblemMCPGWBOWBO-incSATLike
nameC_2C_1UBgaptimegapgapgaptime
min2sat-800-140134013400.002724.412.351.4760
min2sat-800-239834013520.002724.430.850.8560
min2sat-800-339564003400.002722.351.760.5960
min2sat-800-439333983490.002726.362.581.7260
min2sat-800-538714023530.002720.111.700.2860
min2sat-1040-142485254580.003221.622.400.2260
min2sat-1040-241585284730.003322.831.270.2160
min2sat-1040-341945274730.003317.120.210.4260
min2sat-1040-440795204740.003318.571.690.2160
min2sat-1040-541845234650.433317.421.290.0060

Summary of Datasets

We list the downloading links to the datasets used in the papers for reproduction.

Contact

We hope that the package is useful for your application. If you have any bug reports or comments, please feel free to email one of the toolbox authors:

Reference

Cheng Chen, Ruitao Chen, Tianyou Li, Ruicheng Ao, Zaiwen Wen, A Monte Carlo Policy Gradient Method with Local Search for Binary Optimization, arXiv:2307.00783, 2023.

License

GNU General Public License v3.0