-
Notifications
You must be signed in to change notification settings - Fork 1
/
feed.py
executable file
·166 lines (116 loc) · 4.87 KB
/
feed.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
"""
config_dir = '/Users/ttumuon/muonSC8/sas/Python_new/config/'
sim_dir = '/Users/ttumuon/muonSC8/sas/Python_new/simulation/'
base_dir = '/Users/ttumuon/muonSC8/sas/Python_new/'
"""
config_dir = 'config/'
sim_dir = 'simulation/'
base_dir = ''
""" The following is code for config directory """
#*************************************** CASE ***************************************
# Read in the file
with open( config_dir + 'case.py', 'r') as file :
filedata = file.read()
#default values
dlanes = 3
dlength = 100
dnumcars = 50
#user input values
nlanes = 5
nlength = 200
nnumcars = 100
# Replace the target string
filedata = filedata.replace('lanes = ' + str(dlanes), 'lanes = '+str(nlanes))
filedata = filedata.replace('length = '+ str(dlength) , 'length = '+ str(nlength))
filedata = filedata.replace('trafficGenerator = TrafficGenerator('+str(dnumcars)+')', 'trafficGenerator = TrafficGenerator('+str(nnumcars)+')' )
# Write the file out again
with open( config_dir + 'case.py', 'w') as file:
file.write(filedata)
#====================================================================================
""" The following is code for simulation directory """
#*************************************** ROAD ***************************************
# Read in the file
with open( sim_dir + 'road.py', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('lanes = 3', 'lanes = 5')
filedata = filedata.replace('length = 100', 'length = 200')
# Write the file out again
with open( config_dir + 'road.py', 'w') as file:
file.write(filedata)
#*************************************** CAR ***************************************
# Read in the file
with open( sim_dir + 'car.py', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('lanes = 3', 'lanes = 5')
filedata = filedata.replace('length = 100', 'length = 200')
# Write the file out again
with open( config_dir + 'car.py', 'w') as file:
file.write(filedata)
#*************************************** TRAFFIC GENERATOR *************************
# Read in the file
with open( sim_dir + 'trafficGenerators.py', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('lanes = 3', 'lanes = 5')
filedata = filedata.replace('length = 100', 'length = 200')
# Write the file out again
with open( config_dir + 'trafficGenerators.py', 'w') as file:
file.write(filedata)
#====================================================================================
""" The following is code for base directory """
#*************************************** NAGEL ***************************************
# Read in the file
with open( base_dir + 'nagel.py', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('lanes = 3', 'lanes = 5')
filedata = filedata.replace('length = 100', 'length = 200')
# Write the file out again
with open( config_dir + 'nagel.py', 'w') as file:
file.write(filedata)
#*************************************** REPRESENTATION ***************************************
# Read in the file
with open( base_dir + 'representation.py', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('lanes = 3', 'lanes = 5')
filedata = filedata.replace('length = 100', 'length = 200')
# Write the file out again
with open( config_dir + 'representation.py', 'w') as file:
file.write(filedata)
#*************************************** SIMULATION MANAGER ***************************************
# Read in the file
with open( base_dir + 'simulationManager.py', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('lanes = 3', 'lanes = 5')
filedata = filedata.replace('length = 100', 'length = 200')
# Write the file out again
with open( config_dir + 'simulationManager.py', 'w') as file:
file.write(filedata)
#*************************************** INFO DISPLAYER ***************************************
# Read in the file
with open( base_dir + 'infoDisplayer.py', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('lanes = 3', 'lanes = 5')
filedata = filedata.replace('length = 100', 'length = 200')
# Write the file out again
with open( config_dir + 'infoDisplayer.py', 'w') as file:
file.write(filedata)
#*************************************** PLOT EXP 1 ***************************************
# Read in the file
with open( base_dir + 'plot_exp1.py', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('lanes = 3', 'lanes = 5')
filedata = filedata.replace('length = 100', 'length = 200')
# Write the file out again
with open( config_dir + 'plot_exp1 .py', 'w') as file:
file.write(filedata)
#=====================================================================================