Nested loop with changing parameters values - error

19 views
Skip to first unread message

18...@novasbe.pt

unread,
Oct 16, 2017, 7:14:48 AM10/16/17
to AMPL Modeling Language
Hello everyone.

I am new to AMPL. I am trying to execute a loop in two layers  where i am trying to change the initial values of my variables and the values of my parameters in each loop. However I get the error when I try to run I get the following message: "error at _cmdno 40 executing "let" command  a has an = assignment in the model  " This is the structure of my code:

reset;
param a :=1;
var x>=0;

model model.mod;
option solver knitrampl;

repeat {

    for {i in 0..1 by 0.1} {

   let x:=i;
  solve;
  display x , i, a;
}

let a:=a-0.1 ;

}



Robert Fourer

unread,
Oct 16, 2017, 10:44:03 AM10/16/17
to am...@googlegroups.com
You should write "param a default 1;" -- or else just "param a;" and then "let a := 1;" before the repeat. (When you write "param a := 1;" then a is permanently defined as being 1.)

Bob Fourer
am...@googlegroups.com

=======

18...@novasbe.pt

unread,
Oct 16, 2017, 10:57:27 AM10/16/17
to AMPL Modeling Language
Perfect. Thank you very much Robert.
Reply all
Reply to author
Forward
0 new messages