-
Notifications
You must be signed in to change notification settings - Fork 3
/
testing_main.py
55 lines (42 loc) · 1.71 KB
/
testing_main.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
53
54
55
from __future__ import absolute_import
from __future__ import print_function
import os
from shutil import copyfile
from testing_simulation import Simulation
from generator import TrafficGenerator
from model import TestModel
from visualization import Visualization
from utils import import_test_configuration, set_sumo, set_test_path
if __name__ == "__main__":
config = import_test_configuration(config_file='testing_settings.ini')
sumo_cmd = set_sumo(config['gui'], config['sumocfg_file_name'], config['max_steps'])
model_path, plot_path = set_test_path(config['models_path_name'], config['model_to_test'])
Model = TestModel(
input_dim=config['num_states'],
model_path=model_path
)
TrafficGen = TrafficGenerator(
config['max_steps'],
config['n_cars_generated']
)
Visualization = Visualization(
plot_path,
dpi=96
)
Simulation = Simulation(
Model,
TrafficGen,
sumo_cmd,
config['max_steps'],
config['green_duration'],
config['yellow_duration'],
config['num_states'],
config['num_actions']
)
print('\n----- Test episode')
simulation_time = Simulation.run(config['episode_seed']) # run the simulation
print('Simulation time:', simulation_time, 's')
print("----- Testing info saved at:", plot_path)
copyfile(src='testing_settings.ini', dst=os.path.join(plot_path, 'testing_settings.ini'))
Visualization.save_data_and_plot(data=Simulation.reward_episode, filename='reward', xlabel='Action step', ylabel='Reward')
Visualization.save_data_and_plot(data=Simulation.queue_length_episode, filename='queue', xlabel='Step', ylabel='Queue lenght (vehicles)')