-
Notifications
You must be signed in to change notification settings - Fork 0
RunModel batch file
The RunModel.bat file runs the full model by calling various model components using the Python, R, and Java dependencies. The RunModel batch file interfaces with Visum procedure sequences via the Visum's Python API. The batch file also implements the model feedback loops.
First, environment variables are set up using relative paths to the dependencies folder. MAX_ITER
defines the maximum number of model iterations, regardless of traffic assignment convergence.
:: Setup maximum number of iterations
SET MAX_ITER=3
:: -------------------------------------------------------------------------------------------------
:: Setup folders, IP addresses, file references, etc.
:: -------------------------------------------------------------------------------------------------
@ECHO OFF
:: get ip address of machine
SET PATH=C:\Windows\System32
FOR /f "delims=[] tokens=2" %%a IN ('ping -4 -n 1 %ComputerName% ^| findstr [') DO SET HOST_IP_ADDRESS=%%a
ECHO HOST_IP_ADDRESS: %HOST_IP_ADDRESS%
:: setup dependencies, which are one folder up so they can be shared across scenarios
SET JAVA_PATH=%~dp0..\dependencies\jdk1.8.0_111\bin\java.exe
ECHO JAVA_PATH: %JAVA_PATH%
SET PYTHON=%~dp0..\dependencies\Python37\python.exe
ECHO PYTHON: %PYTHON%
SET R_SCRIPT=%~dp0..\dependencies\R-3.4.1\bin\Rscript
ECHO R_SCRIPT: %R_SCRIPT%
SET R_LIBRARY=%~dp0..\dependencies\R-3.4.1\library
ECHO R_LIBRARY: %R_SCRIPT%
:: setup folders
SET PROJECT_DRIVE=%~d0
ECHO PROJECT_DRIVE: %PROJECT_DRIVE%
SET PROJECT_DIRECTORY=%~dp0
ECHO PROJECT_DIRECTORY: %PROJECT_DIRECTORY%
SET PROJECT_DIRECTORY_FORWARD=%PROJECT_DIRECTORY:\=/%
ECHO PROJECT_DIRECTORY_FORWARD: %PROJECT_DIRECTORY_FORWARD%
The RunModel.bat file calls either the the Model Runner (modelRunner.R) or Visum Runner (VISUM_Runner.py) scripts to execute a model step. Both the scripts have been designed to accept a token as an argument for which component to run. The Visum runner scripts runs a specific Visum-based modeling task while the Model Runner script launches a JEMnR or demand specific model step. The table below shows the list of entry point tokens and the modeling task it triggers.
Runner | Token | Component |
---|---|---|
VISUM_Runner.py | skims | Initial auto, transit, bike, and walk skims |
VISUM_Runner.py | assignment | Assign auto and transit demand and save congested skims |
modelRunner.R | jemnr | Run the model modules in JEMnR (University, CVM, household trip models, External model) |
modelRunner.R | buildmat | Build OMX demand matrices from JEMnR's RData matrices |
modelRunner.R | convergence | Check the last assignment for model convergence |
modelRunner.R | report | Run the JEMnR reporting script |
The initial auto, transit, bike, and walk skims are generated in Visum by passing the skims
argument to the Visum runner Python script:
:: -------------------------------------------------------------------------------------------------
:: Initial Skims
:: -------------------------------------------------------------------------------------------------
rem # All skims
%PYTHON% VISUM_Runner.py skims
IF %ERRORLEVEL% NEQ 0 GOTO MODEL_ERROR
The feedback loop allows the model to consider congested travel times from the previous iteration as an input to the demand models. This loop starts by running the full set of JEMnR models, the University model, commercial vehicle model, and external flows by passing the jemnr
argument to the modelRunner.R
script.
:: -------------------------------------------------------------------------------------------------
:: Loop
:: -------------------------------------------------------------------------------------------------
SET /A ITERATION=0
:ITER_START
SET /A ITERATION+=1
ECHO MODEL ITERATION %ITERATION%
rem # run JEMNR main module
%R_SCRIPT% modelRunner.R jemnr %ITERATION%
IF %ERRORLEVEL% NEQ 0 GOTO MODEL_ERROR
JEMnR stores its intermediate and final trip vectors and matrices in RData files. An R script converts the auto and transit zone-to-zone demand matrices from RData to OMX format by passing the buildmat
argument to the R model runner:
:: -------------------------------------------------------------------------------------------------
:: Build, load, and assign trip matrices into Visum
:: -------------------------------------------------------------------------------------------------
rem # write JEMNR demand to OMX
%R_SCRIPT% modelRunner.R buildmat %ITERATION%
IF %ERRORLEVEL% NEQ 0 GOTO MODEL_ERROR
Next, auto and transit demand is assigned in Visum by passing the assignment
argument to the Visum runner:
rem # assign JEMNR demand
%PYTHON% VISUM_Runner.py assignment
IF %ERRORLEVEL% NEQ 0 GOTO MODEL_ERROR
After each assignment run, zone-to-zone travel times are checked against previous runs for convergence:
rem # check convergence
IF %ITERATION% LSS %MAX_ITER% (
%R_SCRIPT% modelRunner.R convergence %ITERATION%
IF %ERRORLEVEL% EQU 10 GOTO REPORTING rem # converged
IF %ERRORLEVEL% NEQ 0 GOTO MODEL_ERROR rem # error
)
:: -------------------------------------------------------------------------------------------------
:: Loop again if needed
:: -------------------------------------------------------------------------------------------------
IF %ITERATION% LSS %MAX_ITER% GOTO ITER_START
The final step after either model convergence or the maximum number of iterations is reached is to run the reporting script for JEMnR demand. This script does not consider outputs from the University model. The output is an HTML report with aggregate household characteristics, trip length (distance or time) frequency plots, mode share graphs, and trip totals by mode, all compared to a previous full model run.
:: -------------------------------------------------------------------------------------------------
:: Reporting
:: -------------------------------------------------------------------------------------------------
:REPORTING
rem # run JEMNR demand model reporting
%R_SCRIPT% modelRunner.R report %ITERATION%
IF %ERRORLEVEL% NEQ 0 GOTO MODEL_ERROR
Any failed model step will pass an %ERRORLEVEL%
of 1 or greater, triggering a GOTO statement that ends the run and sends the "Model Failed" message to the command prompt window. Otherwise, when %ERRORLEVEL%
equals 0 the model continues to run and the loop continues until either condition is satisfied: (a) the difference in congested travel times between iterations converges or (b) the maximum number of iterations is reached.
:: -------------------------------------------------------------------------------------------------
:: All done
:: -------------------------------------------------------------------------------------------------
ECHO MODEL RUN COMPLETE
PAUSE
GOTO END
:MODEL_ERROR
ECHO Model Failed
PAUSE
:END