The official implementation of the paper 'Unsupervised Learning for Combinatorial Optimization with Principled Proxy Design'.
Haoyu Wang, Nan Wu, Hang Yang, Cong Hao, and Pan Li.
Our framework is a general unsupervised framework which could extend the probabilistic framework in Erdos goes neural1 from LCO problems to PCO problems, as shown in the following figure:
Our framework | |
---|---|
LCO: learning for combinatorial optimization | ☑ |
PCO: the objective/constraints require learning | ☑ |
Binary optimization variable: X = {0,1} | ☑ |
Non-binary optimization variable: X = {0,1,...,n} | ☑ * |
* The non-binary optimization variables could be formulated into the binary forms, (e.g.
Choosing from
Here we introduce steps to solve your CO problem!
List the consiguration
We need to construct the
case 1
In this case, our relaxation-and-rounding procedure would reduce to the same framework as the probabilistic framework introduced in Erdos goes neural1 such as the max-clique and the weighted-cut problem. Once the objectives could be written out by hand, they could be written out in the entry-wise concave (affine) way due to their discrete property (See our Theorem 2).
For example, in our feature-based edge covering problem, we directly write out the constraint
case 2
We need to first use neural networks as the proxy
- To learn a discrete function
$h:{0,1}^{|V|}\times \mathcal{C}\rightarrow \mathbb{R}$ , we adopt a GNN as the relaxed proxy of$h$ . We first define a latent graph representation in$\mathbb{R}^F$ whose entries are all entry-wise affine mappings of$X$ .
where
where
In implementation, we could formulate the AFF proxy as follows (not limited to):
- use GNN to encode the configuration C
- Divide the learnt encoding into two parts (coefficient and bias to multiply with X) to construct the latent representation
$\phi(\bar{X};C) = W +\sum_{v\in V} U_{v} \bar{X}_{v} + \sum_{v,u \in V, (v,u) \in E} Q_{v,u} \bar{X}_{v} \bar{X}_{u}$ - For each node with its latent representation, calculate the logarithmic function of the representation, use message passing to add the adjacent log latent representation together, then do exponential function to get the AFF proxy.
In implementation, we could formulate the CON proxy as follows (not limited to):
- we could use a constant to minus the AFF latent proxy, then go through the Relu() function, and finally we send the output into another fully connected layer. We constrain the weights of the last fully connected layer to be greater or equal to 0 (torch.clamp() function).
Note: We may sum the AFF proxy and the CON proxy for better performance.
Form the problem into the following form:
An example of the normalization of the constraint to follow the above form is:
Train
Then we could use
The following packages are required to install to implement our code:
conda create -n proxyco python=3.7.11
conda activate proxyco
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=11.1 -c pytorch -c conda-forge
pip install torch-scatter==2.0.8 -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111
pip install torch-sparse==0.6.11 -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111 # this may take a while...
pip install torch-cluster==1.5.9 -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111
pip install torch-spline-conv==1.2.1 -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111
pip install torch_geometric==1.7.2
Optional but recommend:
pip install matplotlib
pip install pyyaml
pip install tensorboardx
if you install the environment packages above but has the error as follows:
‘NoneType‘ object has no attribute ‘origin‘
you could add the cuda.so libs into the folder of these packages that we uploaded to the folder ./environment_utils/cuda_libs to solve the problem.
[1][Erdos goes neural: an Unsupervised Learning Framework for Combinatorial Optimization on Graphs. Nikolaos Karalias, Andreas Loukas. Neurips 2020.](https://proceedings.neurips.cc/paper/2020/hash/49f85a9ed090b20c8bed85a5923c669f-Abstract.html)