Iterative AMPL model solving with changing constraints

834 views
Skip to first unread message

Erik Lundegaard Hannisdal

unread,
May 8, 2011, 9:33:19 AM5/8/11
to AMPL Modeling Language
I have a MINLP that I wish to solve multiple times, each time
representing a new time value (i.e. same problem over the course of 24
hours). However, as time goes the constraints of the problem changes,
due to changing demands.

The model is set up using a for-loop representing the start of a new
hour. I use some of the information found in the previous optimization
to solve new next one, i.e. the objective function is dependent on the
last optimization.

I tried to change the constraints of the optimization by using
"delete" and "redeclare", however this cannot be done inside a for-
loop. Are there any way around this or do I have for write my new
constraints over and over? Also, can I write my constraints in an
external file as done with parameters in a .dat file?

Thank you for your help,

Regards

Erik L. H

Cristián Hernández

unread,
May 8, 2011, 5:16:25 PM5/8/11
to am...@googlegroups.com, AMPL Modeling Language
Dear Erik

Have you tried using the drop and restore commands?

I am using them to solve an iterative LP problem and it works for me.

Kind regards

Cristián Hernández C.

Enviado desde mi iPhone

> --
> You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
> To post to this group, send email to am...@googlegroups.com.
> To unsubscribe from this group, send email to ampl+uns...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ampl?hl=en.
>

Robert Fourer

unread,
May 9, 2011, 10:04:21 AM5/9/11
to am...@googlegroups.com
Since you are solving the same general model repeatedly, the form of the
constraints should not change from one solve to the next; rather what
changes is the number of constraints and/or the values in them. Thus the
thing to do here is to define your symbolic constraint in a subject-to
statement before the for-loop, and then to use assignments (let-statements)
within the loop to change what explicit constraints are generated. For
example in

www.ampl.com/NEW/LOOP2/trnloc1d.mod
www.ampl.com/NEW/LOOP2/trnloc1d.run

there is a constraint like this:

subj to Cut_Defn {k in 1..nCUT}:
if cut_type[k] = "point" then Max_Ship_Cost >=
sum {i in ORIG} supply_price[i,k] * supply[i] * Build[i] +
sum {j in DEST} demand_price[j,k] * demand[j];

and the meaning of this constraint is changed within a loop by statements
like this:

let nCUT := nCUT + 1;
let cut_type[nCUT] := "point";
let {i in ORIG} supply_price[i,nCUT] := Supply_Price[i];
let {j in DEST} demand_price[j,nCUT] := Demand_Price[j];

The first statement actually increases the number of constraints, by
expanding the index set 1..nCUT of constraint Cut_Defn. The others define
the values of the coefficients and constraints in the new constraint, by
setting them equal to the values of variables from the previous solve. The
same approach could be used to change coefficient values in existing
constraints. (To inactivate or reactivate entire constraints that you have
already created, use the drop and restore commands.)

Bob Fourer
4...@ampl.com

Erik Lundegaard Hannisdal

unread,
May 9, 2011, 4:52:30 AM5/9/11
to AMPL Modeling Language
Thank you, this does work in a way.

However, I cannot do this without adding additional variables, and
therefore using more than my 300 available, due to the use of a
student license. A redecleration of the current constraint would
handle this problem, as well as making the code much more readable to
an external user. Is this not possible in AMPL?

Erik L. H.

On 8 Mai, 23:16, Cristián Hernández <cristia...@gmail.com> wrote:
> Dear Erik
>
> Have you tried using the drop and restore commands?
>
> I am using them to solve an iterative LP problem and it works for me.
>
> Kind regards
>
> Cristián Hernández C.
>
> Enviado desde mi iPhone
>
Reply all
Reply to author
Forward
0 new messages