-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_sotl.py
46 lines (39 loc) · 1.39 KB
/
run_sotl.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
import gym
from environment import TSCEnv
from world import World
from generator import LaneVehicleGenerator
from agent import SOTLAgent
from metric import TravelTimeMetric
import argparse
# parse args
parser = argparse.ArgumentParser(description='Run Example')
parser.add_argument('config_file', type=str, help='path of config file')
parser.add_argument('--thread', type=int, default=1, help='number of threads')
parser.add_argument('--steps', type=int, default=100, help='number of steps')
parser.add_argument('--delta_t', type=int, default=1, help='how often agent make decisions')
args = parser.parse_args()
# create world
world = World(args.config_file, thread_num=args.thread)
# create agents
agents = []
for i in world.intersections:
action_space = gym.spaces.Discrete(len(i.phases))
agents.append(SOTLAgent(action_space, i, world))
# create metric
metric = TravelTimeMetric(world)
# create env
env = TSCEnv(world, agents, metric)
# simulate
obs = env.reset()
actions = []
for i in range(args.steps):
actions = []
for agent_id, agent in enumerate(agents):
actions.append(agent.get_action(obs[agent_id]))
obs, rewards, dones, info = env.step(actions)
print(world.intersections[0]._current_phase, end=",")
print(env.eng.get_average_travel_time())
#print(obs)
#print(rewards)
# print(info["metric"])
#print("Final Travel Time is %.4f" % env.metric.update(done=True))