Traffic simulation for traffic light A.I. training
Project description
TrafficLightAI
A python traffic simulation serving as a playground to create traffic light A.I. systems. The traffic simulation uses a cellular automata approach to simulate large traffic grids. The simulation is optimized with Numba.
Installation
pip install ai-traffic-light-simulator
Example
from traffic_simulation_numba import TrafficSimulation
# OR from traffic_simulation import TrafficSimulation
import random
NORTH_SOUTH_GREEN = 0
EAST_WEST_GREEN = 1
# A basic A.I. which randomly determines light timings
# Inputs: [North waiting, East waiting, South waiting, West Waiting, Previous Light Direction]
def my_ai(inputs):
if inputs[-1] == NORTH_SOUTH_GREEN:
return EAST_WEST_GREEN, random.randint(1,30)
if inputs[-1] == EAST_WEST_GREEN:
return NORTH_SOUTH_GREEN, random.randint(1,30)
# Make traffic simulation object with our naive A.I.
sim = TrafficSimulation(
my_ai,
grid_size_x=8,
grid_size_y=8,
lane_length=10,
max_speed=5,
in_rate=0.2,
initial_density=0.1,
seed=42
)
results = sim.run_simulation(1000) # Runs the simulation for 1000 ticks
print(results)
# Returns { 'cars_stopped': 131680, 'carbon_emissions': 672824 }
# Render a frame of the simulation after 1000 ticks
sim.render_frame("Small.png")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for ai-traffic-light-simulator-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bee7a9c3236c26873062243ddf5dc29db3ca666fbb7c902348a8021d24e8e21b |
|
MD5 | 03e7480501cbdf132837e17bda98af3b |
|
BLAKE2b-256 | f71d5876406f3d29c41e929cf0c7b95c372d0372ea7c16f3b93c8b9fa0fe880e |
Close
Hashes for ai_traffic_light_simulator-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 713d17de44773318095af0409b9c06dc07c8a3e20998a6a83649e4f9731c7726 |
|
MD5 | cbe000781267face981a698f209cc985 |
|
BLAKE2b-256 | a4434305932e98fec6d7fd9c92dd33af69737864547709d9573fdb4d5e09d4e2 |