ERROR

24 views
Skip to first unread message

sahebe...@gmail.com

unread,
Jun 17, 2017, 8:42:41 AM6/17/17
to AMPL Modeling Language
Hi all,

what is wrong with this code?

for {j in VCH}{
let s[j] := min {j in VCH:min_g[j] = minT1} j;}

I want to use this code but I do not know why I can not use j in VCH in line2 !!!!!!! What should I do?

Thanks a lot

Robert Fourer

unread,
Jun 18, 2017, 4:15:24 PM6/18/17
to am...@googlegroups.com
When you write "for {j in VCH} {...}" then j is defined inside your "for" loop, and you cannot define j again with another indexing expression inside the loop. Since "min {j in VCH: ...}" appears inside the loop and it is trying to define j again, it is rejected as an error.

Bob Fourer
am...@googlegroups.com

=======

sahebe...@gmail.com

unread,
Jun 18, 2017, 5:30:26 PM6/18/17
to AMPL Modeling Language
Hi again,
Thanks for your help
what do you mean by defining j again?
How can I do that??can you give me an example!
WBR

Robert Fourer

unread,
Jun 19, 2017, 10:34:45 AM6/19/17
to am...@googlegroups.com
Your for loop begins "for {j in VCH}" so you should *not* write "j in VCH" in the statement that is inside your loop. Inside the loop you can use a different index instead -- for example, "k in VCH".

Bob Fourer
am...@googlegroups.com


-----Original Message-----
From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of sahebe...@gmail.com
Sent: Sunday, June 18, 2017 4:30 PM
To: AMPL Modeling Language
Message has been deleted

sahebe...@gmail.com

unread,
Jun 19, 2017, 2:25:56 PM6/19/17
to AMPL Modeling Language, 4...@ampl.com
I really thank you for your answer
I got one more question, I have a matrix and I want to find the minimum value of each rows.
As example:
D [*,*] (tr)
:           3          4                9             :=
1     18.2408   19.9784     9.15531    
2     91.0059   94.0634    71.0325      
3     12.7454   29.8102    13.0633     

The minimum value of row1:=9.15531 that is belong to point9
The minimum value of row2:=71.0325 that is belong to point9
The minimum value of row3:=12.7454 that is belong to point3

With this code I can get The minimum value of each rows: 
 param s {j in VCH};
for {j in VCH}{
let s[j] := min {i in z} D[i,j] ;}
But how can I get the number of each column????

WBR

Robert Fourer

unread,
Jun 20, 2017, 12:07:25 PM6/20/17
to am...@googlegroups.com
The following loop also stores the number of the column in which the minimum occurs:

param s {VCH};
param scol {VCH};

for {j in VCH}{
let s[j] := min {i in z} D[i,j] ;
let scol[j] := min {i in z: D[i,j] = s[j]} i;
};

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of sahebe...@gmail.com
Sent: Monday, June 19, 2017 1:10 PM
To: AMPL Modeling Language
Cc: 4...@ampl.com
Subject: Re: [AMPL 14248] ERROR

I have a matrix and I want to find the minimum value of each rows!
As example:

D [*,*] (tr)
: 5 10 15 17 :=
1 8.73976 34.309 62.2722 39.8081
2 31.825 23.1055 40.6804 8.17676
3 80.3651 56.2559 38.3523 44.5855
4 59.3589 31.1478 4.11042 39.9419

min value of row1:= 8.73976 it is belong to point 5
min value of row2:= 8.17676 it is belong to point 17

param s {j in VCH};
for {j in VCH}{
let s[j] := min {i in z} D[i,j] ;}

With this code I can find the minimum value of each rows, but how I can get the number of column?


sahebe...@gmail.com

unread,
Jun 21, 2017, 7:52:53 AM6/21/17
to AMPL Modeling Language
Thanks bob
You have always helped me
Reply all
Reply to author
Forward
0 new messages