{"id":22229809,"url":"https://github.com/graph-com/co_proxydesign","last_synced_at":"2025-07-27T19:32:04.196Z","repository":{"id":45399671,"uuid":"513610161","full_name":"Graph-COM/CO_ProxyDesign","owner":"Graph-COM","description":"The repository for 'Unsupervised Learning for Combinatorial Optimization with Principled Proxy Design'","archived":false,"fork":false,"pushed_at":"2022-10-09T18:45:29.000Z","size":66769,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-06-09T01:28:22.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Graph-COM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-13T17:20:13.000Z","updated_at":"2024-03-17T17:19:02.000Z","dependencies_parsed_at":"2023-01-19T17:16:53.897Z","dependency_job_id":null,"html_url":"https://github.com/Graph-COM/CO_ProxyDesign","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FCO_ProxyDesign","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FCO_ProxyDesign/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FCO_ProxyDesign/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FCO_ProxyDesign/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Graph-COM","download_url":"https://codeload.github.com/Graph-COM/CO_ProxyDesign/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227831006,"owners_count":17826154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T01:12:29.183Z","updated_at":"2024-12-03T01:12:29.953Z","avatar_url":"https://github.com/Graph-COM.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unsupervised-Learning-for-Combinatorial-Optimization-with-Principled-Proxy-Design\nThe official implementation of the paper 'Unsupervised Learning for Combinatorial Optimization with Principled Proxy Design'.\n\nHaoyu Wang, Nan Wu, Hang Yang, Cong Hao, and Pan Li.\n\n![image](https://github.com/Graph-COM/CO_ProxyDesign/blob/main/img/architecture.jpg)\n\n# Introduction of the Framework - a Simplified Tutorial\nOur framework is a general unsupervised framework which could extend the probabilistic framework in **Erdos goes neural**[\u003csup\u003e1\u003c/sup\u003e](#refer-anchor-1) from LCO problems to PCO problems, as shown in the following figure:\n\n|                                                   | Our framework |\n|:-------------------------------------------------:|:-------------:|\n|    LCO: learning for combinatorial optimization   |    \u0026#9745;    |\n|  PCO: the objective/constraints require learning  |    \u0026#9745;    |\n|      Binary optimization variable: X = {0,1}      |    \u0026#9745;    |\n| Non-binary optimization variable: X = {0,1,...,n} |   \u0026#9745; *   |\n\n\\* The non-binary optimization variables could be formulated into the binary forms, (e.g.\nChoosing from $(1,2,3)$ could be represented as a binary vector $(X_1,X_2,X_3)$ with a constraint $X_1 + X_2 + X_3 \\leq 1$), and then solved with our\nframework. But note that adding too many constraints might make the training process more difficult. We are working on the future work to solve this problem.\n\nHere we introduce  steps to solve your CO problem!\n\n## Step 1: find the problem\nList the consiguration $C$ and the optimization variable $X$ of the problem,\n\n## Step 2: construct the objective fr, and the constraints gr in entry-wise concave form\nWe need to construct the $f$ or $g$ in entry-wise concave structure with respect to the optimization variables, such that a performance guarantee could be achieved when we obtain a low loss. There could be two cases:\n\n**case 1** $f$ or $g$ could be written out by hand:\n\nIn this case, our relaxation-and-rounding procedure would reduce to the same framework as the probabilistic framework introduced in **Erdos goes neural**[\u003csup\u003e1\u003c/sup\u003e](#refer-anchor-1) 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).\n\nFor example, in our feature-based edge covering problem, we directly write out the constraint \n\n$$ \\textbf{Edge Covering Constraint:} \\quad g_r(\\bar{X};C) = \\sum_{v\\in V} \\prod_{e:v\\in e}(1-\\bar{X}\\_e) $$\n\n**case 2** $f$ or $g$ is unknown:\n\nWe need to first use neural networks as the proxy $h$ to learn them, the structure of the networks could be constructed as:\n\n* 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$.  \n\n$$ \\textbf{Latent representation:} \\quad \\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}$$\n\nwhere $W$ is the graph representation, $U_{v}$'s are node representations and $Q_{v,u}$ are edge representations. These representations do not contain $X$ and are given by GNN encoding $C$. Here, we consider at most 2nd-order moments based on adjacent nodes as they can be easily implemented via current GNN platforms. Then, we use $\\phi$ to generate entry-wise affine \\\u0026 concave proxies as follows.\n\n   $$ \\textbf{Entry-wise Affine Proxy (AFF):}\\quad h_r^{\\text{a}}(\\bar{X};C) = \\langle w^a, \\phi(\\bar{X};C)\\rangle. \\quad\\quad $$\n   \n   $$ \\textbf{Entry-wise Concave Proxy (CON):}\\quad h_r^{\\text{c}}(\\bar{X};C) = \\langle w^c, -\\text{Relu}(\\phi(\\bar{X};C))\\rangle + b, $$ \n   \nwhere $w^a,w^c\\in\\mathbb{R}^F, b\\in\\mathbb{R}$ are learnt parameters and $w^c\\geq0$ guarantees entry-wise concavity.\n\nIn implementation, we could formulate the AFF proxy as follows (not limited to):\n\n1. use GNN to encode the configuration C\n1. 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}$\n1. 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.\n\nIn implementation, we could formulate the CON proxy as follows (not limited to):\n\n1. 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).\n\n**Note:** We may sum the AFF proxy and the CON proxy for better performance.\n\n## Step 3: formulate the problem\nForm the problem into the following form:\n\n$$ \\min_{X \\in \\{0,1\\}^n} f(X;C) \\ \\ \\text{s.t. } g(X;C) \u003c 1$$\n\nAn example of the normalization of the constraint to follow the above form is: $(g(\\cdot;C) - g_{\\min})/(g_{\\min}^+ - g_{\\min})$, where $g_{\\min}^+ = \\min_{X \\in \\{0,1\\}^n \\backslash \\Omega} g(X;C)$ and $g_{\\min} = \\min_{X \\in \\{0,1\\}^n} g(X;C)$. They could be easily eatimated in practice.\n\n## Step 4: write out the relaxed training loss function\n\n$$ \\min_{\\theta} l_r(\\theta;C) \\triangleq f_r(\\bar{X};C) + \\beta g_r(\\bar{X};C), \\text{where} \\bar{X} = \\mathcal{A}\\_{\\theta}(C) \\in [0,1]^n, \\beta \u003e 0 $$\n\n## Step 5: train the randomized algorithm with the loss function above\nTrain $\\mathcal{A}\\_{\\theta}$ with the loss function above.\n\n## Step 6: Inference\nThen we could use $\\mathcal{A}\\_{\\theta}$ to infer the elarnt assignment of the optimization variables. We could then use our rounding process to obtain the discrete solution.\n\n# Environment Requirements\nThe following packages are required to install to implement our code:\n```shell\nconda create -n proxyco python=3.7.11\nconda activate proxyco\nconda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=11.1 -c pytorch -c conda-forge\npip install torch-scatter==2.0.8 -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111\npip install torch-sparse==0.6.11 -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111   # this may take a while...\npip install torch-cluster==1.5.9 -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111\npip install torch-spline-conv==1.2.1 -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111\npip install torch_geometric==1.7.2\n\nOptional but recommend:\npip install matplotlib\npip install pyyaml\npip install tensorboardx\n```\nif you install the environment packages above but has the error as follows:\n```\n‘NoneType‘ object has no attribute ‘origin‘\n```\nyou 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.\n\n# Application I: Feature Based Edge Covering and Node Matching in Graphs\n\n# Application II: Resource Allocation in Circuit Design\n\n# Application III: Imprecise Functional Unit Assignment in Approximate Computing\n\n\n\u003cdiv id=\"refer-anchor-1\"\u003e\u003c/div\u003e\n[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) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraph-com%2Fco_proxydesign","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraph-com%2Fco_proxydesign","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraph-com%2Fco_proxydesign/lists"}