Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commissioned report "Traffic Nightmare" - a damming investigation into the slowdown impact of commercial vehicles #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
layout python3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ target/
# Temporary data
.ipynb_checkpoints/

.direnv
1,257 changes: 1,257 additions & 0 deletions Traffic.ipynb

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ipython[notebook]
numpy
matplotlib
random
math
statistics
95 changes: 95 additions & 0 deletions test_traffic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from traffic import *

my_car = Car(0)

Ncars = 30
positions = np.linspace(0, 1000, num=Ncars+1)
cars = [Car(positions[i]) for i in range(Ncars)]
for i in range(Ncars-1):
cars[i].set_next(cars[i+1])
cars[Ncars-1].set_next(cars[0])



def test_magic_setters():
my_car.pos = 5
assert my_car.pos == 5
my_car.length = 7
assert my_car.length == 7

def test_rollup():
car = Car(10)
car2 = Car(400)
car2.speed = 0
car.set_next(car2)
for i in range(40):
car.move()
# print(car)
assert car.pos < 400

def test_rollup2():
car = Car(10)
car2 = Car(400)
car2.speed = car.top_speed / 2
car.set_next(car2)
for i in range(20):
car2.pos = (car2.pos + car2.speed) % 1000
car.move()
# print(str(car)+ " "+str(car2))
assert car.pos < car2.pos

def test_rollup3():
car = Car(800)
car2 = Car(900)
car2.speed = car.top_speed / 2
car.set_next(car2)
for i in range(40):
car2.pos = (car2.pos + car2.speed) % 1000
car2.advance_time()
# print(car.space())
car.move()
# print(str(car)+ " "+str(car2)+" "+str(car.space()))
assert car.pos < car2.pos

def test_dist_consistency():

tol = 1.0e-4
sim = Simulation(cars)

for i in range(10):
sim.run_once()
assert 1000-tol <= sim.dist_array().sum()+5*30 <= 1000 + tol

def test_create_hard():

simz = Simulation(30, True)
print(simz.N)
assert simz.N == 7*30

def test_hard_cars():

simz = Simulation(30, True)
assert len(simz.dist_array()) == 7*30

def test_nightmare_cars():

simx = Simulation(30, False, True) # normal + nightmare

int_count = 0
for x in simx.cars:
if type(x) is not Car:
int_count += 1

assert int_count == 0


def test_nightmare_cars2():

simx = Simulation(30, True, True) # hard + nightmare

int_count = 0
for x in simx.cars:
if type(x) is not Car:
int_count += 1

assert int_count == 0
Loading