; Script for program HIGHWAY in file "D:\JOB\D3\MODEL\NEW\APPLICATIONS\TDHWY00A.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=HIGHWAY PRNFILE="D:\JOB\D3\MODEL\NEW\BASE\OUTPUT\TDHWY00A.PRN" MSG='Preassignment'
FILEO NETO = "{Scenario_Dir}\OUTPUT\PREASSIGN_A07.NET"
FILEI TURNPENI = "{Scenario_Dir}\Input\TURN_07A.PEN"
FILEI NETI = "{Scenario_Dir}\OUTPUT\UNLOADED_{ALT}{Year}.NET"
FILEI MATI[1] = "{Scenario_Dir}\OUTPUT\VEHTRIPS_PREASSIGN.MAT"

PAR ZONEMSG=100 MAXITERS={AssignIters}
ZONES={ZONESA}
LOOKUP,
INTERPOLATE=Y,LIST=Y,NAME=DECEL,
LOOKUP[1]=1,RESULT=2,
R='30 4',
  '70 6.2'


PROCESS PHASE=LINKREAD
; Use this phase to obtain initial values from the input network (LI.varname) and compute 
; link values (LW.varname) that can be used in other 
  T0=li.TIME
  LW.FFTIME=LI.TIME ; USE FOR PRELOAD PURPOSES (FFTIME)
  C=LI.CAPACITY*LI.NUM_LANES*LI.UROADFACTOR/LI.CONFAC

  IF (LI.{PATHGROUP}) ADDTOGROUP=7 
      LINKCLASS=1 ; no toll
      if (li.tolltype=1) 
       LINKCLASS=2 ; with toll
       T0=({CTOLL}*LI.CARTOLL)*60 + LI.SVCMINUTES + LI.SVCSECONDS/60
       if (iteration=0)
          LW.ARRIVR=(V/LI.UROADFACTOR)*LI.CONFAC/LI.PLZALNSMAX  ; hourly volume per toll lane ie. arrival rate in vehicles per hour
        LW.SERVT=LI.SVCMINUTES+(LI.SVCSECONDS/60)           ; Plaza lane service time in minutes per vehicle
        LW.SERVR=(1/LW.SERVT)*60                            ; Plaza lane service rate in vehicle per hour
        PRINT LIST='ARRIVR= ',LW.ARRIVR
        PRINT LIST='SERVT= ',LW.SERVT
        PRINT LIST='SERVR= ',LW.SERVR
        if (LW.ARRIVR>=LW.SERVR) LW.ARRIVR=0.99*LW.SERVR    ; prevent infinite or negative queue 
       endif
      endif
; classify links based on presence/absence of Open Road Toll
      if (li.tolltype=2) 
       LINKCLASS=3 ; with ORT
       T0=({CTOLL}*LI.CARTOLL)*60
       endif
       if (li.TOLL_ACC>0) 
       LINKCLASS=4 ; Toll Plaza Acceleration link
       T0= T0 + (LI.SPEED/2.5)/60
      endif
      if (li.TOLL_DEC>0) 
       LINKCLASS=5 ; Toll Plaza Deceleration link
       T0 = T0 + (LI.SPEED/DECEL(1,LI.SPEED))/60
      endif
ENDPROCESS

PROCESS PHASE=ILOOP
; This phase performs a zonal loop (I=1,Zones).  This phase is required and must contain
; at least 1 PATHLOAD statement.  Almost all MATRIX operation are available in this phase
; and the PATHLOAD statement can be used to build and load paths for assignment
PATHLOAD PATH=TIME, PENI=1, VOL[1]=MI.1.1
IF (I=ZONES)
  LINKLOOP
    LW.PREVTIME=TIME
  ENDLINKLOOP
ENDIF


ENDPROCESS


PROCESS PHASE=ADJUST
; This phase is automatically run after the ILOOP phase.  The volume-delay functions (TC) are
; automatically recomputed in this phase to update the link congested travel times based 
; on the volumes from the ILOOP phase.  User defined link computations (LW.varname) that 
; need to be updated based on the new congested travel times should be coded in this phase.
IF(TIME>0) LW.CGSTSPEED=(LW.DISTANCE/TIME)*60
IF(LI.TOLLTYPE=1)
 LW.ARRIVR=(V/LI.UROADFACTOR)*LI.CONFAC/LI.PLZALNSMAX  ; hourly volume per toll lane ie. arrival rate in vehicles per hour
 LW.SERVT=LI.SVCMINUTES+(LI.SVCSECONDS/60)           ; Plaza lane service time in minutes per vehicle
 LW.SERVR=(1/LW.SERVT)*60                            ; Plaza lane service rate in vehicle per hour
IF(LW.ARRIVR>=LW.SERVR) LW.ARRIVR=0.99*LW.SERVR; prevent infinite or negative queue 
;PRINT LIST='ARRIVR= ',LW.ARRIVR
;PRINT LIST='SERVT= ',LW.SERVT
;PRINT LIST='SERVR= ',LW.SERVR
;PRINT LIST='TOLLTIME= ',TIME
ENDIF

;FUNCTION TC[1]={DAMPINGFACTOR}*LW.PREVTIME+(1.0-{DAMPINGFACTOR}*LI.TIME*(1+LI.BPRCOEFFICIENT*MIN(V/C),{VCMAX}*LI.BPREXPONENT);Congested time for non-toll links
 FUNCTION TC[1]={DAMPINGFACTOR}*LW.PREVTIME+(1.0-{DAMPINGFACTOR})*LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT)
FUNCTION TC[2]=MIN((1/(LW.SERVR-LW.ARRIVR))*60,20)+{CTOLL}*LI.CARTOLL*60;CONGESTED TIME FOR TOLL LINKS
FUNCTION TC[3]={CTOLL}*LI.CARTOLL*60;CONGESTED TIME FOR ORT TOLL LINKS
;FUNCTION TC[4]=LI.TIME*(1+LI.BPRCOEFFICIENT*MIN(V/C),{VCMAX})^LI.BPREXPONENT)+(LW.CGSPEED/2.5)/60;CONGESTED TIME TOLL ACCELERATION LINKS
 FUNCTION TC[4]=LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT) + (LW.CGSTSPEED/2.5)/60
FUNCTION TC[5]=LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT)+(LW.CGSTSPEED/DECEL(1,LW.CGSTSPEED))/60; congested time toll deceleration links
;if (li.cartoll>0) print list="Iter:",iteration(2.0)," TOLLFM Summary, A=",A(6.0)," B=",B(6.0)," PLAZAID=",li.TOLL(3.0)," NAME=",li.PLAZADESC(24)," MAX LNS=",li.PLZALNSMAX," GCOST=",TIME(6.2),
 ;       printo=1
ENDPROCESS

ENDRUN


