AI4Finance-Foundation / RLSolver

Solvers for NP-hard and NP-complete problems with an emphasis on high-performance GPU computing.
https://ai4finance.org
MIT License
120 stars 30 forks source link

📝 Graph: Learning Combinatorial Optimization Algorithms over Graphs #221

Open Yonv1943 opened 10 months ago

Yonv1943 commented 10 months ago

我们图上的组合优化问题,例如 Graph maxcut,下面的论文提出了对图结构进行了编码的方案:

直接复现上面的代码,因为版本问题,不容易,我有以下建议:

复现过程碰到问题,随时在这个issue 提出来。


建议复现他们的 PyTorch版本:

Dec. 22, 2017 update: pytorch version of structure2vec For people who prefer python, here is the pytorch implementation of s2v: https://github.com/Hanjun-Dai/pytorch_structure2vec

建议安装PyTorch的 0.8.5 版本

2017年的PyTorch 的版本是 0.4 ~ 0.8:

0.x 版本的PyTorch 经常能看到下面的代码,这个在 0.8.5 之前都兼容 https://github.com/Hanjun-Dai/pytorch_structure2vec/blob/bcf20c90f21e468f862f13e2f5809a52cd247d4e/graph_classification/main.py#L7C1-L8C4

from torch.autograd import Variable
from torch.nn.parameter import Parameter

建议安装 rdkit 和 boost 的最新版本

和C++有关的,我建议安装最新的 rdkit 和 boost(rdkit一直都有维护) ,如果最新的版本安装后,发现依然编译不成功,才去降低版本并更换C++编译器到对应的低版本(能上网查到)

The following versions have been tested. But newer versions should also be fine. rdkit : [Q3 2017 Release](https://github.com/rdkit/rdkit/releases/tag/Release_2017_09_1, Release_2017_09_2) boost : Boost 1.61.0, 1.65.1

运行

按Readme 的方式来


我之前单独抽取里面的 PyTorch 代码跑过它的推理过程,只需要PyTorch就好, rdkit 和 boost 这两个库用来提供“训练标签”,不想要完整复现,只想要了解网络结构的情况下,可以跳过。 https://github.com/Hanjun-Dai/pytorch_structure2vec/tree/master/s2v_lib

Yonv1943 commented 10 months ago

https://github.com/AI4Finance-Foundation/RLSolver/blob/main/helloworld/maxcut/graph_max_cut_auto_regression.py

我更新了两个文件,它参考了 VCA的方法,需要读取图结构作为输入,然后用自回归的方法更新,这个方法不再依赖 simulator 提供一个 “根据 prob得到有梯度的objective” 。

|        1       0      1.621  score     74      74  
best_score 74.0  best_sln_x 
0lYUoY
|        6       4      1.741  score     71      74  
|       11       8      1.545  score     71      74  
|       16      12      1.516  score     69      74  
|       20      16      1.544  score     72      74  
|       25      20      1.538  score     68      74  
|       30      24      1.344  score     70      74  
|       35      28      1.580  score     70      75  
ZhangZiYang11 commented 3 months ago

这个pytorch版本的代码不是论文 Learning Combinatorial Optimization Algorithms over Graphs的代码吧,网络结构定义不同,其中也没有关键的强化学习环境的代码