Giter VIP home page Giter VIP logo

xrouting's Introduction

XRouting

XRouting: An explainable vehicle rerouting system based on reinforcement learning with Transformer structure

Table of Contents

Citation

If you use our code, please consider cite the following: Z. Wang and S. Wang, "XRouting: Explainable Vehicle Rerouting for Urban Road Congestion Avoidance using Deep Reinforcement Learning," 2022 IEEE International Smart Cities Conference (ISC2), Pafos, Cyprus, 2022, pp. 1-7, doi: 10.1109/ISC255366.2022.9922404.

@INPROCEEDINGS{9922404,
  author={Wang, Zheng and Wang, Shen},
  booktitle={2022 IEEE International Smart Cities Conference (ISC2)}, 
  title={XRouting: Explainable Vehicle Rerouting for Urban Road Congestion Avoidance using Deep Reinforcement Learning}, 
  year={2022},
  volume={},
  number={},
  pages={1-7},
  doi={10.1109/ISC255366.2022.9922404}}

Installation

Installation instructions are provided for MacOS Monterey 12.4. In order to reproduce the results, the traffic scenario simulator SUMO with version 1.13.0 and the reinforcement learning training tool RLlib with version 1.12.0 should be installed. Besides, the version of python is highly recommended to be 3.8. The installation steps are elaborated as follows.

  1. Users can install SUMO by following the macOS section in https://sumo.dlr.de/docs/Installing/index.html#macos . Note that users are strongly recommended to set SUMO_HOME directory carefully.
  2. Users can install Ray/RLlib by following https://docs.ray.io/en/latest/ray-overview/installation.html . Note that Installing Ray with Anaconda is highly suggested.
  3. It is equally important that the version of tensorflow should be 2.7+.
  4. The versions of xlrd and xlwt should be 1.2.0 for the sake of sucessful running.
  5. Note that after installing SUMO, it is prerequisite for users to modify line 18 in /rl/env/multi_agent_rerouting_env.py and line 21 in /rl/env/dynamic_rerouting_env.py for the sake of importing SUMO packages for SUMO and python connection.
  6. Note: All the training and evaluation processes should be conducted under the downloaded repository directory.

Scenario

The training scenario is defined in the directory \sumo_scenario\, including the configuration files scenario.sumocfg.xml for training stage and scenario_rl.sumocfg.xml for evaluation stage, scenario.net.xml for traffic netwrok construction, exercise.add.xml for necessary components and scenario.trips.xml for determining traffic trips. Note that edge_coordinates.xlsx is stored in this directory as well, which is used to store the coordinates information of all edges. The training scenario is illstrated as:

Training

In order to train the models including the proposed XRouting and the other two comparisms (normal PPO and DQN), users are highly recommended to run the train.py file in virtue of terminal by following the command:

python train.py --run=XRouting

Note that input argument --run is used to indicate the model to be trained. If users desire to train normal PPO and DQN, the value of --run should be set as PPO and DQN respectively. The default value is XRouting. Moreover, there are other argements that could be claimed by users, whose names and meanings can be found by following the command:

python train.py -h

Note that users can visualize training performance by running tensorboard --logdir [directory] in a seperate terminal, where [directory] is defaulted to \training_result\XRouting\PPO for XRouting model, \training_result\PPO\PPO for PPO model and \training_result\DQN\DQN for DQN model.

Another important training results are information of trips. More specifically, the basic trip information for each vehicle, including travelling time and travelling length, of each episode during training process is stored in the directory \training_tripinfo\XRouting_training for XRouting model, \training_tripinfo\PPO_training for PPO model and \training_tripinfo\DQN_training for DQN model.

Finetuning

Though XRouting model for the aforementioned traffic scenario has been well tuned, users are still able to tune the hyperparameters used for training. More specifically, all the three models hyperparameters tuning can be implemented in the directory \rl\model_config.py. For example, the hyperparameters setting for XRouting is illustrated as:

 def XRouting_config(self, env_name):
        """
        Configuration of XRouting actor
        """
        ModelCatalog.register_custom_model("XRouting_model", XRoutingModel)

        return {
            "env": env_name,
            "num_gpus": self.num_gpus,
            "num_envs_per_worker": 1,
            "gamma": 0.99,
            "train_batch_size": 4096,
            "sgd_minibatch_size": 256,
            "lr": 4e-4,
            "vf_loss_coeff": 1e-5,
            "model": {
                "custom_model": "XRouting_model",
                "custom_model_config": {
                    "attention_dim": 64,
                    "num_heads": 4,
                    "head_dim": 32,
                    "mlp_dim": 100,
                    "observation_dim": (38, 6),
                    "pos_encoding_dim": (38, 1),
                }
            },
            "entropy_coeff": 0.01,
            "num_sgd_iter": 4,
            "framework": "tf",
            "num_cpus_per_worker": self.num_cpus_per_worker,
        }

For the meaning and function of each hyperparameter, it is strongly recommended that users can search them by following the url: https://docs.ray.io/en/latest/rllib/rllib-algorithms.html .

Evaluation

After obtaining the trained models, users can evaluate the models in multi-agent scenario by using the following command

python evaluation_multi_agent.py --run=XRouting

In the evaluation stage, both scenario_rl.sumocfg.xml and scenario_rl.trips.xml are used instead, and scenario_rl.trips.xml defines 50% penetration, which is generated randomly. Furthermore, SUMO_GUI is used for visulization because of just one episode.

Note that the four well trained models have already been stored in the directory /trained_models/XRouting/, and the default model used is /trained_models/XRouting/checkpoint_1/checkpoint-50. Userd can also utilize the specific trained model in virtue of the argument --checkpoint-dir. All the evaluation results, that is, the excel files which contains the input observations and the corresponding actions of all the steps that rl vehicles take, are stored in the directory /evaluation_results/.

xrouting's People

Contributors

zkbig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xrouting's Issues

Errors

Hello

Thank you for sharing your models.
I followed your instructions to build the environment.
I had error when running python train.py --run=PPO

(RolloutWorker pid=45995) Loading additional-files from '/home/osboxes/Desktop/XRouting/sumo_scenario/exercise.add.xml'...
(RolloutWorker pid=45995) Loading of additional-files failed.
(RolloutWorker pid=45996) Loading net-file from '/home/osboxes/Desktop/XRouting/sumo_scenario/scenario.net.xml'... done (6ms).
(RolloutWorker pid=45996) Loading additional-files from '/home/osboxes/Desktop/XRouting/sumo_scenario/exercise.add.xml'...
(RolloutWorker pid=45996) Loading of additional-files failed.
Traceback (most recent call last):
File "train.py", line 135, in
local_dir=training_results_dir
File "/home/osboxes/anaconda3/envs/Py/lib/python3.7/site-packages/ray/tune/tune.py", line 695, in run
raise TuneError("Trials did not complete", incomplete_trials)

About 'next_state'

Hi, Thank you for open-source your code, I have a question: when the agent makes an action according to the current state, how can we get the next state? I don't seem to have found the relevant explanation and method in your paper and code。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.