MinFUNC

52 views
Skip to first unread message

sahebe...@gmail.com

unread,
Jul 20, 2016, 7:38:47 AM7/20/16
to AMPL Modeling Language
Hi
how i can get the minimum value of a matrix rows ???
the matrix has n rows and n column.
for example: min (M[1,1]):=10 = M[1,3]   How i can get this???
M[i,j]:=
                 1               2             3    

    
1               20            30           10

 
2               30             40           20
 

3               10             50           60

WBR

Victor Zverovich

unread,
Jul 21, 2016, 12:08:24 PM7/21/16
to am...@googlegroups.com
You can get the minimum with the following expression:

  min{i in 1..3, j in 1..3} M[i, j]

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 https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

sahebe...@gmail.com

unread,
Jul 23, 2016, 11:44:41 AM7/23/16
to AMPL Modeling Language
hi
i get minimum value of each rows
please answer me thanks a lot

Robert Fourer

unread,
Jul 24, 2016, 6:43:50 AM7/24/16
to am...@googlegroups.com
The minimum of row i is

min {j in 1..3} M[i,j]

You can use this expression anywhere that the index i is defined. So for example you can specify

param M {1..3,1..3};
param Mmin {i in 1..3} = min {j in 1..3} M[i,j];

Bob Fourer
am...@googlegroups.com

///////

sahebe...@gmail.com

unread,
Jul 24, 2016, 10:40:07 AM7/24/16
to AMPL Modeling Language, 4...@ampl.com
hi
thanks Bob for your answer
bat i get Mmin[i,j]
for example the minimum value of first row is on the third column so Mmin:=[1,3]
WBR

Robert Fourer

unread,
Jul 27, 2016, 3:19:38 AM7/27/16
to am...@googlegroups.com
Are you looking for the "arg min" -- the column in which the minimum appears, rather than the value of the minimum? AMPL does not have this kind of min function, but you could write

param M {1..3,1..3};
param Mmin {i in 1..3} = min {j in 1..3} M[i,j];
param MminCol {i in 1..3} = min {j in 1..3: M[i,j] = Mmin[i]} j;

If the minimum occurs in more than one column, the first one will be chosen. This is not especially efficient, but it will be very fast unless your matrix is very large.

Bob Fourer
am...@googlegroups.com

=======

sahebe...@gmail.com

unread,
Jul 30, 2016, 12:44:18 PM7/30/16
to AMPL Modeling Language, 4...@ampl.com
thanks a lot
Reply all
Reply to author
Forward
0 new messages