Code Monkey home page Code Monkey logo

deep-rl-tsc's Introduction

deep-rl-tsc

Distributed Deep Reinforcement Learning Traffic Signal Control

Distributed deep reinforcement learning traffic signal control framework for SUMO traffic simulation.

YouTube Video Demo

This code is an improvement and extension of published research along with being part of a PhD thesis. Please cite the following reference if you use this code in your own research:

@article{doi:10.1080/15472450.2018.1491003,
author = {Wade Genders and Saiedeh Razavi},
title = {Asynchronous n-step Q-learning adaptive traffic signal control},
journal = {Journal of Intelligent Transportation Systems},
volume = {0},
number = {0},
pages = {1-13},
year  = {2019},
publisher = {Taylor & Francis},
doi = {10.1080/15472450.2018.1491003},
URL = {https://doi.org/10.1080/15472450.2018.1491003},
eprint = {https://doi.org/10.1080/15472450.2018.1491003}
}

Installation

Dependancies

Running the code

Training

python run.py -nogui -save -mode train

To learn more about all input arguments, run python run.py --help.

After training has completed, execute:

python graph_actors.py

to create a visualization of actors with different action explortation rates, similar to:

Screenshot

When training, optimal execution requires balancing the number of parallel actors -actor and learners -learner. A simulation with a single intersection can be left at the default settings (i.e., 1 learner and the rest actors). As the number of signalised intersections in the network increases, more learners will be required. Agents are distributed to learners in an approximately equal fashion; each learner is responsible for performing batch updates for their assigned subset of agents (e.g., a network with 13 signalised intersections and 3 learners would allocate 4, 4 and 5 intersections to the learners). Each actor is assigned an epsilon greedy exploration policy from equally spaced intervals between a random policy and a defined greedy policy -eps 0.05 (e.g., with 4 actors and -eps 0.05, the actors implement one of [1.0, 0.68, 0.37, 0.05] epsilon greedy policies).

Testing

To watch learned agents, execute:

python run.py -load -mode test -actor 1 -learner 1

Overview

This framework takes a SUMO network simulation and develops deep reinforcement learning agents for each signalised intersection to act as optimal signal controllers. A distributed actor/learner architecture implemented with Python multiprocessing enables hardware scalability. This research implements n-step Q-learning, an off-policy, value-based form of reinforcement learning.

Simulation

Two simple SUMO simulations are included, the first (-netfp networks/single.net.xml -sumocfg networks/single.sumocfg) with a single intersection:

Screenshot

and the second (default) with two intersections:

Screenshot

Vehicle generation is implemented in Vehicle.py class. Vehicles are generated uniform randomly over origin edges with their departure times into the network modelled as a Poisson process. SUMO subscriptions are used to optimize performance accessing vehicle data. Yellow and red phases are inserted between conflicting green phases, their duration controlled by -yellow 4 -red 4.

Reinforcement Learning

The n-step Q-learning algorithm is used to train agents to implement acyclic, adaptive traffic signal control. An agent's policy selects the next green phase for a fixed duration. Green phases can be selected in an acyclic manner (i.e., no cycle). The fixed duration (i.e., action repeat) of the green phase is controlled with -arepeat 15. Smaller action repeats enable more frequent control but are likely more difficult to learn. The agent's state is a function of the density of all incoming intersection lanes. The reward is the negative cumulative delay of all vehicles on incoming lanes. The default deep neural network is a 2 hidden layer fully-connected architecture to model the action-value function, implemented in NeuralNetwork.py.

In -mode train the actors first execute until all experience replays are filled -replay 10000. Then actors continue to generate trajectories until learners perform sufficient batch updates -updates 10000. In -mode test the actors execute 1 simulation.

Help

Consult the SUMO Wiki and API docs for additional help.

Additional Resources

My PhD thesis on this topic

Some of my other reinforcement learning traffic signal control research

deep-rl-tsc's People

Contributors

docwza avatar hammertime89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

deep-rl-tsc's Issues

error

after running
python run.py -nogui -save -mode train
Screenshot from 2022-05-25 16-22-01

can someone help me, i have no idea how to continue this

file: deep-rl-tsc/NetworkData.py return for get_intersection_data not specified

def get_intersection_data(self, net):
nodes = [n for n in net.getNodes()]

    nodes = net.getNodes()
    node_data = {str(node.getID()):{} for node in nodes} 
                                                                                      
    for node in nodes:
        node_ID = str(node.getID())
        node_data[node_ID]['incoming'] = [str(lane.getID()) for lane in node.getIncoming()]
        node_data[node_ID]['outgoing'] = [str(lane.getID()) for lane in node.getOutgoing()]

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.