On Jun 7, 11:26 pm, Ruben Proano <
rpro...@...> wrote:
> Hello,
> I am trying to solve a sequence of problems, where the solutions to
> the first problem become data for the second problem, and so forth.
> What is the best way to implement a script for it?
>
> Thank you,
>
> Ruben
Here's a simple model file that contains an outer problem and an inner
problem, with the solution to the outer problem used in the inner
formulation:
# outer problem: knapsack
var x {1..2} integer >= 0;
maximize knapobj: x[1] + 2*x[2];
s.t. knaplimit: 4*x[1] + 3*x[2] <= 15;
problem Outer: x, knapobj, knaplimit;
# inner problem: LP with objective coefficients
# from the outer problem
var y {1..2} >= 0;
maximize lpobj: x[1]*y[1] + x[2]*y[2];
s.t. lpconstraint: y[1] + y[2] <= 3;
problem Inner: y, lpobj, lpconstraint;
# solve the outer problem
solve Outer;
display x;
# use the results in the inner problem
solve Inner;
display y;
You can find more sophisticated examples at
http://www.ampl.com/NEW/LOOP2/index.html,
where among other things they use separate files for models and
scripts.
One thing: if you have a situation in which the value of a variable X
in the previous solution is used as a parameter in a problem where X
itself again appears as a variable, then you need to introduce a
parameter to hold the previous value. In other words, something like
var X;
# model M1 has X as a variable
solve M1;
# store the value of X
param xval;
let xval := X; # use this wherever you need the value of X from the
previous solution
# model M2 also has X as a variable, and uses xval as a parameter
solve M2;
# ...
/Paul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to
ampl@...
To unsubscribe from this group, send email to
ampl-unsubscribe@...
For more options, visit this group at
http://groups.google.com/group/ampl?hl=en-~----------~----~----~----~------~----~------~--~---