~o=16
~?!i&32768
~o=39
~$>end_of_copyright
~/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
~/Copyright (C) Heinz Spiess, CH-2558 Aegerten, 1997. 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
~/*****************************************************************************
~/********* BALANCE 1.2 - 2-DIMENSIONAL BALANCING USING MODULE 3.21 *********
~/********* Copyright (C) Heinz Spiess, CH-2558 Aegerten, 1991-1997 *********
~/
~/This macro performs a 2-dimensional matrix balancing (also known as "Fratar",
~/"Furness" or "biproportional Factoring") using only the matrix calculator
~/module 3.21. It is not as efficient as the 2-dimensional balancing in
~/module 3.22, but the macro is mainly intended for didactical purposes or
~/as a starting point to implement all kind of variants of the basic balancing
~/procedure.
~/
~/Usage: balance []
~/
~/where: : full matrix containing matrix to be balanced (mfxx)
~/ : origin matrix containing productions (moxx)
~/ : destination matrix containing productions (mdxx)
~/ : origin matrix to hold origin multipliers (moxx)
~/ : destination matrix to hold destination muttipliers (mdxx)
~/ : full matrix to hold balanced matrix (mfxx) - optional!
~/
~/Temporaries: ms99 is used to save the stopping criteria
~/ md99 is used to save the current attractions
~/
~/Stopping criteria: r1 contains maximum allowed constraint violation
~/ r2 contains maximum number of iteration
~/
~x=%0%
~?x<5 / check if enough parameters are provided
~$end_of_macro
~+|~?r1=0|~r1=.01
~+|~?r2=0|~r2=25
~/Matrix to balance: %1%
~/Productions: %2%
~/Attractions: %3%
~/Origin multipliers: %4%
~/Destin. multipliers: %5%
~?x>5
~/Result matrix: %6%
~/Stopping criteria: %r1% max. constraint violation %r2% iterations
~/=========================================================================
~/
~x=0
c='start macro: balance %1% %2% %3% %4% %5% %6% '
3.21 /perform a 2-dimensional matrix balancing using matrix calculator
1 /initialize destination multipliers to 1
y
%5%
y
betaq
destination multipliers beta q
~?q=1
y
1
~?e
r
~:next_iteration
~x+1 / first balance origins at iteration %x%
1 /compute current productions
y
%4%
y
p%x%
current productions
~?q=1
y
0
%5%*%1%
n
+
~?q=2
2 /send report to print file
1 /now compute new origin multipliers
y
%4%
y
a%x%
origin multipliers alpha-p
n
%2%/(%4%+(%4%.eq.0))
n
~?q=2
2 /send report to print file
1 /now balance destinations
y
md99
y
p%x%
current attractions
~?q=1
y
0
%4%*%1%
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(%3%-%5%*md99)
n
.max.
~?q=2
2 /send report to print file
1 /now compute new destination multipliers
y
%5%
y
b%x%
destination multipliers beta-p
n
%3%/(md99+(md99.eq.0))
n
~?q=2
2 /send report to print file
~/Iteration%x_4%: maximum contraint violation: %ms99%
~?r1<%ms99%
~+|~?!x>%r2%|~$next_iteration
~y=%0%
~?y<6
~$no_result_matrix
~/
~/Compute result matrix in %6%
1
y
%6%
y
b2res
balance %1% %2% %3% (%d%)
~?q=0
0
~?q=1
n
%1%*%4%*%5%
n
~?q=2
2 /send report to print file
~:no_result_matrix
q
c='end macro: balance %1% %2% %3% %4% %5% %6% '
~/
~/=========================================================================
~/ Macro 'balance %1% %2% %3% %4% %5% %6%' terminated normally
~/ after %x% iterations with a maximum constraint violation
~/ of %ms99% trips. Results were stored in: %4% %5% %6%
~:end_of_macro
~/=========================================================================
~o=6