User Tools

Site Tools


gams:counting_the_number_of_equations_generated_by_a_specific_constraint

Counting the Number of Equations generated by a specific Constraint

Q: I wonder if there is a nice way to count the number of the equation that is is related to a specific constraint. For example, a gams expression that is:

  demand(j) ..   sum(i, x(i,j))  =g=  b(j) ; 

How can I count the number of equation generated by that equation? Is there any suffix or index I can refer to?

If you use the limrow = 1 option, then the output of your gams model will include the first instance of every equation you have defined and include a message indicating the number of skipped rows also generated:

---- demand  =G=  satisfy demand at market j

demand(new-york)..  x(seattle,new-york) + x(san-diego,new-york) =G= 325 ;
     
      (LHS = 0, INFES = 325 ***)
     
REMAINING 2 ENTRIES SKIPPED

Thus the constraint demand(j) generates three equations.

Another approach is to use the results of the profile option to get the number of generated equations. Below is an example, which writes the collected information of the trnsport model into a file eq.txt:

$call 'gamslib trnsport'
option limrow=1,limcol=0, profile=1;
$include trnsport.gms
*  get number of equations from profile
execute 'grep -i secs %system.ofile% |grep "EQUATION" >eq.txt'

The last entry of each line in eq.txt tells you the number of generated equations:

  74  execute 'grep -i secs C:\temp\xxx\t2.lst |grep "EQUATION" >eq.txt'
----     61 EQUATION   cost          0.000     0.000 SECS      4 Mb      1
----     63 EQUATION   supply        0.000     0.000 SECS      4 Mb      2
----     65 EQUATION   demand        0.000     0.000 SECS      4 Mb      3
gams/counting_the_number_of_equations_generated_by_a_specific_constraint.txt · Last modified: 2007/08/09 13:56 (external edit)