To find the maximum row sum in a matrix in AMPL

351 views
Skip to first unread message

ashish.s...@gmail.com

unread,
Apr 29, 2014, 4:01:14 AM4/29/14
to am...@googlegroups.com
I am trying to find the maximum row sum in a matrix in AMPL. 
The code that I have written is 

param I_max;             # number of rows in the intensity matrix
param J_max;           # number of columns in the intensity matrix

# sets
set I := 1 .. I_max ; # set of rows of the intensity matrix , {1,...,I_max}
set J := 1 .. J_max ; # set of columns of the intensity matrix , {1,...,J_max}

# parameters
param A{I,J} >= 0, integer;  # given intensity matrix
param T_max = max( {i in I} : sum{j in J} A[i,j] );  

The error is 
i is undefined
context:  param T_max = max{ {i in I} : sum{j in J}  >>> A[i,j] <<<  }; 

Please help

victor.z...@gmail.com

unread,
Apr 29, 2014, 11:50:22 AM4/29/14
to am...@googlegroups.com
You don't need a colon after {i in I}:

  max {i in I} sum{j in J} A[i,j];

See the example of iterated max in the AMPL book.

HTH,
Victor


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at http://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages