[AMPL 18324] Iterations in Run

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[AMPL 18324] Iterations in Run

davidmat025
Hello, I would like to write a script that can call the model and data scripts and solve the problem using AMPL CPLEX then after use the results found and repeat again for like five iterations. 

Anyone can help, please.

Thank you.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 18335] Iterations in Run

AMPL mailing list
As a simple example, if you have a model file iter.mod and data files iter1.dat, iter2.dat, iter3.dat, iter4.dat, iter5.dat, you can create an AMPL script file iter.run that contains the following statements:

model iter.mod;
for {i in 1..5} {
   reset data;
   data ("iter" & i & ".dat");
   solve;
}

Then you can run the script with the command "include iter.run". This approach can be adapted to many other situations.

--
Robert Fourer
[hidden email]
{#HS:793819243-37760#}
On Tue, Mar 5, 2019 at 4:40 AM UTC, Ampl Modeling Language <[hidden email]> wrote:
Hello, I would like to write a script that can call the model and data scripts and solve the problem using AMPL CPLEX then after use the results found and repeat again for like five iterations.

Anyone can help, please.
Thank you.



--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 18339] Iterations in Run

davidmat025
Hello, 
I have received your response but I have only one data script. I want the Program to solve the problem and the use results as new data for the next iteration If possible one can set the stopping criteria.
I have attached all the scripts that I have.

On Wednesday, March 6, 2019 at 6:13:38 AM UTC+9, AMPL Google Group wrote:
As a simple example, if you have a model file iter.mod and data files iter1.dat, iter2.dat, iter3.dat, iter4.dat, iter5.dat, you can create an AMPL script file iter.run that contains the following statements:

model iter.mod;
for {i in 1..5} {
   reset data;
   data ("iter" & i & ".dat");
   solve;
}

Then you can run the script with the command "include iter.run". This approach can be adapted to many other situations.

--
Robert Fourer
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="xw-Jm273AgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...
{#HS:793819243-37760#}
On Tue, Mar 5, 2019 at 4:40 AM UTC, Ampl Modeling Language <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="xw-Jm273AgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...> wrote:
Hello, I would like to write a script that can call the model and data scripts and solve the problem using AMPL CPLEX then after use the results found and repeat again for like five iterations.

Anyone can help, please.
Thank you.



--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

Optim.run (963 bytes) Download Attachment
Optim.dat (1K) Download Attachment
Optim.mod (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 18343] Iterations in Run

AMPL mailing list
You can still put your "solve" inside a loop. For example:

repeat {
   solve;
   let {c in Cars, t in Time} 
      alpha[c,t] := beta[c,t]*otherprice[t] + (othersupplier[c,t] - otherclient[c,t]);
   let {t in Time} Newotherprice[t] := 
      (gamma*( sum{c in Cars:((alpha[c,t]/beta[c,t])<=otherprice[t])} alpha[c,t]) + 
      (sum{c in Cars: ((alpha[c,t]/beta[c,t]) > otherprice[t])} alpha[c,t])) / 
         (gamma*( sum{c in Cars: ((alpha[c,t]/beta[c,t]) <= otherprice[t])} beta[c,t] ) + 
      (sum{c in Cars: ((alpha[c,t]/beta[c,t]) > otherprice[t])} beta[c,t]));
   printf {t in time} "%5d %6.2lf\n", t, Newotherprice[t] > 2Prosumers1.out;
   let {c in Cars, t in Time} otherprice[t] :=  Newotherprice[t];
} until some-termination-condition;

Alternatively, instead of the "until" at the end, you can put a statement of the form "if some-termination-condition then break;" anywhere inside the loop. For other possibilities, see Chapter 13 of the AMPL book, particularly sections 13.2 and 13.3.

--
Robert Fourer
[hidden email]
{#HS:793819243-37760#}
On Wed, Mar 6, 2019 at 5:19 PM UTC, Ampl Modeling Language <[hidden email]> wrote:
Hello,
I have received your response but I have only one data script. I want the Program to solve the problem and the use results as new data for the next iteration If possible one can set the stopping criteria.
I have attached all the scripts that I have.



On Tue, Mar 5, 2019 at 9:13 PM UTC, AMPL Google Group <[hidden email]> wrote:
As a simple example, if you have a model file iter.mod and data files iter1.dat, iter2.dat, iter3.dat, iter4.dat, iter5.dat, you can create an AMPL script file iter.run that contains the following statements:

model iter.mod;
for {i in 1..5} {
   reset data;
   data ("iter" & i & ".dat");
   solve;
}

Then you can run the script with the command "include iter.run". This approach can be adapted to many other situations.

--
Robert Fourer
[hidden email]


On Tue, Mar 5, 2019 at 4:40 AM UTC, Ampl Modeling Language <[hidden email]> wrote:
Hello, I would like to write a script that can call the model and data scripts and solve the problem using AMPL CPLEX then after use the results found and repeat again for like five iterations.

Anyone can help, please.
Thank you.



--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.