forked from dongspam0209/traffic_light_control_DQN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
44 lines (36 loc) · 1.5 KB
/
util.py
File metadata and controls
44 lines (36 loc) · 1.5 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
41
42
43
44
import sys
import os
from sumolib import checkBinary
def set_sumo(gui, sumocfg_file_name, max_steps):
"""
Configure various parameters of SUMO
"""
# sumo things - we need to import python modules from the $SUMO_HOME/tools directory
if 'SUMO_HOME' in os.environ:
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variable 'SUMO_HOME'")
# setting the cmd mode or the visual mode
if gui == False:
sumoBinary = checkBinary('sumo')
else:
sumoBinary = checkBinary('sumo-gui')
# setting the cmd command to run sumo at simulation time
sumo_cmd = [sumoBinary, "-c", os.path.join('intersection', sumocfg_file_name), "--no-step-log", "true", "--waiting-time-memory", str(max_steps)]
return sumo_cmd
def set_train_path(models_path_name):
"""
Create a new model path with an incremental integer, also considering previously created model paths
"""
models_path = os.path.join(os.getcwd(), models_path_name, '')
os.makedirs(os.path.dirname(models_path), exist_ok=True)
dir_content = os.listdir(models_path)
if dir_content:
previous_versions = [int(name.split("_")[1]) for name in dir_content]
new_version = str(max(previous_versions) + 1)
else:
new_version = '1'
data_path = os.path.join(models_path, 'model_'+new_version, '')
os.makedirs(os.path.dirname(data_path), exist_ok=True)
return data_path