</br></br>
<a href="https://pytorch.org/get-started/locally/"><img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-ee4c2c?logo=pytorch&logoColor=white"></a> <a href="https://pytorchlightning.ai/"><img alt="Lightning" src="https://img.shields.io/badge/-Lightning-792ee5?logo=pytorchlightning&logoColor=white"></a> <a href="https://github.com/pytorch/rl"><img alt="base: TorchRL" src="https://img.shields.io/badge/base-TorchRL-red"></a> <a href="https://hydra.cc/"><img alt="config: Hydra" src="https://img.shields.io/badge/config-Hydra-89b8cd"></a> <a href="https://github.com/psf/black"><img alt="Code style: black" src="https://yellow-cdn.veclightyear.com/0a4dffa0/12661fe3-3d57-4958-9fec-270778b32cb6.svg"></a> <a href="https://join.slack.com/t/rl4co/shared_invite/zt-1ytz2c1v4-0IkQ8NQH4TRXIX8PrRmDhQ"><img alt="Slack" src="https://yellow-cdn.veclightyear.com/0a4dffa0/d7e0e7a4-7c16-4817-b836-d16341949b52.svg?logo=slack"></a> <a href="https://opensource.org/licenses/MIT"><img alt="License: MIT" src="https://yellow-cdn.veclightyear.com/0a4dffa0/154af963-7089-4164-8be4-16e0cb7fc452.svg"></a> <a href="https://colab.research.google.com/github/ai4co/rl4co/blob/main/examples/1-quickstart.ipynb"><img src="https://yellow-cdn.veclightyear.com/0a4dffa0/1f30273e-8073-41ad-acba-3e9e63087c54.svg" alt="Open In Colab"></a> <a href="https://pypi.org/project/rl4co"><img alt="PyPI" src="https://img.shields.io/pypi/v/rl4co?logo=pypi"></a> <a href="https://app.codecov.io/github/ai4co/rl4co/tree/main/rl4co"><img alt="Codecov" src="https://yellow-cdn.veclightyear.com/0a4dffa0/c8d0857d-a49e-4dcc-a6dd-e1fc4586b083.svg"></a> <a href="https://github.com/ai4co/rl4co/actions/workflows/tests.yml"><img alt="Test" src="https://yellow-cdn.veclightyear.com/0a4dffa0/6477875b-bc20-4a48-bf3e-4ad0f79a71e7.svg"></a>
<p> <a href="https://rl4co.readthedocs.io/"><strong>文档</strong></a> | <a href="#getting-started"><strong>开始使用</strong></a> | <a href="#usage"><strong>用法</strong></a> | <a href="#contributing"><strong>贡献</strong></a> | <a href="https://arxiv.org/abs/2306.17100"><strong>论文</strong></a> | <a href="#join-us"><strong>加入我们</strong></a> </p> </div>一个广泛的强化学习(RL)用于组合优化(CO)的基准。我们的目标是为基于RL的CO算法提供一个统一的框架,并促进该领域的可复现研究,将科学与工程解耦。
RL4CO建立在以下基础之上:
我们提供以下策略的灵活高效实现:
我们提供了几个实用工具和模块化组件。例如,我们将可重用组件(如_环境嵌入_)模块化,这些组件可以轻松交换以解决新问题。
<div align="center"> <img src="https://github.com/ai4co/rl4co/assets/48984123/c47a9301-4c9f-43fd-b21f-761abeae9717" alt="RL4CO-Env-Embedding" style="max-width: 90%;"> </div><a href="https://colab.research.google.com/github/ai4co/rl4co/blob/main/examples/1-quickstart.ipynb"><img src="https://yellow-cdn.veclightyear.com/0a4dffa0/1f30273e-8073-41ad-acba-3e9e63087c54.svg" alt="在Colab中打开"></a>
RL4CO现在可以通过pip
安装了!
pip install rl4co
为了开始使用,我们建议查看我们的快速入门笔记本或下面的最小化示例。
这个命令安装最新的main
版本,对于保持最新开发很有用 - 例如,如果自上次官方发布以来修复了一个bug,但还没有推出新的发布版本:
pip install -U git+https://github.com/ai4co/rl4co.git
如果你想开发RL4CO,我们建议你使用pip
以可编辑模式在本地安装:
git clone https://github.com/ai4co/rl4co && cd rl4co pip install -e .
我们建议使用虚拟环境(如conda
)在本地安装rl4co
。
使用默认配置训练模型(AM在TSP环境上):
python run.py
<details> <summary>更改实验设置</summary>[!提示] 你可以查看这个笔记本来开始使用Hydra!
使用从configs/experiment/选择的实验配置训练模型
python run.py experiment=routing/am env=tsp env.num_loc=50 model.optimizer_kwargs.lr=2e-4
在这里,你可以通过命令行更改环境,例如使用env=cvrp
,或者通过修改相应的实验配置,例如configs/experiment/routing/am.yaml。
python run.py experiment=routing/am logger=none '~callbacks.learning_rate_monitor'
注意,~
用于禁用需要日志记录器的回调。
</details>python run.py -m experiment=routing/am model.optimizer.lr=1e-3,1e-4,1e-5
这里是一个最小化示例,在不到30行代码内训练具有贪婪rollout基线的注意力模型在TSP上:
from rl4co.envs.routing import TSPEnv, TSPGenerator from rl4co.models import AttentionModelPolicy, POMO from rl4co.utils import RL4COTrainer # 实例化生成器和环境 generator = TSPGenerator(num_loc=50, loc_distribution="uniform") env = TSPEnv(generator) # 创建策略和强化学习模型 policy = AttentionModelPolicy(env_name=env.name, num_encoder_layers=6) model = POMO(env, policy, batch_size=64, optimizer_kwargs={"lr": 1e-4}) # 实例化训练器并拟合 trainer = RL4COTrainer(max_epochs=10, accelerator="gpu", precision="16-mixed") trainer.fit(model)
其他示例可以在文档中找到!
从根目录使用pytest
运行测试:
pytest tests
通过Conda
安装PyG
似乎会更新Torch本身。我们发现这个更新会导致torchrl
出现一些问题。目前,我们建议使用Pip
安装PyG
:
pip install torch_geometric
有建议、请求或发现了bug?欢迎提出问题或提交拉取请求。 如果您想贡献,请查看我们的贡献指南这里。我们欢迎并期待所有对RL4CO的贡献!
如果您有任何问题或想与我们讨论RL4CO,我们也在Slack上。我们欢迎合作,很乐意听到您的想法🚀
如果您发现RL4CO对您的研究或应用项目有价值:
@article{berto2024rl4co, title={{RL4CO: an Extensive Reinforcement Learning for Combinatorial Optimization Benchmark}}, author={Federico Berto and Chuanbo Hua and Junyoung Park and Laurin Luttmann and Yining Ma and Fanchen Bu and Jiarui Wang and Haoran Ye and Minsu Kim and Sanghyeok Choi and Nayeli Gast Zepeda and André Hottung and Jianan Zhou and Jieyi Bi and Yu Hu and Fei Liu and Hyeonah Kim and Jiwoo Son and Haeyeon Kim and Davide Angioni and Wouter Kool and Zhiguang Cao and Jie Zhang and Kijung Shin and Cathy Wu and Sungsoo Ahn and Guojie Song and Changhyun Kwon and Lin Xie and Jinkyoo Park}, year={2024}, journal={arXiv preprint arXiv:2306.17100}, note={\url{https://github.com/ai4co/rl4co}} }
请注意,RL4CO的先前版本已被接受为NeurIPS 2023 GLFrontiers研讨会的口头报告。自那时以来,该库已经大大发展和改进!
我们邀请您加入我们的AI4CO社区,这是一个面向组合优化的人工智能开放研究小组!
<div align="center"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/acea5bfe-dd94-47d4-a1fb-d7e6484aa05b.svg" alt="AI4CO标志" style="width: 30%; height: auto;"> </div>AI辅助编程,代码自 动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
AI小说写作助手,一站式润色、改写、扩写
蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。