~+;~o|32;~?!i&32768;~o|7 / run in silent mode if switch 15 is off ~/*** *** ~/*** CAPTRAS: TRANSIT ASSIGNMENT WITH CAPACITY CONSIDERATIONS (1.6) *** ~/*** Copyright (C) INRO Consultants Inc., Montreal, Canada 2003-11 *** ~/*** Macro written by Shuguang He and Michael Florian *** ~/*** Modified by Yolanda Noriega, November 2010 *** ~/** ** ~/** The macro CAPTRAS performs an equilibrium transit assignment ** ~/** by considering the increased waiting times at stops due to ** ~/** transit vehicle capacities and in-vehicle congestion functions. ** ~/** The theoretical basis of this algorithm is described in the ** ~/** paper entitled "A transit model with strict capacity cons- ** ~/** traints: characterization and computation of equlibria" by ** ~/** M.Cepeda, R. Cominetti and M.Florian (2003). It uses the ** ~/** method of successive averages (MSA) to minimze a gap function ** ~/** which has the property that each of its global minima is a ** ~/** transit equilibrium. ** ~/** ** ~x=%0% ~?x>0 ~$>end_of_comments ~/** Calling sequence: ** ~/** ~ [modes] ** ~/** [btim] [ww] [aw] [bw] [beta] [hours] ** ~/** e.g. ~ type (two digits) of congestion function to be used ** ~/** first digit - for segment congestion function ** ~/** = 0, no segment congestion function ** ~/** = 1, BPR function with given ms85, ms86 ** ~/** = 2, Conical function with given ms85, ms86 ** ~/** second digit - for headway congestion function ** ~/** = 0, no headway congestion function ** ~/** = 1, use effective headway function ** ~/** max. no. of MSA iterations (stopping criteria) ** ~/** max. relative volume dif. % (stopping criteria) ** ~/** max. over capacity ratio % (stopping criteria) ** ~/** transit demand matrix ** ~/** Optional: ** ~/** [modes] active modes (default=all modes) ** ~/** [btim] boarding time (default=2.5) ** ~/** [ww] waiting time weight (default=2.0) ** ~/** [aw] auxiliary time weight (default=2.0) ** ~/** [bw] boarding time weight (default=2.0) ** ~/** [beta] power of headway adjustment function (default=0.02) ** ~/** [hours] hour factor for the capacity (default=1) ** ~/** ** ~/** Requirements: ** ~/** - All transit time functions must be coded in the form ** ~/** ()*(1+us1) ** ~/** - us1, ms80-ms99 are reserved for this macro ** ~/** us1: congestion penalty for segment ** ~/** ms80: is used temporally for copy data using m=1.11 ** ~/** ms81-ms83: are used for recording the segment with max. v/c ** ~/** ms84: is used for recording the segment capacity ** ~/** ms85 and ms86: contain the weight and exponent of the ** ~/** congestion term on segments (must be set by the user) ** ~/** ms91: iteration counter ** ~/** ms93: current excess segment volume percentage ** ~/** ms94: current relative volume difference ** ~/** ms95: total excess segment volume ** ~/** ms96: total excess passenger-distances ** ~/** ms97: number of segment over capacity ** ~/** ms98: max. volume/capacity ratio of segment ** ~/** ms99: min. volume/capacity ratio of segment ** ~/** ** ~/** Results: ** ~/** inboa -- initial boardings at node i (N) ** ~/** fiali -- final alightings at node i (N) ** ~/** volax -- aux. transit volume on link (L) ** ~/** voltr -- transit segment volume (S) ** ~/** board -- transit boardings (S) ** ~/** timtr -- transit travel time on segment(S) ** ~/** @phwdy -- perceived transit headway (S) ** ~/** @timtr -- congested transit travel time on segment(S) ** ~/** @aligh -- transit alightings (S) ** ~/** captras_cvg.rep -- convergence report ** ~/** mf"Upq" -- congested transit impedance matrix ** ~/*************************************************************************** ~$>STOP ~:end_of_comments ~# ###Input parameters validation ~?!m=000 ~+;~/ERROR: Macro must be started from the main menu!;~$>STOP ~?x<5 ~+;~/ERROR: At least five arguments required!;~$>STOP ~# Validation of the congestion function ~t1=%1% ~t2=%t1.1% ~+;~?t2=0;~$>Second-Dig;~?t2=1;~$>Second-Dig;~?t2=2;~$>Second-Dig ~+;~/ERROR: Segment congestion function is not correct!;~$>STOP ~:Second-Dig ~t2=%t1.-1% ~+;~?t2=0;~$>Function-ok;~?t2=1;~$>Function-ok ~+;~/ERROR: Headway congestion function is not correct!;~$>STOP ~:Function-ok ~# Matrices verification (ms85, ms86 and demand) 3.12 ~t2=%t1.1% ~?t2=0 ~$>Cong-terms-ok ~+;3;ms85 ~?q=1 ~+;q;~/ERROR: Weight of the congestion term (ms85) not defined!;~$>STOP ~+;r;3;ms86 ~?q=1 ~+;q;~/ERROR: Exponent of the congestion term (ms86) not defined!;~$>STOP r ~:Cong-terms-ok ~+;3;%5% ~?q=1 ~+;q;~/ERROR: Demand matrix missing!;~$>STOP q ~x=%2% ~?x<0 ~+;~/ERROR: Max. no. of MSA iterations must be >= 0!;~$>STOP ~x=%3% ~?x<0 ~+;~/ERROR: Max. relative volume dif. must be >= 0!;~$>STOP ~x=%4% ~?x<0 ~+;~/ERROR: Max. over capacity ratio must be >= 0!;~$>STOP ~# Active modes ~t4=%6% ~+;~?t4=;~t4=*;~?t4=all;~t4=*;~?t4=All;~t4=*;~?t4=ALL;~t4=* ~# Boarding time ~t5=%7% ~+;~?t5=;~t5=2.5 ~r5=%t5% ~?r5<0 ~+;~/ERROR: Boarding time must be >= 0!;~$>STOP ~?r5>999.99 ~+;~/ERROR: Boarding time must be <= 999.99!;~$>STOP ~# Waiting time weight ~t6=%8% ~+;~?t6=;~t6=2.0 ~r6=%t6% ~?r6<0 ~+;~/ERROR: Waiting time weight must be >= 0!;~$>STOP ~?r6>999.99 ~+;~/ERROR: Waiting time weight must be <= 999.99!;~$>STOP ~# Auxiliary time weight ~t7=%9% ~+;~?t7=;~t7=2.0 ~r7=%t7% ~?r7<0 ~+;~/ERROR: Auxiliary time weight must be >= 0!;~$>STOP ~?r7>999.99 ~+;~/ERROR: Auxiliary time weight must be <= 999.99!;~$>STOP ~# Boarding time weight ~t8=%10% ~+;~?t8=;~t8=2.0 ~r8=%t8% ~?r8<0 ~+;~/ERROR: Boarding time weight must be >= 0!;~$>STOP ~?r8>999.99 ~+;~/ERROR: Boarding time weight must be <= 999.99!;~$>STOP ~# Beta ~+;~r101=0.020;~t2=%11% ~+;~?!t2=;~r101=%t2% ~?r101<0 ~+;~/ERROR: Beta must be >= 0!;~$>STOP ~?r101>1.0 ~+;~/ERROR: Beta must be <= 1.0!;~$>STOP ~# Hours ~+;~r100=1;~t2=%12% ~+;~?!t2=;~r100=%t2% ~?!r100>0 ~+;~/ERROR: Hours factor must be > 0!;~$>STOP c='Start captras %t0%' ~# ### The convergence report ~p=2004 ~?p=1 (Unix) ~+;~!rm captras.rep;~!rm captras_cvg.rep ~?p=2 ~+;~!del captras.rep;~!del captras_cvg.rep reports=captras.rep ~x=%t1.1% ~y=%t1.-1% ~# Get hours, minutes and seconds of current time ~+;~p=2009;~r3=%%%p%%%;~p=2010;~r4=%%%p%%%;~p=2011;~r9=%%%p%%% ~# Print to the report ~>>captras_cvg.rep ~/=============== TRANSIT ASSIGNMENT WITH CAPACITY CONSIDERATIONS ========= ~/Date: %d% ~/Initial time: %r3%h%r4%m%r9%s ~/Scenario: %s% ~/Max. iterations: %2% ~/Max. relative difference: %3% ~/Max. over capacity ratio: %4% ~/Transit demand: %5% ~/Active modes: %t4% ~?x=0 ~/Segment function type: Not used ~?x=1 ~/Segment function type: BPR ~?x=2 ~/Segment function type: Conical ~?!x=0 ~/Congestion weight: ms85=%ms85% ~?!x=0 ~/Congestion exponent: ms86=%ms86% ~?y=0 ~/Headway function: Not used ~?y=1 ~/Headway function: Used ~?y=1 ~/Beta: %r101% ~>> ~# ### Initialization ~# Matrices initialization ~+;3.12;3;mf"Upq" ~?e ~+;;q;~/ERROR: No space for transit impedances matrix!;~$>STOP ~?q=1 /matrix not initialized ~+;y;transit impedances (MSA);0 ~+;r;3;mf"UpqLT" ~?e ~+;;q;~/ERROR: No space for last it. impedances matrix!;~$>STOP ~?q=1 /matrix not initialized ~+;y;transit impedances of the last iteration;0 q 3.21 ~+;1;y;ms80;y;aux;auxiliary for copy data with m=1.11;~?q=1;y;0;0;;;2 ~+;1;y;ms81;y;line;line of max. v/c;~?q=1;y;0;0;;;2 ~+;1;y;ms82;y;i-node;segment i-node with max. v/c;~?q=1;y;0;0;;;2 ~+;1;y;ms83;y;j-node;segment j-nod with max. v/c;~?q=1;y;0;0;;;2 ~+;1;y;ms84;y;totCAP;total segment capacity in %r100% hour(s);~?q=1;y;0;0;;;2 ~+;1;y;ms91;y;curit;current number of iterations;~?q=1;y;0;0;;;2 ~+;1;y;ms93;y;curEVD;current excess segment volume percentage;~?q=1;y;0;999;;;2 ~+;1;y;ms94;y;curDIF;current relative volume difference;~?q=1;y;0;0;;;2 ~+;1;y;ms95;y;totESV;total excess segment volume;~?q=1;y;0;0;;;2 ~+;1;y;ms96;y;totEPD;total excess passenger distance;~?q=1;y;0;0;;;2 ~+;1;y;ms97;y;totSN;total number of over capacity segments;~?q=1;y;0;0;;;2 ~+;1;y;ms98;y;maxVC;max. V/C ratio of segments;~?q=1;y;0;0;;;2 ~+;1;y;ms99;y;minVC;min. V/C ratio of segments;~?q=1;y;0;0;;;2 q ~# Initialize the extra attributes 2.42 ~+;2;1 ~?e ~+;q;~/ERROR: No space for extra node attribute @inboa!;~$>STOP ~+;@inboa;~?e ~+; ;3;@inboa;y;2;1;@inboa ~+;MSA initial boardings at node i; ~+;2;1 ~?e ~+;q;~/ERROR: No space for extra node attribute @fiali!;~$>STOP ~+;@fiali;~?e ~+; ;3;@fiali;y;2;1;@fiali ~+;MSA final alightings at node i; ~+;2;1 ~?e ~+;q;~/ERROR: No space for extra node attribute @ui1tp!;~$>STOP ~+;@ui1tp;~?e ~+; ;3;@ui1tp;y;2;1;@ui1tp ~+;Temporary storage for ui1; ~+;2;2 ~?e ~+;q;~/ERROR: No space for extra link attribute @volax!;~$>STOP ~+;@volax;~?e ~+; ;3;@volax;y;2;2;@volax ~+;MSA aux. transit volume on link; ~+;2;2 ~?e ~+;q;~/ERROR: No space for extra link attribute @ul1tp!;~$>STOP ~+;@ul1tp;~?e ~+; ;3;@ul1tp;y;2;2;@ul1tp ~+;Temporary storage for ul1; ~+;2;4 ~?e ~+;q;~/ERROR: No space for extra segment attribute @timtr!;~$>STOP ~+;@timtr;~?e ~+; ;3;@timtr;y;2;4;@timtr ~+;Congested transit segment travel time; ~+;2;4 ~?e ~+;q;~/ERROR: No space for extra segment attribute @voltr!;~$>STOP ~+;@voltr;~?e ~+; ;3;@voltr;y;2;4;@voltr ~+;MSA transit segment volume; ~+;2;4 ~?e ~+;q;~/ERROR: No space for extra segment attribute @board!;~$>STOP ~+;@board;~?e ~+; ;3;@board;y;2;4;@board ~+;MSA transit boardings; ~+;2;4 ~?e ~+;q;~/ERROR: No space for extra segment attribute @lsvtr!;~$>STOP ~+;@lsvtr;~?e ~+; ;3;@lsvtr;y;2;4;@lsvtr ~+;Last MSA transit segment volume; ~+;2;4 ~?e ~+;q;~/ERROR: No space for extra segment attribute @aligh!;~$>STOP ~+;@aligh;~?e ~+; ;3;@aligh;y;2;4;@aligh ~+;Transit alightings; ~+;2;4 ~?e ~+;q;~/ERROR: No space for extra segment attribute @phdwy!;~$>STOP ~+;@phdwy;~?e ~+; ;3;@phdwy;y;2;4;@phdwy ~+;Perceived line headway on segments; ~+;2;4 ~?e ~+;q;~/ERROR: No space for extra segment attribute @time!;~$>STOP ~+;@time;~?e ~+; ;3;@time;y;2;4;@time ~+;Uncongestion transit travel time; ~+;2;4 ~?e ~+;q;~/ERROR: No space for extra segment attribute @vcapt!;~$>STOP ~+;@vcapt;~?e ~+; ;3;@vcapt;y;2;4;@vcapt ~+;Segment capacity in %r100% hour(s); q ~# Initialize congested segment travel time us1 to 0 and extra attributes ~p=2005 ~t3=%p% 2.41 ~+;1;y;us1;0;;*;*;4 ~+;1;y;@phdwy;n;hdwy;;*;*;4 ~+;1;y;@vcapt;n;60*vcapt/hdwy*%r100%;;*;*;4 ~+;1;n;@vcapt;;~?t4=*;*;~?!t4=*;mod=%t4% ~?e ~+;;;q;~/ERROR: Invalid selected modes! ;~$>STOP ~+;~?!t4=*;;*;5 ~+;4;ms84;;;1 ~r13=%ms84% ~+;1;n;(@vcapt.gt.0) ~+;;~?t4=*;*;~?!t4=*;mod=%t4%;~?!t4=*;;* ~+;5;4;ms97;totSN;total number of segments;1 ~r10=%ms97% q ~?r13=0.0 ~+;~/ERROR: Total segment capacity must be > 0.0!;~$>STOP ~# ### Main ~:LOOP ~# Preparing transit assignment 5.11 2 / transit assignment ~?q=2 2 %5% / demand matrix mf"UpqLT" / transit impedances n / no in-vehicle time matrix / no auxiliary time matrix / no waiting time matrix / no first waiting time matrix / no boarding time matrix / no number of boardings matrix '%t4%' / active modes 4 / line specific headway on segment @phdwy / perceived segment headway 1 / same boarding times %r5% / minutes boarding time 1 / same wait time factor 0.5 / wait time factor %r6% / wait time weight %r7% / aux time weight %r8% / boarding time weight ~?q=1 n / no additional options ~# Performing transit assignment 5.31 2 / report to printer ~# Save uncongestion time at iteration 0 ~z=%ms91% ~?z=0 ~+;2.41;1;y;@time;n;timtr;;*;*;4;q ~# Current MSA step size: 1/(iter+1) ~z+1 ~# Update the transit results 2.41 ~+;1;y;@fiali;n;@fiali+(fialii-@fiali)/%z%;;*;4 ~+;1;y;@inboa;n;@inboa+(inboai-@inboa)/%z%;;*;4 ~+;1;y;@volax;n;@volax+(volax-@volax)/%z%;;*;4 ~+;1;y;@lsvtr;n;@voltr;;*;*;4 ~+;1;y;@voltr;n;@voltr+(voltr-@voltr)/%z%;;*;*;4 ~+;1;y;@board;n;@board+(board-@board)/%z%;;*;*;4 q ~+;3.21;1;y;mf"Upq";n;mf"Upq"+(mf"UpqLT"-mf"Upq")/%z%;;;n;2;q ~# ### Convergence measures ~# Compute current excess segment volume percentage ~+;2.41;1;n;(@voltr-@vcapt)*((@voltr-@vcapt) .gt. 0) ~+;;*;*;5;4;ms95;;;1;q ~+;3.21;1;y;ms93;n;ms95/ms84*100;;;2;q ~# Compute relative volume difference % ~+;2.41;1;n;abs(@voltr-@lsvtr) ~+;;*;*;5;4;ms94;;;1 ~r11=%ms94% ~+;1;n;@voltr ~+;;*;*;5;4;ms94;;;1;q ~r13=%ms94% ~?r13=0.0 ~+;~/ERROR: Total transit volume must be > 0.0!;~$>STOP ~+;3.21;1;y;ms94;n;%r11%/ms94*100;;;2;q 2.41 ~# Compute the transit alighting at the beginning node of each segment ~+;1;y;@alighn;n (@voltr+@boardn-@voltrn)*((@voltr+@boardn-@voltrn) .gt.0) ~+;;~?t4=*;*;~?!t4=*;mod=%t4%;~?!t4=*;;*;4 ~# Compute the congested transit travel time ~+;1;y;@timtr;n;timtr;;*;*;4 ~# Compute the volume/capacity ratios ~+;1;n;@voltr/@vcapt ~+;;~?t4=*;*;~?!t4=*;mod=%t4%;~?!t4=*;;* ~+;5;3;ms98;; ~+;ms81;; ~+;ms82;; ~+;ms83;; ~+;2;ms99;;;;;;1 ~# Compute the total number of over capacity segments ~+;1;n;((@voltr-@vcapt).gt.0) ~+;;*;*;5;4;ms97;totSN;total number of over capacity segments;1 ~r11=%ms97% ~r11/%r10% ~r11*100 ~# Compute the aux. transit volume - distances ~+;1;n;@volax*length ~+;;*;5;4;ms96;totAVD;total aux. transit volume-distances;1 ~r12=%ms96% ~# Compute the total excess transit volume - distances ~+;1;n;((@voltr-@vcapt).gt.0)*(@voltr-@vcapt)*length ~+;;*;*;5;4;ms96;totEPD;total excess passenger distance;1;q ~x=%ms91% ~# Step size ~r1=1 ~r1/%z% ~p=2005 ~z=%p% ~z-%t3% ~z/10 ~t3=%p% ~# ### Print results to the report ~>>captras_cvg.rep ~/============================= Iteration %ms91% ========================== ~/Relative volume difference: %ms94.4%% ~/Excess transit volume-distance: %ms96.2% ~/Total aux. transit volume-distance: %r12.2% ~/Excess segment volume: %ms93.4%% ~/MSA step size: %r1.4% ~/No. of seg. over capacity: %ms97%, %r11.4%% ~/Min. seg. volume/capacity ratio: %ms99.4% ~/Max. seg. volume/capacity ratio: %ms98.4% (line: %ms81%, seg: %ms82%-%ms83%) ~/CPU Time: %z% sec ~>> ~# ### Convergence tests ~r1=%ms94% ~r2=%3% ~?r1<%r2% ~+;~>>captras_cvg.rep;~/============== Stopped by convergence criteria (%3%) ===============;~>>;~$>Done ~r2=%4% ~?r11<%r2% ~+;~>>captras_cvg.rep;~/============== Stopped by over capacity criteria (%4%) =============;~>>;~$>Done ~x=%ms91% ~y=%2% ~?!x<%y% ~+;~>>captras_cvg.rep;~/================== Stopped by max. iterations (%2%) ================;~>>;~$>Done ~# Increase iteration number by 1 ~+;3.21;1;y;ms91;n;ms91+1;;;2;q ~# ### Update of the segment and headway functions ~# The segment function ~t2=%t1.1% ~?t2=0 ~$>Segment-Function-Done ~+;2.41;1;y;us1 ~?t2=1 %ms85%*(@voltr/@vcapt)^%ms86% ~?t2=2 %ms85%*(sqrt(put(%ms86%*(1-@voltr/@vcapt))*get(1)+ ~?t2=2 put((%ms86%-0.5)/(%ms86%-1))*get(2))+1-get(1)-get(2)) ~+;;~?t4=*;*;~?!t4=*;mod=%t4%;~?!t4=*;;*;5;q ~:Segment-Function-Done ~# The headway function ~t2=%t1.-1% ~?t2=0 ~$>Headway-Function-Done ~+;2.41;1;y;@phdwy;n;(@voltr.lt.@vcapt)*(hdwy/ (1-(@board/(@vcapt-@voltr+@board))^%r101%) .min. 999.98)+(@voltr.ge.@vcapt)*999.98 ~+;;~?t4=*;*;~?!t4=*;mod=%t4%;~?!t4=*;;*;4;q ~:Headway-Function-Done ~# More iterations ~$LOOP ~:Done ~# ### Copy results using m=1.11 ~# Store temporarily values of ui1 and ul1 2.41 ~+;1;y;@ui1tp;n;ui1;;*;4 ~+;1;y;@ul1tp;n;ul1;;*;4 q ~# Find the internal number of the current scenario, and save it in x ~+;1.11;4;1;1,1,35,35;61,1,80,80;y;r ~x=%ms80% ~# Find the max. number of the scenarios, and save in y ~+;4;1;1,1,51,51;61,1,80,80;y;q ~y=%ms80% ~y+%x% ~# Copy @inboa into inboai ~+;2.41;1;y;ui1;@inboa;;*;4;q ~+;1.11;4;1;8,%x%;10,%x%;q ~# Copy @fiali into fialii ~+;2.41;1;y;ui1;@fiali;;*;4;q ~+;1.11;4;1;8,%x%;10,%y%;q ~# Copy @volax into volax ~+;2.41;1;y;ul1;@volax;;*;4;q ~+;1.11;4;1;16,%x%;19,%x%;q ~# Copy @voltr into voltr ~+;2.41;1;y;us1;@voltr;;*;*;4;q ~+;1.11;4;1;39,%x%;36,%x%;q ~# Copy @board into board ~+;2.41;1;y;us1;@board;;*;*;4;q ~+;1.11;4;1;39,%x%;37,%x%;q ~# Save real time in timtr ~+;2.41;1;y;us1;@time;;*;*;4;q ~+;1.11;4;1;39,%x%;38,%x%;q ~# Restore values and compute the congestion penalty 2.41 ~+;1;y;ui1;@ui1tp;;*;4 ~+;1;y;ul1;@ul1tp;;*;4 ~+;1;y;us1;@timtr-@time;;*;*;4 q ~# Delete the extra attributes 2.42 ~+;3;@inboa;y ~+;3;@fiali;y ~+;3;@volax;y ~+;3;@voltr;y ~+;3;@board;y ~+;3;@lsvtr;y ~+;3;@time;y ~+;3;@ui1tp;y ~+;3;@ul1tp;y q ~# Delete the auxiliary matrix ~+;3.12;2;mf"UpqLT";q ~# Final time to the report ~+;~p=2009;~r3=%%%p%%%;~p=2010;~r4=%%%p%%%;~p=2011;~r9=%%%p%%% ~>>captras_cvg.rep ~/Final time: %r3%h%r4%m%r9%s ~/========================================================================= ~>> reports=^ ~:STOP ~o=6