~?!i&32768 ~o=263 ~/*********************************************************************** ~/*** STOCHAS: EMME/2 MACRO FOR STOCHASTIC AUTO ASSIGNMENT (1.5) *** ~/*** (Copyright (C) 1993 - Heinz Spiess, Aegerten, Switzerland) *** ~/*********************************************************************** ~$>skipnotice !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I herewith grant the right to use this macro to all EMME/2 users, provided the following conditions are met: 1) The macro cannot be sold for a fee (but it can be used and distributed within consulting projects). 2) The user is aware that this macro is not a part of the EMME/2 software licence and there is no explicit or implied warranty or support provided with this macro. 3) This notice and the comments in this macros must not be removed. 4) Any additions or modification made by anyone else but me must be clearly identified as such, including date, name and the reason of the modification. Aegerten, February 26, 1993 Heinz Spiess !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ~:skipnotice ~t3=ul3 ~/*** ~/*** This EMME/2 macro implements a stochastic type auto assignment ~/*** based on averaging several separate equilibrium assignments, ~/*** each using a different set of random terms in the link costs. ~/*** ~/*** Requirements: ~/*** - Macro is started from main menu and needs EMME/2 Release 6.0. ~/*** - Link user data %t3% is used to contain the pseudo random term. ~/*** - All volume-delay functions that are subject to random perception ~/*** are coded in a form to incorporate %t3% as the random term. ~/*** - All volume dependencies in the volume-delay functions should ~/*** be coded using "(volau+volad)" in order to assure the correct ~/*** computation of link and turn times at the end of the macro. ~/*** - ms97-ms99 are reserved for the internal use of this macro ~/*** ms97: used for temporary storage ~/*** ms98: used for temporary storage ~/*** ms99: current seed for random number generator ~/*** - A temporary scenario with the number 90000+%s% is used for the ~/*** partial assignments. This scenario is created automatically ~/*** at the beginning and deleted at the end of the macro. ~/*** - Assignment reports are appended to the file stochas.rep ~/*** ~/*** References: ~/*** - "Generating Random Numbers in Network and Matrix Calculator", ~/*** EMME/2 News 9, April 1990 ~/*** - Abramowitz and Stegun, Handbook of Mathematical Functions (26.8.6) ~/*** ~/*** Calling sequence: ~/*** ~ ~/*** where ~/*** type of distribution for pseudo random term (%t3%) ~/*** 1=uniform[0-1] 4=uniform[0-1] (alternate form) ~/*** 2=normal(0,1) 5=normal(0,1) (alternate form) ~/*** 3=exponential(1) 6=exponential(1) (alternate form) ~/*** 7=Gumble(0.577,1.645) 8=Gumble(0.577,1.645)(alt. form) ~/*** number of partial assignments to be carried out ~/*** auto demand matrix ~/*** vehicle occupancy matrix (,=none) ~/*** no. of iteration assignment stopping criterion ~/*** relative gap assignment stopping criterion ~/*** normalized gap assignment stopping criterion ~/*** ~/*********************************************************************** ~x=%m% /test if started from main menu ~x+%q% ~?x>0 ~$stop ~x=%0% ~?x=0 ~$stop ~y=3 /test if enough parameters are provided ~?x<4 ~$error ~z=%1% ~% ~y=1 /test if scenario number is 4 digits or less ~?s>9999 ~$error ~y=2 /test if type of distribution is vald ~?z<1 ~$error ~?z>8 ~$error ~y=%s% ~y+90000 s=%y% / test if scenario %y% exists already ~?e ~$start ~y-90000 s=%y% ~y=4 ~$error ~:start c='START stochas %z% %1% %2% %3% %4% %5% %6%' ~p=2005 ~t1=%p% ~/================ STOCHAS: STOCHASTIC AUTO ASSIGNMENT ================== ~/Date: %d% ~/Scenario: %s% ~/No. of assignments: %1% ~/Auto demand: %2% ~/Vehicle occupancy: %3% ~/Max. iterations: %4% ~/Max. rel. gap: %5% min ~/Max. norm. gap: %6% min ~?z= 1 ~/Random distribution 1: Uniform [0,1] (pseudo random generator 1) ~?z=2 ~/Random distribution 2: Normal(0,1) (pseudo random generator 1) ~?z=3 ~/Random distribution 3: Exponential(1) (pseudo random generator 1) ~?z=4 ~/Random distribution 4: Uniform [0,1] (pseudo random generator 2) ~?z=5 ~/Random distribution 5: Normal(0,1) (pseudo random generator 2) ~?z=6 ~/Random distribution 6: Exponential(1) (pseudo random generator 2) ~?z=7 ~/Random distribution 7: Gumble(0.577,1.645) (pseudo random generator 1) ~?z=8 ~/Random distribution 8: Gumble(0.577,1.645) (pseudo random generator 2) ~/----------------------------------------------------------------------- reports=stochas.rep ~x=1 ~:nextstep ~?x>1 ~+|~p=2005|~y=%%%p%%%|~y-%t1%|~y/10|~/..... total CPU seconds: %%%y%%% ~/Assignment step %x%: 2.41 /##### update random seed in ms99 and compute new random term %t3% 1 n put((int(ms(99))*1366+1283).mod.6075) all 5 3 99 rseed random seed r ~/..... compute new random term into %t3% (seed=%ms99%) 1 y %t3% ~?z=1 / uniform(0,1) (see Abramowitz and Stegun 26.8.) (put(int(get(1)*430+2531).mod.11979)+.5)/11979 ~?z=2 / normal(0,1) (see Abramowitz+Stegun 26.8.6) sqrt(-2*ln(((int(get(1)*430+2531).mod.11979)+.5)/11979))*cos(6.28318531 ~?z=2 *(put(int((int(get(1)*430+2531).mod.11979)*430+2531).mod.11979)+.5)/11979) ~?z=3 / exponential(1) (see Abramowitz+Stegun 26.8.6) 0-ln((put(int(get(1)*430+2531).mod.11979)+.5)/11979) ~?z=4 / uniform(0,1) alternate form (put(int(get(1)*936+1399).mod.6655)+.5)/6655 ~?z=5 / normal(0,1) alternate form sqrt(-2*ln(((int(get(1)*936+1399).mod.6655)+.5)/6655))*cos(6.28318531 ~?z=5 *(put(int((int(get(1)*936+1399).mod.6655)*936+1399).mod.6655)+.5)/6655) ~?z=6 / exponential(1) alternate form 0-ln((put(int(get(1)*936+1399).mod.6655)+.5)/6655) ~?z=7 / Gumble(0.577,1.645) (see Abramowitz+Stegun 26.8.6) 0-ln(0-ln((put(int(get(1)*430+2531).mod.11979)+.5)/11979)) ~?z=8 / Gumble(0.577,1.645) alternate form 0-ln(0-ln((put(int(get(1)*936+1399).mod.6655)+.5)/6655)) all 5 5 97 averag Average of random terms at step %x% r 1 n put(%t3%-ms(97))*get(1) all 5 5 98 var variance of random terms at step %x% q ~/ (avg=%ms97% var=%ms98%) ~/..... prepare assignment 5.11 /##### prepare auto assignment to compute auto volumes ################### 1 / fixed demand auto assignment ~?q=2 2 / new assignment ~?q>2 1 / single class assignment 1 / no additional volumes %2% / demand %3% / no auto occupancy matrix / no addl demand / no auto times saved ~?q=1 / initialize auto volumes only in step 1 ~+|~?x>1|y|~?x=1|n %4% / max iterations %5% / % gap %6% / time diff. ~/..... perform assignment 5.21 /##### perform auto assignment to compute auto volumes ################### ~?q=2 2 ~?x>1 ~$>combine 1.22 /##### create a temporary copy of scenario 3 ~?e ~+|q|~/No space available for creating temporary scenario %y%!|~$>stop %s% ~y=%s% ~y+90000 %y% ~?e ~+|q|~/Cannot create temporary scenario %y%!|~$>stop temp. scen. for stochastic auto assignment y q ~x+1 ~$nextstep ~:combine 3.21 1 /compute weight of step i y ms97 y w%x% weight step %x% ~?q=1 y 0 1./%x% ~?q=2 1 c 1 /compute complement weight y ms98 y cw%x% complement weight step %x% ~?q=1 y 0 1.-ms97 ~?q=2 1 c q ~/..... combine new and current assignment 1.11 ~y=%s% ~y-90000 4 ~+|3| 18,-%s%| 18,-%y%| %ms97%,%ms98%,0 ~+|3| 20,-%s%| 20,-%y%| %ms97%,%ms98%,0 ~+|3| 43,-%s%| 43,-%y%| %ms97%,%ms98%,0 ~+|3| 44,-%s%| 44,-%y%| %ms97%,%ms98%,0 q ~x+1 ~?!x>%1% ~$nextstep ~+|~p=2005|~y=%%%p%%%|~y-%t1%|~y/10|~/..... total CPU seconds: %%%y%%% ~/Finishing Up: ~/..... reset random term to 0 2.41 1 y %t3% 0 all 5 q 3.21 1 /compute null demand y ms97 y zero zero ~?q=1 y 0 0. ~?q=2 1 c q ~/..... prepare dummy assignment to compute correct link and turn times 5.11 /##### prepare auto assignment to compute auto volumes ################### 1 / fixed demand auto assignment ~?q=2 2 / new assignment ~?q>2 1 / single class assignment 1 / no additional volumes ms97 / demand (null) / no auto occupancy matrix / no addl demand / no auto times saved ~?q=1 y / initialize auto volumes 0 / max iterations -1 / % gap 0 / time diff. ~/..... copy result link and turn volumes into additional volumes 1.11 /##### copy result link and turn volumes into addl volumes ~y=%s% ~y-90000 4 ~+|3| 18,-%y%| 20,-%s%| 1,1,0 ~+|3| 44,-%y%| 43,-%s%| 1,1,0 q ~/..... perform dummy assignment to obtain correct link and turn times 5.21 /##### perform auto assignment to compute auto volumes ################### ~?q=2 2 ~/..... copy link and turn times into main scenario 1.11 /##### copy link and turn times into main scenario ~y=%s% ~y-90000 4 ~+|3| 17,-%s%| 17,-%y%| 1,0,0 ~+|3| 45,-%s%| 45,-%y%| 1,0,0 q ~y=%s% ~y-90000 ~/..... delete temporary scenario %s% 1.22 /##### delete temporary scenario 2 %s% y q reports=^ s=%y% c='END stochas %z% %1% %2% %3% %4% %5% %6%' ~+|~p=2005|~y=%%%p%%%|~y-%t1%|~y/10|~/..... total CPU seconds: %%%y%%% ~/======================================================================= ~$stop ~:error ~/ ~?y=1 ~/Scenario number must not exceed 9999! ~?y=2 ~/Invalid distribution function type! ~?y=3 ~/Invalid number of macro parameters! ~x=%s% ~x+90000 ~?y=4 ~/Scenario %x% exists already! ~:stop ~o=6