-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtrip_gen.bat
More file actions
369 lines (314 loc) · 10.7 KB
/
trip_gen.bat
File metadata and controls
369 lines (314 loc) · 10.7 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
@echo off
rem trip_gen.bat
rem Craig Heither, CMAP
rem Matt Stratton, CMAP
rem Nick Ferguson, CMAP
echo This script:
echo 1) Converts UrbanSim outputs into Trip Generation model inputs.
echo 2) Uses UrbanSim land use data to develop trip allocation factors
echo for heavy trucks.
echo 3) Runs the work-from-home allocation model.
echo 4) Runs the Trip Generation model.
echo 5) Creates the trip generation files to import into the emmebank
echo and runs distribute.trucks and distribute.poes.
echo ===================================================================
echo.
rem Revision history
rem ----------------
rem 10/05/2018 Heither: Change Module 2 so truck.class.skim.mac is the
rem primary truck distribution macro; use Python version of
rem prepare_iom_inputs.
rem 07/16/2020 Ferguson: Refined the Python search to use a virtual
rem environment with custom package requirements by calling
rem activate_python_env.bat.
rem 09/15/2020 Ferguson: Replaced summary_tg_results.sas with
rem summarize_tg_results.py.
rem 03/01/2021 Ferguson: Updated paths for removal os sas directory.
rem 05/14/2021 Heither: Include option to run both modules in one pass.
rem 11/08/2022 Ferguson: Removed call to activate_python_env.bat. Uses only conda env.
rem 02/20/2023 Heither: Read arguments from batch_file.yaml to run model.
rem ====================================================================
rem Settings
rem --------
rem In case CMD.exe is doing stuff in the wrong directory, this command
rem changes the directory to where the batch file was called from.
cd %~dp0
rem -- Read model run settings from Telework.yaml --
for /f "eol=# skip=2 tokens=2 delims=:" %%a in (Telework.yaml) do (set sc=%%a & goto break1)
:break1
for /f "eol=# skip=4 tokens=2 delims=:" %%b in (Telework.yaml) do (set wfhFile=%%b & goto break2)
:break2
for /f "eol=# skip=5 tokens=2 delims=:" %%c in (Telework.yaml) do (set wfh=%%c & goto break3)
:break3
for /f "eol=# skip=6 tokens=2 delims=:" %%d in (Telework.yaml) do (set tc14=%%d & goto break4)
:break4
for /f "eol=# skip=8 tokens=2 delims=:" %%e in (Telework.yaml) do (set wfhLow=%%e & goto break5)
:break5
for /f "eol=# skip=9 tokens=2 delims=:" %%f in (Telework.yaml) do (set wfhMedium=%%f & goto break6)
:break6
for /f "eol=# skip=10 tokens=2 delims=:" %%g in (Telework.yaml) do (set wfhHigh=%%g & goto break7)
:break7
for /f "eol=# skip=11 tokens=2 delims=:" %%g in (Telework.yaml) do (set declineScaled=%%g & goto break8)
:break8
set sc=%sc:~1,3%
set wfhFile=%wfhFile:~1%
set wfh=%wfh:~1%
set tc14=%tc14:~1%
set wfhLow=%wfhLow:~1%
set wfhMedium=%wfhMedium:~1%
set wfhHigh=%wfhHigh:~1%
set declineScaled=%declineScaled:~1%
@echo.
@echo ========================================
@echo --- Model Run Settings ---
@echo Scenario = %sc%
@echo Create WFH validation file = %wfhFile%
if %sc%==100 (
@echo 2019 Usual WFH share = %wfh%
@echo 2019 WFH 1-4 days share = %tc14%
) else (
@echo 2025/26 WFH low rate group share= %wfhLow%
@echo 2025/26 WFH medium rate group share= %wfhMedium%
@echo 2025/26 WFH high rate group share= %wfhHigh%
@echo Decline factor= %declineScaled%
)
@echo ========================================
@echo.
rem
set dt=%date%
set tm=%time%
echo Run module list:
echo 1) Run trip generation model ONLY (items 1-4 above).
echo 2) Import trip generation files into emmebank and run distribute
echo macros ONLY (item 5 above).
echo 3) Run the trip generation model, import files into the emmebank
echo and run distribute macros. Use this for UrbanSim data. (All items)
echo.
set /p choice="[SELECT A MODULE TO RUN] "
echo.
if not "%choice%"=="" (
set choice=%choice:~0,1%
if "%choice%"=="1" (goto one)
if "%choice%"=="2" (goto two)
if "%choice%"=="3" (goto notes)
)
echo !!! "%choice%" IS NOT A VALID SELECTION !!!
echo Please resubmit the program and select a number from the module list.
goto end
:notes
rem Notes for running both modules. Move these up front.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo SET GROWTH FACTOR
echo.
echo Before continuing, please update the growth factor variable in
echo each of the following scripts:
echo * prep_macros\distribute.trucks
echo * prep_macros\distribute.poes
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pause
echo.
rem -- Run trip generation model. --
:one
set /a val=%sc%
if %val% geq 100 (goto runit)
goto badscen
:runit
rem Supply project and run titles.
set /p project="[ENTER PROJECT TITLE (E.G., c26q2)] "
echo.
set /p run="[ENTER RUN TITLE (E.G., 100_20260202)] "
echo.
set project=%project: =%
set run=%run: =%
if "%project%" == "" (
echo !!! NO PROJECT TITLE !!!
echo Please resubmit the program and enter a project title.
goto end
)
if "%run%" == "" (
echo !!! NO RUN TITLE !!!
echo Please resubmit the program and enter a run title.
goto end
)
echo ===================================================================
echo.
rem Activate Python env
call %~dp0..\Scripts\manage\env\activate_env.cmd
if %ERRORLEVEL% NEQ 0 (goto end)
cd tg\scripts
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Updating Trip Generation inputs with UrbanSim data ...
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
python urbansim_update_tg_input_files.py
if %ERRORLEVEL% NEQ 0 (goto urbansim_issue)
@echo.
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Updating Heavy Truck Trip allocation weights with UrbanSim data ...
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
python urbansim_hcv_allocation.py
if %ERRORLEVEL% NEQ 0 (goto hcv_issue)
cd ..\fortran
rem -- Run the Work-from-Home procedures. --
set savedir="%cd%"
cd wfhmodule
set filedir="%cd%"
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Starting the work-from-home allocation model ...
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if %val%==100 (
echo Running wfhflag_base.py ...
python wfhflag_base.py %filedir% %savedir% %wfhFile%
) else (
echo Running wfhflag.py ...
python wfhflag.py %filedir% %savedir% %wfhFile%
)
if %ERRORLEVEL% NEQ 0 (goto wfh_issue)
cd ..
rem Check for necessary input files.
if not exist HH_IN.TXT (goto socec_data_error)
if not exist GQ_IN.TXT (goto socec_data_error)
if not exist ATTR_IN.TXT (goto socec_data_error)
if not exist POPSYN_HH.CSV (goto socec_data_error)
rem Delete old output files.
if exist *OUT.TXT (del *OUT.TXT)
if exist *OUTPUT.TXT (del *OUTPUT.TXT)
if exist MCHW_HH.TXT (del MCHW_HH.TXT)
TG_PopSyn.exe
cd ..\scripts
echo Creating summary files ...
python summarize_tg_results.py %project% %run%
python prepare_iom_inputs.py %project% %run%
echo.
cd ..\data
if not exist hoa.in (goto python_error)
if not exist hop.in (goto python_error)
if not exist hwahi.in (goto python_error)
if not exist hwalo.in (goto python_error)
if not exist hwphi.in (goto python_error)
if not exist hwplo.in (goto python_error)
if not exist nha.in (goto python_error)
if not exist nhp.in (goto python_error)
if not exist m01tg.txt (goto python_error)
if not exist m01auto.csv (goto m01_data_error)
if not exist m01type.csv (goto m01_data_error)
cd %~dp0
python tg\fortran\create_HHvtype_file.py
echo Module 1 finished.
echo.
echo ===================================================================
echo.
if "%choice%"=="3" (goto macros)
goto last
rem Import production and attraction files, then run distribution macros.
:two
echo ===================================================================
echo.
rem Set distribution factors before running.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo SET GROWTH FACTOR
echo.
echo Before continuing, please update the growth factor variable in
echo each of the following scripts:
echo * prep_macros\distribute.trucks
echo * prep_macros\distribute.poes
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pause
echo.
set /a val=%sc%
if %val% geq 100 (goto macros)
goto badscen
:macros
if exist tg.rpt (del tg.rpt)
if exist report\stop_truck_distribution.txt (
del report\stop_truck_distribution.txt
)
copy tg\fortran\TG_HHENUM_OUTPUT.TXT TG_HHENUM_OUTPUT.TXT /y
echo.
REM -- Get name of .emp file --
set infile=empfile.txt
cd ..
if exist %infile% (del %infile% /Q)
dir "*.emp" /b >> %infile% 2>nul
set /p file1=<%infile%
echo file1 = %file1%
call :CheckEmpty %infile%
:filepass
if exist %infile% (del %infile% /Q)
cd Database
rem Activate Emme Python env
call %~dp0..\Scripts\manage\env\activate_env.cmd emme
if %ERRORLEVEL% NEQ 0 (goto end)
echo Preparing emmebank for model run...
call python useful_macros\cleanup_for_rerun.py %val%>> tg.rpt
echo.
echo Importing production and attraction matrices (used only for b/l/m truck distribution)...
call emme -ng 000 -m prep_macros\import.tg.results 1 >> tg.rpt
echo.
echo Skimming highway network...
call python prep_macros\free.skim.mac.py %file1% %val%
echo.
echo Distributing trucks...
call emme -ng 000 -m prep_macros\truck.class.skim.mac %val% 1 1 >> tg.rpt
if exist report\stop_truck_distribution.txt (goto truck_balance_err)
echo.
echo Distributing POEs...
call emme -ng 000 -m prep_macros\distribute.poes 1 >> tg.rpt
echo.
cd %~dp0
echo Module 2 finished.
echo.
goto last
rem ------------------------------------------------------------
:socec_data_error
echo !!! MISSING SOCEC FILES !!!
echo Socioeconomic input files are missing from tg\fortran.
goto end
:m01_data_error
echo !!! MISSING DATA FILES !!!
echo M01 data files (m01auto.csv, m01type.csv) are missing from tg\data.
goto end
:python_error
echo !!! MISSING IOM FILES !!!
echo Review tg\scripts\prepare_iom_inputs.log for errors.
goto end
:badscen
echo !!! NO 3-DIGIT SCENARIO !!!
echo Please resubmit the program and supply a scenario number.
goto end
:urbansim_issue
echo !!! THE URBANSIM FILES DID NOT PROCESS PROPERLY !!!
goto end
:hcv_issue
echo !!! THE HEAVY COMMERCIAL VEHICLE ALLOCATION DID NOT PROCESS PROPERLY !!!
goto end
:wfh_issue
echo !!! THE WORK FROM HOME ALLOCATION MODEL DID NOT RUN PROPERLY !!!
goto end
:truck_balance_err
echo !!! TRUCK BALANCING PROCEDURES PRODUCED NaN ERRORS !!!
echo Please review report\truck.access.rpt, modify distribute.trucks and
echo resubmit trip_gen.bat
goto end
:CheckEmpty
if %~z1 == 0 (goto badfile)
goto filepass
:badfile
@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ECHO COULD NOT FIND .EMP FILE.
@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
goto end
:last
echo End of batch file.
@ECHO Trip Generation Model Start Time: %dt% %tm%
@ECHO Trip Generation Model End Time : %date% %time%
:end
echo.
pause
exit