Code Monkey home page Code Monkey logo

trafficlight-rl's Introduction

TrafficLight-RL

This is Reinforcement Learning Project to Build RL agent to control Traffic light in a 4 way intersection to optimize traffic flow. Main aim is to minimize average waiting time of vehicles and increase average velocities. This is course project for CS221 course of Stanford University.

Simulator Used and Environement Setup:

We used Flow project by OpenAI and SUMO simulator. Flow us wrapper on top of SUMO, which provides RL wrappre and provide wasy ways to integrate with RL algorithms. Basically it creates a gym environment for us, that we can use with various out of box RL algorithms directly.

We had just 1 intersection. and TrafficLightFlow.py is the file where all the parameters of simulations are defined. Here are state,action and rewards used by us:

  1. States: k-nearest vehicles position & Velocity from interseciton. we tried with k=2,5,10
  2. Actions: 0,1. 1 when signal needs to be changed, else 0
  3. Reward: - avg waiting time + penality for standstill vehicles + penality for switching lights. (penalities are -ve)

We had to dig further and by spending lot of time, we were able to add left turn in to the simulator. FLOW didn;t have any documentation for it. FLOW seems to be mroe focused on creating AI agents for Cars and not traffic lights. LeftTurnWithTwoLanes directory contains, custom network, environment and parameter file to create flow environment with 2 lanes in each edge and adding left turn.

RL Algorithms

We first tried Out of Box, OpenAI Baselines algorithms DQN with replay buffer and a target network. It uses TensorFlow with Keras Layer abstraction. It worked pretty well. Then we spent most of our time in writing algorithms from scratch in pytorch and performing experiments and generating SUMO emission file from predictions and generating inference from this emission results. we tried these 3 algorithms varient of Deep Q Learning.

  1. Simple DQN: simple 2 layer MLP network for Q function approximator. without any replay experience and no target netowork.
  2. DQN with Replay buffer: DQN + a replay buffer. Replay buffer improves sample efficiency of training. and you can get most out of your training data with few iterations.
  3. DDQN with priortity buffer: Then we added one mpre Neural Net, which is called target netowork, which stores the weights for target Q Values. and after each n_updates, we copy parameters from Q network to Target Q network. Q network is updated once for each sample.

We also used Checkpointing to keep storing models after each 100 episodes of training. you can find code in prediction files for storing and loading checkpoints in pytorch.

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.