For-Loop and Let Command

18 views
Skip to first unread message

fats...@gmail.com

unread,
Jan 16, 2017, 3:22:10 PM1/16/17
to AMPL Modeling Language
Hello everybody I have some problems understanding the For-Loop and the Let Command.

I don't understand the indexing of r in LB in the for-Loop for example. I don't understand the meaning of let lambda := r .

set LB; 

let LB := lambda .. lambda + 10 by 1; 

param Costs1{r in LB}; 

for {r in LB} 

{

let lambda := r;

solve;

let Costs1[r] := Costs;

}


Best regards


Robert Fourer

unread,
Jan 17, 2017, 10:52:40 AM1/17/17
to am...@googlegroups.com
"for {r in LB}" sets r to some member of the set LB and executes the statements in the loop; then it sets r to another member of the set LB and executes the statements in the loop; and so forth for as many times as there are members in LB. Each time through the loop, "let lambda := r" sets assigns the current value of r to lambda (which is maybe defined earlier by an AMPL statement like "param lambda integer > 0;").

I would agree however that the purpose of this code is hard to understand. Why make the assignment

let LB := lambda .. lambda + 10 by 1;

before the loop and then write

let lambda := r;

inside the loop? To figure this out you would need to study the entire example, or else ask the person who wrote it.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages