[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sumo-dev] automate the simulation process
|
import random
import timeit
import matplotlib.pyplot as plt
import datetime
import itertools
import sys
date=datetime.datetime.now()
print("Last execution:", date, "\n" )
#print random time for
def car_pass(max):
roll = random.randint(1,max)
return roll
x = 1
result =[]
time_result=[]
while x <= 20:
start_time=timeit.default_timer()
result.append(car_pass(800))
time_result.append((timeit.default_timer()-start_time)*1000000)
result.append(car_pass(result[x-1]))
start_time=timeit.default_timer()
time_result.append((timeit.default_timer()-start_time)*1000000)
print("Scenario %s: %s cars passed in %.5s seconds when the traffic light is green" % (x,result[x-1],time_result[x-1]))
print("When the traffic lights are in the phase amber-red %s vehicles passed in %s seconds" % (result[x], time_result[x]))
x+= 1
with open("Scenario" +str(x/2) +".txt", "w") as text_file:
#print(f"Scenario No 1", file=text_file)
print(f"vehicles passed: {result}", file=text_file)
print(f"in seconds: {time_result}", file=text_file)
plt.plot(time_result,result,'ro')
plt.ylabel("Number of cars")
plt.xlabel("Time ")
#plt.line=plt.plot(time_result,result, marker='*', markerfacecolor='red')
plt.show()