Code Monkey home page Code Monkey logo

trafficsim's Introduction

TrafficSim

env = simpy.Environment()
nodes = [0, 1]
roads = {
    (0,1): (3000, 100, 50),
    (1,0): (3000, 40, 60)
}
rho = np.array([[0.0, 0.1, 0.9],
                [0.2, 0.0, 0.8]])

simulator = TrafficSimulator(rho, nodes, roads, env)
env.process(simulator.run())
env.run(until=100)

Basic idea and motivation

  • generate traffic data given a $\rho_{i,j}(t)$ of cars going from point $i$ to point $j$. This is a row-wise probability measure, where for each $n \in Nodes$ there is a $p_{i,j}$ of a vehicle appearing and wanting to make the trip $i-j$. So the idea is that this matrix performs some evolution over time.

Ambitions

  • given $\rho_{ij}(t)$ we should be able to generate a simulation where we can track each car in each point of the route. In this way we are going to be able to generate traffic volume, traffic speeds, and some other metrics related to each load at each time step.
  • an ambitious goal would be to study the ability to regenerate with simulated data $\rightarrow \rho (t)$. So given traffic information, find the pseudo probability matrix that generated it.

Model

  • the city is a DiGraph were the edges are Roads.
  • each road holds information
    • speed
    • distance
    • capacity
    • vehicles
  • each road connects to RoadNodes
  • each RoadNode $a$ holds the following information:
    • queue of vehicles wanting to start their journey at $a$ and going to $b$. That is, a queue of vehicles wanting to go through Road $a-b$, where $b$ corresponds to each direct edge from a.

Rules for time evolution

def run(self):
    for a in self.nodes:
        self.new_vehicles(a)
        a.release_queues()
    for road in self.roads:
        road.move_vehicles()
    yield self.env.timeout(1)
  • add new vehicles following the probability matrix.
  • release all queues, one car at a time per queue
  • move vehicles in that road
  • make time update

Examples

2 hour periodic discrete shifts.

def dynamic_rho(tf):
    env = simpy.Environment()
    nodes = [0, 1]
    roads = {
        (0,1): (100, 10, 3),
        (1,0): (100, 10, 3)
    }
    def rho(t):
        if t//7200 % 2 == 0:
            return np.array([[0.0, 0.25, 0.75],
                            [0.15, 0.0, 0.85]])
        return np.array([[0.0, 0.15, 0.85],
                        [0.25, 0.0, 0.75]])
    
    simulator = TrafficSimulator(rho, nodes, roads, env)
    env.process(simulator.run())
    for i in tqdm(range(1,tf)):
        env.run(until=i)

    simulator.plot_travel_times()

Next steps

  • at the moment there is no use for simpy really, but could come handly for semaphors

trafficsim's People

Contributors

ivanbelenky avatar

Stargazers

 avatar

Watchers

 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.