-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
52 lines (43 loc) · 1.57 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import gymnasium as gym
import numpy as np
import traci
from rlsumo.envs.multiagent_ringroad import MultiAgentRingRoad
from rlsumo.envs.ringroad import RingRoad
from rlsumo.metrics.metrics import Metrics
from rlsumo.utils.params import Params, VehicleParams, SimulationParams, RLParams
params = Params(VehicleParams(env_vehicles=20, rl_vehicles=2, rl_action_type="discrete", agent_type="idm"),
RLParams(),
SimulationParams(render=True))
env_config = {
"params": params
}
vmt = []
fuel = []
for i in range(1):
test = RingRoad(env_config)
obs, info = test.reset()
metrics = Metrics(test)
s = 0
while s <= 6000:
obs, rew, term, done, info = test.step(action=None)
if term:
print("Terminating")
break
metrics.step()
s += 1
print("Episode no: {step}".format(step=i))
t = 0
for ind, std in enumerate(metrics.stabilizing_time[3000:]):
if std <= 0.1:
t = ind + 1
break
print("Stabilizing time: {t}".format(t=t))
print("Maximum Gap: {gap}".format(gap=max(metrics.maximum_gap[t + 3000:])))
print("Vehicle Miles Travelled: {vmt}".format(vmt=sum(metrics.vmt_dict.values())))
print("Fuel Consumption: {fuel}".format(fuel=sum(metrics.fuel_dict.values()) * 1e-3))
print("Economy: {eco}".format(eco=metrics.vmt_dict["veh_id_0"]/metrics.fuel_dict["veh_id_0"]))
vmt.append(sum(metrics.vmt_dict.values()))
fuel.append(sum(metrics.fuel_dict.values()) * 1e-3)
test.close()
metrics.plot()
print(np.mean(vmt), np.mean(fuel))