~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 ~/ ========================================================================= ~/ BALANCE3 1.3 - Copyright (C) Heinz Spiess, Aegerten, Switzerland, 1992. ~/ ~/ Perform a 3-dimensional matrix balancing using the matrix calculator ~/ module 3.21 only. The third dimension constraints are given by the ~/ group-to-group totals of an aggregated matrix. Contrary to the ~/ module 3.22, in this macro the numbers of 3rd dimension constraint is ~/ not restricted to a maximum of 99. ~/ ~/ Usage: balance3 ~/ ~/ where: : full matrix containing matrix to be balanced (mfxx) ~/ : origin matrix containing productions (moxx) ~/ : destination matrix containing productions (mdxx) ~/ : full matrix to hold 3rd dimension totals (mfxx) - this ~/ matrix must contain the applicable 3rd dimension totals ~/ replicated in all corresponding o-d pairs (such as is ~/ always the case when an aggregated matrix is read in from ~/ batch with 3.11) ~/ : ensemble containing groups for 3rd dimension index (a-z) ~/ : origin matrix to hold origin multipliers (moxx) ~/ : destination matrix to hold destination muttipliers (mdxx) ~/ : full matrix to hold balanced result matrix (mfxx) ~/ ~x=%0% ~?x>7 / check if enough parameters are provided ~$>start_macro ~t9=~* Do you want to see more detailed instructions? ~t9=%t9.1% ~?!t9=y ~$>end_of_macro ~/ ~/ Temporaries (these matrices must exist prior to macro invocation): ~/ ms98 and ms99 used to save the maximum vialoations ~/ on origin and destination constraints ~/ mo99 used to save the current productions ~/ md99 used to save the current attractions ~/ ~/ Notes: ~/ - The matrix Rpq must contain the same value for all O-D pairs that have ~/ the same origin and destination group, i.e. the value which corresponds ~/ to the total group-to-group demand (this is the case automatically ~/ if matrix Rpq was read as an aggregated matrix in module 3.11). ~/ ~/ - In order for the balancing procedure to converge, it is necessary that ~/ all the group subtotals for productions and attractions in matrix Rpq ~/ match the corresponding subtotals in the production and attraction ~/ matrices Op and Dq. ~/ ~/ - If the above condition is met and the balancing procedure does not ~/ converge, this might also be due to too many zero cells in the matrix ~/ to be balanced Cpq. In particular, the multiplicative nature of the ~/ balancing model will cause the procedure not to work if a group-to-group ~/ total in the matrix Cpq is zero, but the corresponding value in Rpq ~/ is non-zero. ~$>end_of_macro ~:start_macro ~/ Matrix to balance: %1% (Cpq) ~/ Productions: %2% (Op) ~/ Attractions: %3% (Dq) ~/ 3-dim totals: %4% (Rpq - aggregation by zone gruop ensemble g%5%) ~/ Origin multipliers: %6% (ALPHAp) ~/ Destin. multipliers: %7% (BETAq) ~/ Result matrix: %8% (ALPHAp*BETAq*GAMMAk*Cpq) ~/ ========================================================================= ~x=0 c='start macro: balance3 %1% %2% %3% %6% %7% %4% %5% %8%' ~p=2004 ~?p=1 (UNIX) ~!rm -f bal3.sum ~?p=2 (DOS) ~!erase bal3.sum reports=bal3.rep batchout=bal3.tmp batchin=bal3.tmp 3.21 /perform a 3-dimensional matrix balancing using matrix calculator 1 /initialize destination multipliers to 1 (BETAq=1) y %7% y BETAq destination multipliers BETAq q ~?q=1 y 1 ~?e r 1 /initialize 3rd dimension multipliers to 1 y %8% y GAMMAk 3rd dimension multipliers GAMMAk ~?q=1 y 0 %1% n ~?q=2 2 ~:next_iteration ~x+1 / first balance origins at iteration %x% 1 /compute current productions y %6% y p%x% current productions ~?q=1 y 0 %7%*%8% n + ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) 1 /now compute new origin multipliers y %6% y a%x% origin multipliers APLHAp n %2%/(%6%+(%6%.eq.0)) n ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) 1 / now balance destinations y /compute current attractions md99 y p%x% current attractions ~?q=1 y 0 %6%*%8% n + ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) 1 /now compute new destination multipliers y %7% y b%x% destination multipliers BETAq-p n %3%/(md99+(md99.eq.0)) n ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) 1 /compute current demand matrix y %8% y abg0 ALPHAp*BETAq*gpq0 (%x%) n %6%*%7%*%1% n ~?q=2 2 q ~p=2004 ~?p=1 (UNIX) ~!rm -f bal3.tmp ~?p=2 (DOS) ~!del bal3.tmp 3.14 3 %8% y g%5% y g%5% 1 n q 3.12 2 %8% y q 3.11 ~?q=2 2 3.21 1 /compute new 3-dim multipliers y %8% y cg0%x% GAMMAk*gpq0 (iter%x%) n %4%*%1%/%8% %8% 0,0,ex n ~?q=2 2 1 /compute max violation y mo99 y gp%x% gp%x% ~?q=1 y 0 %6%*%7%*%8% n + ~?q=2 2 1 y ms98 y maxvp maxvio balance3 n 1000*abs(%2%-mo99) n .max. ~?q=2 2 1 y md99 y gq%x% gp%x% ~?q=1 y 0 %7%*%6%*%8% n + ~?q=2 2 1 y ms99 y maxvq maxvq %x% ~?q=1 y 0 1000*abs(%3%-md99) n .max. ~?q=2 2 ~/ Iteration %x%: maxvp=%ms98% maxvq=%ms99% (*.001) ~z=%ms98% ~?z>10 ~z=%ms99% ~?z>10 ~$next_iteration ~y=%0% 1 y %8% y gqp%x% balance3 %1% %2% %3% %4% g%5% ~?q=0 0 ~?q=1 n %8%*%6%*%7% n ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) q reports=^ batchin=^ batchout=^ c='end macro: balance3 %1% %2% %3% %6% %7% %8% ' ~/ ~/ ========================================================================= ~/ Macro 'balance3 %1% %2% %3% %6% %7% %8%' terminated normally ~/ after %x% iterations with a maximum constraint violation of ~/ %ms98% 1/1000th trips for productions and %ms99% 1/1000th trips ~/ for attractions. Results were stored in: ~/ origin multipliers (ALPHAp): %6% ~/ destination multipliers (BETAq): %7% ~/ balanced result matrix: %8% ~:end_of_macro ~/ ========================================================================= ~o=6