-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·40 lines (33 loc) · 1.08 KB
/
main.py
File metadata and controls
executable file
·40 lines (33 loc) · 1.08 KB
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
#!/usr/bin/python
"""This module contains the entry function for the traffic simulator.
Reads argument information and executes a simulation depending on the given
arguments.
"""
import argparse
import intersection
import learner
import random
import time
import viewer
def main():
"""Entry function for the traffic simulator."""
learning_algorithm = learner.Learner()
view = viewer.Viewer()
intersec = intersection.Intersection()
time_steps = 0
while 1:
# Snapshot the state of the roads
view.update_roads(intersec.get_roads()[0], intersec.get_roads()[1])
if time_steps % 1000 == 0 and time_steps != 0:
print intersec.get_performance()
old_state = intersec.get_state()
# Update the state of the roads
action = learning_algorithm.get_action(old_state)
# action = time_steps % 10 == 0
intersec.update_state(action)
new_state = intersec.get_state()
learning_algorithm.learn(old_state, new_state, action)
time_steps += 1
time.sleep(1)
if __name__ == "__main__":
main()