~o|16 ~?!i&32768 ~o=295 ~$>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 ~/========================================================================= ~/BALMPROD 1.4 - Heinz Spiess, EMME/2 Support Center, CH-2558 Aegerten ~/ ~/Perform a 2-dimensional matrix balancing with multiple production types ~/using the matrix calculator module 3.21 only. ~/Up to 4 types of productions and corresponding friction matrices can be ~/specified. Make sure that the sum of all productions OpX matches the sum ~/of the attractions Dq. ~/ ~/Usage: balmprod ~/ ~/where: : destination matrix containing attractions (mdxx) ~/ : friction matrix for first type of productions (mfxx) ~/ : origin matrix containing first type of productions (moxx) ~/ : friction matrix for second type of productions (mfxx) ~/ : origin matrix containing second type of productions (moxx) ~/ : friction matrix for third type of productions (mfxx) ~/ : origin matrix containing third type of productions (moxx) ~/ : friction matrix for fourth type of productions (mfxx) ~/ : origin matrix containing fourth type of productions (moxx) ~/ ~y=%0% ~?y>2 / 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 ~/ ~/Results: ~/ mo91: origin matrix to hold first set multipliers (moxx) ~/ mo92: origin matrix to hold second set multipliers (moxx) ~/ mo93: origin matrix to hold thrird set multipliers (moxx) ~/ mo94: origin matrix to hold fourth set multipliers (moxx) ~/ md91: destination matrix to hold destination multipliers (mdxx) ~/ ~/Temporaries: ms99 is used to save the stopping criteria ~/ md99 is used to save the current attractions ~/ ~/Notes: ~/- Omit the parameters for balancing only two ~/ types of productions, and for three types. ~/- The sum of all productions must match the sum of the attractions. ~/- The balanced result matrices for type X are obtained by multiplying ~/ mo9X**md91. ~/- By default, the number of iterations is limited to 15. If required, ~/ change the corresponding test near the end of the macro ~/- It is possible to use matrix expression as parameters, e.g. ``2*mo15'' ~/ or ``mo10+"produc"'', as long as these do not contain blanks. ~$>end_of_macro ~:start_macro ~/Matrices to balance: %2% %4% %6% %8% ~/Productions: %3% %5% %7% %9% ~/Attractions: %1% ~/========================================================================= ~x=0 c='start macro: balmprod %1% %2% %3% %4% %5% %6% %7% %8% %9%' ~?e ~/log book entry too long! 3.21 /perform a 2-dimensional matrix balancing using matrix calculator 1 /initialize destination multipliers to 1 y md91 y betaq destination multipliers beta q ~?q=1 y 1 ~?e r ~:next_iteration ~x+1 ~/iteration %x%: 1 /compute current productions of type 1 ~/... balancing type 1 productions y mo91 y p1-%x% current productions of type 1 ~?q=1 y 0 md91*(%2%) n + ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) 1 /now compute new origin multipliers of type 1 y mo91 y a1-%x% origin multipliers alpha1-p n (%3%)/(mo91+(mo91.eq.0)) n ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) ~?y<5 ~$do_destinations 1 /compute current productions of type 2 ~/... balancing type 2 productions y mo92 y p2-%x% current productions of type 2 ~?q=1 y 0 md91*(%4%) n + ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) 1 /now compute new origin multipliers of type 2 y mo92 y a2-%x% origin multipliers alpha2-p n (%5%)/(mo92+(mo92.eq.0)) n ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) ~?y<7 ~$do_destinations 1 /compute current productions of type 3 ~/... balancing type 3 productions y mo93 y p3-%x% current productions of type 3 ~?q=1 y 0 md91*(%6%) n + ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) 1 /now compute new origin multipliers of type 3 y mo93 y a3-%x% origin multipliers alpha3-p n (%7%)/(mo93+(mo93.eq.0)) n ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) ~?y<9 ~$do_destinations 1 /compute current productions of type 4 ~/... balancing type 4 productions y mo94 y p4-%x% current productions of type 4 ~?q=1 y 0 md91*(%8%) n + ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) 1 /now compute new origin multipliers of type 4 y mo94 y a4-%x% origin multipliers alpha4-p n (%9%)/(mo94+(mo94.eq.0)) n ~?q=2 2 ~:do_destinations 1 /compute current attractions ~/... balancing attractions y md99 y a%x% current attractions ~?q=1 y 0 (mo91*(%2%) ~?y>4 +mo92*(%4%) ~?y>6 +mo93*(%6%) ~?y>8 +mo94*(%8%) ) n + ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) 1 /compute maximum violation y md98 y diff difference for balancing ~?q=1 y 0 (%1%)-md91*md99 n ~?q=2 2 /send report to print file 1 /compute maximum violation y ms99 y mxdiff maximum difference for balancing ~?q=1 y 0 abs((%1%)-md91*md99)*1000 n .max. ~?q=2 2 /send report to print file 1 /now compute new destination multipliers y md91 y b%x% destination multipliers beta-p n (%1%)/(md99+(md99.eq.0)) n ~?q=2 2 /send report to print file (iter=%x% maxdiff=%ms99%) ~/... maximum constraint violation at iteration %x% is %ms99%/1000 ~z=%ms99% ~t9=terminated normally ~?x>15 /maximum number of iterations is limited - change if required ~+|~z=0|~t9=was stopped ~?z>10 ~$next_iteration q c='end macro: balmprod %1% %2% %3% %4% %5% %6% %7% %8% %9%' ~?e ~/log book entry too long! ~/ ~/======================================================================== ~/Macro 'balmprod %1% %2% %3% %4% %5% %6% %7% %8% %9%' ~/%t9% after %x% iterations with a maximum constraint ~/violation of %ms99%/1000 trips. The resulting multipliers are ~?y=3 ~/stored in matrices md91 and mo91. ~?y=5 ~/stored in matrices md91, mo91 and mo92. ~?y=7 ~/stored in matrices md91, mo91, mo92 and mo93. ~?y=9 ~/stored in matrices md91, mo91, mo92, mo93 and mo94. ~/Type 1 trip matrix is: mo91*md91*%2% ~?y>4 ~/Type 2 trip matrix is: mo92*md91*%4% ~?y>6 ~/Type 3 trip matrix is: mo93*md91*%6% ~?y>8 ~/Type 4 trip matrix is: mo94*md91*%8% ~:end_of_macro ~/========================================================================= ~o=6