Coder Social home page Coder Social logo

pocinnovation / underflow Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 0.0 609 KB

With underflow, create trafic light clusters that interact together to regulate circulation

License: Apache License 2.0

Python 99.86% Shell 0.14%
reinforcement-learning actor-critic deep-reinforcement-learning double-q-learning artificial-intelligence

underflow's Introduction

Regularflow

(The project is under construction, the document and code documentation will evolve you can ask me if you don't understand).

This module allows you to create trafic light clusters that interact together to regulate circulation. Trafic lights are smart and can take decision according to the environnement.

I use Deep-reinforcement Q learning for the first POC and Actor-Critic A3C for the next POC

Introduction

There are two types of traffic lights. Influencers and Followers. Influencers are traffic lights that train and followers are trafic lights symmetrical to their influencers. A follower will take the opposite action of an influencer. This allows the case managed two traffic lights that don't have to be green at the same time

When we create an influencer we can assign him a follower and this follower will take the opposite actions of this influencer. To create a cluster of traffic lights that communicate with each other for the regularisation of a zone it's simple. When we create a fire we give the id of the other traffic lights

Managers are fake cameras to simulate the number of cars and pedestrians on the way of a traffic light. Each traffic lights has a manager who tells him the numbers of cars and pedestrians on his way.

Depending on the numbers of cars and pedestrians the traffic lights are rewarded. Each traffic light knows the status of all the others traffic lights which are into the cluster. If a traffic light is overbooked and causes the bottling of another traffic light, traffic lights will adapt to gain the most reward and therefore regulate the traffic

You need to have Apache Kafka and Zookeper for the stream communication.

sheme

First you need to create topic's partitions :

One for Manager's communications and one for traffic lights communications

  • Download apache kafka here.

  • Install regularflow with setup :

    ./setup install

  • Start a kafka's broker and a Zookeper's server

  • Run this code in an python's interpreter

from confluent_kafka.admin import AdminClient, NewTopic

adminConfig = {
                'bootstrap.servers': 'localhost:9092'
              }

topicList = ["manager0", "cluster0", "display"]    # Topic Names
partitions = [4, 4, 4]   # Here replace the number 4 by the number of Trafic light that you want in the cluster
replications = [1, 1, 1]

if __name__ == '__main__' :
    newTopics = []
    adminClient = AdminClient(adminConfig)
    adminClient.delete_topics(topicList)
    adminClient.delete_topics(["__consumer_offsets"])
    for i in range(len(topicList)):
        newTopics.append(NewTopic(topicList[i], partitions[i] , replications[i]))
    print(newTopics)
    adminClient.create_topics(newTopics)

Example of configuration for a "follower" trafic light

from regularflow import newAgent, startDemo, startAgent

consumerConfig = {
                'bootstrap.servers': 'localhost:9092',
                'group.id': 'cluster0',
                'auto.offset.reset': 'earliest'
                }
producerConfig = {
                'bootstrap.servers': 'localhost:9092'
                 }

agent = newAgent(1, consumerConfig, producerConfig, "cluster0", "manager0","display", "follower")  # the first number is the id of the traffic light
agent._setAgents([0]) # Here type the id of the other trafic light in the cluster for the communication
startDemo(agent) # run the agent with startDemo for the non-training mode and with startAgent for the training mode

Example of configuration for a "influencer" trafic light

from regularflow import newAgent, startDemo, startAgent

consumerConfig = {
                'bootstrap.servers': 'localhost:9092',
                'group.id': 'cluster',
                'auto.offset.reset': 'earliest'
                }
producerConfig = {
                'bootstrap.servers': 'localhost:9092'
                 }


agent = newAgent(0, consumerConfig, producerConfig,"cluster0", "manager0", "display", "influencer") # the first number is the id of the traffic light
agent._setAgents([1]) # set the id of other traffic lights in the cluster for communication
agent._setForbidenAgents([1]) # set the follower's id of this influencer
agent._restore("/home/roloman/projet-perso/regularflow/example/saves/save_influencer0") # setup the path of the the saved model
startDemo(agent)  # start agent with startDemo for start with non-training mode
agent._save() # specify the save for save this traffic light

Usage example :

For an example, go in the example directory and run in differents terminals :

  • The code for initialisation topic's partitions
  • Influencer.py and Follower.py
  • Then Manager0.py and Manager1.py

You can see the training mode

Author

underflow's People

Contributors

aslhans avatar l-antique avatar paulmonnery avatar

Stargazers

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

Watchers

 avatar  avatar

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.