|
| 1 | +# Multi-agent Path Finding using Reinforcement Learning |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +## Description |
| 9 | + |
| 10 | +**Multi-agent pathfinding in partially observable environments. Search-based vs. RL-based algorithms.** |
| 11 | + |
| 12 | +The main goal of this repository is to provide a DHC [1] model implementation alongside with some benchmarks and charts. |
| 13 | +We also aim to compare the performance of the DHC model with the basic M* algorithm. |
| 14 | + |
| 15 | +## Requirements |
| 16 | +In order for `models.dhc.train` to be successfully run, you have to have a machine equipped with 1 GPU and several CPUs. |
| 17 | +Consider having `num_cpus - 2` actors configured through the `dhc.train.num_actors` in `config.yaml` |
| 18 | + |
| 19 | +**Attention: We do not guarantee the desired performance on a non-GPU machine.** |
| 20 | + |
| 21 | +While we aim at supporting MacOS, Linux and Windows platforms, the successful training is not guaranteed on a Windows-based machine. |
| 22 | +The benchmarking script should work there, though. Please report it [here](https://github.com/acforvs/po-mapf-thesis/issues) if it doesn't. |
| 23 | + |
| 24 | +## Setting up |
| 25 | +1. Install [Poetry](https://python-poetry.org) |
| 26 | +2. Run [poetry install](https://python-poetry.org/docs/cli/#install) to install the dependencies |
| 27 | + |
| 28 | +If you see ``Failed to create the collection: Prompt dismissed..`` this error when trying to run `poetry install`, [consider](https://github.com/python-poetry/poetry/issues/1917#issuecomment-1251667047) executing this line first: |
| 29 | +```shell |
| 30 | +export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring |
| 31 | +``` |
| 32 | + |
| 33 | +## Repository description & Usage |
| 34 | +1. `models` dir contains the weights of the trained models |
| 35 | +2. `config.yaml` - training & model params, environmental settings etc. |
| 36 | +3. `pathfinding/models` provides one with the implementation of different models |
| 37 | + |
| 38 | +## Models |
| 39 | +### DHC |
| 40 | + |
| 41 | +**D**istributed, **H**euristic and **C**ommunication [1] |
| 42 | + |
| 43 | +> To guide RL algorithm on long-horizon goal-oriented tasks, we embed the potential choices of shortest paths from single source as heuristic guidance instead of using a specific path as in most existing works. Our method treats each agent independently and trains the model from a single agent’s perspective. The final trained policy is applied to each agent for decentralized execution. The whole system is distributed during training and is trained under a curriculum learning strategy. |
| 44 | +
|
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +<details> |
| 49 | + <summary>DHC</summary> |
| 50 | + |
| 51 | +#### Benchmarking |
| 52 | + |
| 53 | +**To run the generated test suite, run** |
| 54 | +```shell |
| 55 | +poetry run python3 pathfinding/models/dhc/evaluate.py test_model TESTS_DESCR MODEL_ID |
| 56 | +``` |
| 57 | +where |
| 58 | +* TESTS_DESCR is a string of the format `'[(map_length, num_agents, density), ...]'` (you may want to copy this line from the generation command) |
| 59 | +* MODEL_ID is the name of the file from the `models` dir |
| 60 | +For example, by running |
| 61 | + |
| 62 | +```shell |
| 63 | +poetry run python3 pathfinding/models/dhc/evaluate.py test_model '[(40, 16, 0.3), (80, 4, 0.1)]' 60000 |
| 64 | +``` |
| 65 | +you will benchmark the `models/60000.pth` on the provided test cases |
| 66 | + |
| 67 | +**Attention: the test cases must be generated first!** |
| 68 | + |
| 69 | +#### Training |
| 70 | +1. Set the desired `actors` amount by setting the appropriate value for `dhc.train.num_actors` in `config.yaml` |
| 71 | + |
| 72 | +It is recommended to use the amount of CPU cores on you machine minus 2 |
| 73 | + |
| 74 | +2. To initialize training, run |
| 75 | +```shell |
| 76 | +poetry run python3 pathfinding/models/dhc/train.py |
| 77 | +``` |
| 78 | + |
| 79 | +The `models` dir will be created afterwards where the weights of the intermediate models will be saved. |
| 80 | + |
| 81 | +#### Visualizing |
| 82 | + |
| 83 | +1. To visualize the results, run |
| 84 | +```shell |
| 85 | +poetry run python3 pathfinding/models/dhc/visualize.py MODEL_ID TEST_NAME TEST_ID |
| 86 | +``` |
| 87 | +where |
| 88 | +* MODEL_ID is the name of the file from the `models` dir |
| 89 | +* TEST_NAME is the name of the file with tests, for example `80length_32agents_0.3density.pkl` |
| 90 | +* TEST_ID [optional], id of the test from the provided test suite |
| 91 | + |
| 92 | +</details> |
| 93 | + |
| 94 | +## The setup |
| 95 | +The DHC network was trained on a single [NVIDIA TESLA T4 GPU](https://www.nvidia.com/en-us/data-center/tesla-t4/) for 7 hours. |
| 96 | + |
| 97 | +We used 20 CPU cores, 18 were used for the actors, additionally, 2 cores were used for the Learner and GlobalBuffer all together. |
| 98 | + |
| 99 | + |
| 100 | +## DHC Results |
| 101 | + |
| 102 | +**Our trained model outperforms PRIMAL benchmarks** |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +## Contributing |
| 114 | +<details> |
| 115 | + <summary>See the detailed contribution guide</summary> |
| 116 | + |
| 117 | +1. Install [black](https://github.com/psf/black), you can likely run |
| 118 | +```shell |
| 119 | +pip3 install black |
| 120 | +``` |
| 121 | + |
| 122 | +3. Use [black](https://github.com/psf/black) to ensure that the codestyle remains great |
| 123 | +```shell |
| 124 | +poetry run black dir |
| 125 | +``` |
| 126 | +2. Make sure tests are OK |
| 127 | +```shell |
| 128 | +poetry run pytest |
| 129 | +``` |
| 130 | +3. Create a PR with new features |
| 131 | +</details> |
| 132 | + |
| 133 | +## References |
| 134 | + |
| 135 | +<a id="1">[1]</a> |
| 136 | +Ma, Ziyuan and Luo, Yudong and Ma, Hang, 2021. Distributed Heuristic Multi-Agent Path Finding with Communication. |
| 137 | + |
| 138 | +<a id="2">[2]</a> |
| 139 | +Sartoretti, G., Kerr, J., Shi, Y., Wagner, G., Kumar, T.S., Koenig, S. and Choset, H., 2019. Primal: Pathfinding via reinforcement and imitation multi-agent learning. IEEE Robotics and Automation Letters, 4(3), pp.2378-2385. |
| 140 | + |
| 141 | +## License |
| 142 | + |
| 143 | +[](https://github.com/acforvs/po-mapf-thesis/blob/main/LICENSE) |
| 144 | + |
| 145 | + |
0 commit comments