~o|16 ~?!i&32768 ~o=39 ~$>end_of_copyright ~/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ~/Copyright (C) Heinz Spiess, CH-2558 Aegerten, 1994. All rights reserved. ~/ ~/The right to use this macro is granted 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 ~/ without charge 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) The comments in this macros must not be removed and any additions or ~/ modification must be appropriately identified as such and give at least ~/ date, name and the reason of the modification. ~/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ~:end_of_copyright ~/***************************************************************************** ~/********* DEMADJ 1.6 - DEMAND ADJUSTMENT USING GRADIENT METHOD *********** ~/********* Copyright (C) Heinz Spiess, CH-2558 Aegerten, 1989-95 *********** ~/ ~/ This macro implements the gradient method for the O-D matrix adjustment ~/ problem. Using observed volumes on a subset of links and a starting O-D ~/ matrix, the model will adjust the matrix to better fit with the observed ~/ volumes. The "steepest descent" property of the gradient approach ensures ~/ that the O-D matrix is not changed more than necessary. In a nut shell, ~/ here is a summary of the computations performed by this macro at each ~/ gradient step: ~/ - auto assignment to get the link volumes 5.11/5.21 ~/ - computation link derivatives and objective funct. 2.41 ~/ - generate scattergram observed vs predicted volumes 2.43 ~/ - addl options assignment to compute gradient matrix 5.11/5.21 ~/ - multiply gradient matrix with weights (optional) 3.21 ~/ - addl options assignment to assign gradient matrix 5.11/5.21 ~/ - compute maximal gradient 3.21 ~/ - compute optimal step length 2.41 ~/ - update demand matrix and step counter 3.21 ~/ ~/ This method has shown to work very well and, using this macro, is very ~/ simple to apply. However, as all matrix adjustment methods, it is extremely ~/ important to be sure that the differences between observed and assigned ~/ volumes are indeed due to the demand matrix and not a result of a coding ~/ errors in the network, badly calibrated volume delay functions or wrong ~/ counts. Very careful analysis of the data before and after the adjustment ~/ is of utmost importance!!! ~/ ~/ Reference: Spiess, H., "A GRADIENT APPROACH FOR THE O-D MATRIX ADJUSTMENT ~/ PROBLEM", Publication 693, CRT, University of Montreal, 1990. ~/ ~/ Data requirements: ~/ @ltmp Reserved for temporary storage. Original contents will be lost. ~/ ms90: This scalar contains the current adjustment step number. If it ~/ exists, it must be initialized to 0 before a new adjustment ~/ is started. This scalar will be incremented after each adjustment ~/ step. It is compared with the stopping criterion at each ~/ iteration. ~/ ms91: Scalar to hold the value of the objective function Z. ~/ ms92: Scalar to hold the maximum gradient. ~/ ms93: Scalar to hold optimal step length. ~/ ms94: Scalar to hold temporary data. ~/ ~/ Other requirements: ~/ 1)This macro must be started at the main menu. ~/ 2)This macro needs a release 7.0 or later of the EMME/2 system. ~/ 3)This macro produces for each iteration a plot file named "scatNNN.plt" ~/ containing the observed vs. assigned scattergram. ~/ 4)This macro contains command escapes for UNIX and DOS systems which produce ~/ a file "summary" containing a one line summary with the value of the ~/ objective function Z, the maximum gradient M and the step length L ~/ for each iteration. ~/ 5)The demand adjustments can be restricted to a subset of O-D pairs by ~/ specifying an adjustability matrix in register t4 which contains a 1 ~/ if the demand of an OD-pair can be adjusted and 0 if it should not be ~/ changed. (Register t4 is changed by editing the macro accordingly.) ~/ 6)If needed, optional weight factors for the counts can be specified ~/ as an arbitrary link expression in text register t6. (Register t6 is ~/ changed by editing the macro accordingly.) ~/ ~/ Usage: ~ [] ~/ ~/ Macro Parameters: ~/ : link data item containing link counts (0=no count), e.g. "ul1" ~/ : Demand matrix to be adjusted (e.g. "mf6"). Since the initial ~/ contents of this matrix will be overwritten with the resulting ~/ adjusted matrix, it is recommended to first do a copy. ~/ This matrix must not be write protected. ~/ : Temporary matrix of type mf which is used to hold the gradient ~/ direction matrix. Must exist and not be write protected. ~/ : Number of iteration stopping criteria used in assignment. ~/ : Relative gap stopping criteria used in assignment. ~/ : Normalized gap stopping criteria used in assignment. ~/ : Number of gradient steps to be performed (adjustment ~/ iterations). ~/ : Optional argument. If set to 1, the first "half step" (reg. ~/ assignment to compute volumes) is skipped, assuming that the ~/ assignment was already performed. Use only when continuing ~/ with more step on the same adjustment (i.e. higher ~/ value). ~/ ~x=%0% ~?x<7 ~$STOP ~t2=%1% ~t3=.001 ~: If register t4 is empty (default), all O-D pairs are considered adjustable. ~: Otherwise, t4 can be set to a matrix expression containing 1 for cells that ~: are adjustable and 0s for cells that must not be changed. As this matrix ~: is multiplied into the gradient matrix, it can also be used as "weight" ~: matrix, specifying for each O-D pair a relative adjustability factor. ~t4= ~: Register t5 contains the type of equilibrium assignment: By default it ~: is "1", i.e. time based. A generalized cost assignment can be specified ~: by setting t5 to "~+|2|||" ~t5=1 ~: Register t6 contains an optional weight factor for count posts. ~: By default this register is empty, which implies that all count posts ~: have an implicit weight of 1. If needed t6 can be set to an arbitrary ~: link expression which provides positive weight factors for all count ~: post links (e.g. "t6=@cwght" if the weights are stored in the ~: extra link attribute @cwght). ~t6= ~% ~/***************************************************************************** ~/Link counts: %t2% ~/Current demand: %1% ~/Demand direction: %2% ~?!t4= ~/Adjustability factor: %t4% ~?!t6= ~/Countpost weight factors: %t6% ~/Assignment: %3% iterations, %4% % rel.gap, %5% norm.gap ~/Gradient steps: %ms90% - %6% (continue: %7%) c=demadj %t2% %1% %2% %3% %4% %5% %6% %7% ~x=%7% 0 ~?x>0 ~$CONTINUE STEP 3.12 /##### check if matrices exist and create them if necessary ############## 1 /create scalar ms90, if it does not already exist ms90 ~?e ~$CHECK MS91 step matrix adjustment step counter 0 1 /create scalar ms91, if it does not already exist ~:CHECK MS91 ms91 ~?e ~$CHECK MS92 Z-0 value of objective function Z 0 1 /create scalar ms92, if it does not already exist ~:CHECK MS92 ms92 ~?e ~$CHECK MS93 M-0 max abs gradient 0 1 /create scalar ms93, if it does not already exist ~:CHECK MS93 ms93 ~?e ~$CHECK MS94 L-0 maximum step length 0 1 /create scalar ms94, if it does not already exist ~:CHECK MS94 ms94 ~?e ~$CHECK DPQ temp temporary scalar 0 1 /create full matrix dpq, if it does not already exist ~:CHECK DPQ %2% ~?e ~$MATRIX CHECKS DONE dpq-0 demand gradient 0 ~:MATRIX CHECKS DONE ~?q=0 q 2.42 /##### check if extra attribute @ltmp exists 3 / remove @ltmp if it exists @ltmp ~?e ~?q=1 yes 2 ~?e ~+|q|~/No space for extra link attribute @ltmp!|~$STOP 2 @ltmp ~?e ~+||q|~$>NEXT STEP extra attribute created by DEMADJ.MAC 0 q ~:NEXT STEP ~/ ~/Gradient step %ms90%: 5.11 /##### prepare auto assignment to compute auto volumes ################### ~/.... Assign demand to get link volumes 1 / fixed demand auto assignment ~?q=2 2 / new assignment %t5% / type of assignment (time based or generalized cost) 1 / no additional volumes %1% / demand / no auto occupancy matrix / no addl demand / no auto times saved ~?q=1 y / initialize auto volumes %3% / max iterations %4% / % gap %5% / time diff. 5.21 /##### perform auto assignment to compute auto volumes ################### ~?b=1 2 2.41 /##### compute gradient and objective function ########################### 1 / network calculation - compute link gradient y @ltmp y link gradient - macro demadj (it %ms90%) %t3%*(%t2%>0)*(%t2%-volau) ~?!t6= *(%t6%) all 4 / none 1 / network calculation - compute objective function n (%t2%-volau)*(%t2%-volau)*%t3% ~?!t6= *(%t6%) not %t2%=0 5 / save summary results in scalars 4 / save sum of result values 91 / in scalar ms91 Z-%ms90% / scalar name 'Dem adj. obj. function - step %ms90%' q ~/.... Objective function at step %ms90% is %ms91% on=1 plots=scat%ms90%.plt 2.43 /##### plot scattergram observed vs predicted volumes #################### 2 / link scattergram %t2% / observed volumes vs volau / predicted volumes at step %ms90% n ~?q=1 n / no symbol index ~?q=1 n / no color index i=%ms90% and 0 not %t2%=0 y / compute regression 0 / default x range maximum 0 / default y range maximum ~?q=2 2 q off=1 plots=^ ~:CONTINUE STEP ~x=%6% ~?x<%ms90% ~$STOP 5.11 /##### prepare add option assignment to compute gradient matrix ########## ~/.... Compute gradient matrix 1 / fixed demand auto assignment ~?q=2 2 / new assignment %t5% / type of assignment (time based or generalized cost) 5 / additional options %1% / demand matrix / no auto occupancy / no add. demand = auto demand / no auto times ~?q=1 y / initialize volumes 6 @ltmp / addl path attribute + / addl path operator -99999,99999 / addl path threshold %2% / addl attribute matrix (4.3 and later) y D-%ms90% / matrix name demand gradient step %ms90% ~?q=1 y / initialize matrix 0 / to zero 3 / save weighted addl path attributes in matrix ~?q=1 y / initialize volumes %3% / number of iterations %4% / relative gap %5% / normalized gap 5.21 /##### perform add. opt. assignment to obtain gradient matrix ############ ~?q=2 2 ~?t4= ~$>No adjustability factor specified in register t4 3.21 /##### multiply gradient matrix with adjustability factor - if applicable 1 / matrix calculations y / save result %2% / gradient matrix n / don't change header %2%*(%t4%) / no constraint matrix n / no submatrix ~?q=2 2 / report to print file q ~:No adjustability factor specified in register t4 5.11 /##### prepare addl options assignment to get volume direction ########### ~/.... Assign gradient matrix to obtain volume direction 1 / fixed demand auto assignment 2 / new assignment %t5% / type of assignment (time based or generalized cost) 5 / addl options %1% / demand matrix / no auto occupancy %2% / demand gradient matrix / no auto times ~?q=1 y / initialize auto volumes 5 / no addl link attribute %3% / number of iterations %4% / relative gap %5% / normalized gap 5.21 /##### perform addl options assignment to get volume direction ########### ~?q=2 2 3.21 /##### compute maximum gradient ########################################## 1 / matrix calculation y / save result ms92 / in scalar 92 y M-%ms90% / scalar name 'maximum abs gradient step %ms90%' / and description ~?q=1 y 0 abs(%2%/%1%) %1% 0,0,ex n .max. .max. ~?q=2 2 ~?m=321 q ~/.... Maximum gradient is %ms92% 2.41 /##### compute optimal step length ####################################### 1 / compute denominator of optimal step n volad*volad/ms(92) not %t2%=0 5 4 94 / save temporarily in scalar 94 T-%ms90% SUM ( volad*volad ) .... step %ms90% r 1 / compute optimal step length now n (%t2%-volau)*volad/ms(94) ~?!t6= *(%t6%) not %t2%=0 5 4 93 / save step length in scalar 93 L-%ms90% Optimal step length .... step %ms90% q ~/.... Optimal step length is %ms93% 3.21 /##### update demand matrix ############################################## 1 / matrix calculations y / save result %1% / in y / modify header gpq%ms90% Demand at step %ms90% ~?q=1 n %1%+(ms93.min.1)*%2%/ms92 ~/.... Update demand: %1% := %1%+(%ms93%.min.1)*%2%/%ms92% n ~?q=2 2 ~?m=321 q 3.21 /##### increment step counter ms90 ####################################### 1 / matrix calculations ~p=2004 (check for operating system) ~?p=1 (UNIX) ~! echo I%ms90%: Z%ms91% M%ms92% L%ms93% >>summary ~?p=2 (DOS) ~! echo I%ms90%: Z%ms91% M%ms92% L%ms93% >>summary y / save result ms90 / in scalar 90 n / don't change header ms90+1 ~?q=2 2 ~?m=321 q c= I%ms90%: Z%ms91% M%ms92% L%ms93% ~$NEXT STEP ~:STOP ~/***************************************************************************** ~o=6 ~?b=2 q