model updates with display command

58 views
Skip to first unread message

james.co...@gmail.com

unread,
May 23, 2016, 8:27:03 AM5/23/16
to AMPL Modeling Language
I'm solving a multi-period dynamic stochastic problem with decisions made for the entire problem in advance and then moving through time sequentially.

I make use of dynamic sets to track time and which variables to fix.

I have three main sets to track time
set SetTimeInterest                  ordered := 1 .. Time ;
set SetTimeInterestStochastic ordered := 1+time .. Time ;
set SetTimeInterestFixed         ordered := 1 .. time-1 ;

Initially time = 0 and I solve for the variables.

I then let time := 1

I then fix a set of variables, eg
fix {t in SetTimeInterestFixed, j in SetBalanceBidPrices} Qbid_b[t,j] ;

If I then enter in the command "display {t in SetTimeInterest} sum{b in SetBalancing} rho_b[b] * Qbid_sum_b[b,t] ;" the model goes through the pre-solve phase and tells me how many variables etc it has eliminated.

var Qbid_sum_b{b in SetBalancing, t in SetTimeInterest} = sum{j in SetBalanceBidPrices} Qbid_b[t,j] * Abid_b[b,t,j] ;

where Abid_b is a parameter and Qbid_b is a variable.

In the model, Qbid_sum_b shows up in a piecewise linear constraint:
subject to FloodingStoch {b in SetBalancing, t in SetTimeInterestStochastic} : Q_b[b,t] = << Q_b_bar[b,t] ; 1,0 >> Qbid_sum_b[b,t] ;

Why is the model going through the pre-solve phase when displaying a variable from the model?

Could there be a large problem in my code? I can share a zip folder if needed.

thanks
James

Robert Fourer

unread,
May 23, 2016, 2:34:58 PM5/23/16
to am...@googlegroups.com
At the first solve, some of the variables are fixed by presolve, and others have their values set by the solver. Then when you use "let" and "fix" to change the problem after the solve, the previous presolve may become invalid; in particular, some of the some of the variables previously fixed may no longer be fixed to correct values, or may not be fixable at all.

Thus when you subsequently display an expression involving variables, presolve has to be run again. Note that at that point, the values of the variables are not necessarily optimal for either the original problem or the current one. So if you want to display some expressions involving the optimal values from the original problem, you should do that before making changes with "let" or "fix".

Bob Fourer
am...@googlegroups.com

=======

james.co...@gmail.com

unread,
May 24, 2016, 11:59:56 AM5/24/16
to AMPL Modeling Language, 4...@ampl.com
Hi Bob

Thanks for the answer - that makes sense.

A separate (but related) problem I'm having is that when I run my with each time iteration, each time I run 'solve', presolve is telling me the problem is infasible. If I then type in 'solve' again, the problem solves.

However, when I run the code in a loop, the second solve doesn't seem to force it to a solver, and instead keeps on telling me that the problem is infeasible.

How can I force the second solve to run from within a loop?

thanks
James

james.co...@gmail.com

unread,
May 24, 2016, 12:06:29 PM5/24/16
to AMPL Modeling Language, 4...@ampl.com
Attached is my model and data. The problem occurs in part_7_solve_path.mod. The master file is code.run, if this helps.
model.zip

Robert Fourer

unread,
May 26, 2016, 9:27:45 PM5/26/16
to am...@googlegroups.com
We have reproduced this behavior and are considering what steps we should take. I'll post a follow-up when there's more to report, probably within a week. A possible workaround would be to set "option presolve 0;" which will force the solver to do all the presolving (except for some trivial operations such as removing unused variables).

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of james.co...@gmail.com
Sent: Tuesday, May 24, 2016 11:06 AM
To: AMPL Modeling Language
Cc: 4...@ampl.com
Subject: Re: [AMPL 12020] model updates with display command

Attached is my model and data. The problem occurs in part_7_solve_path.mod. The master file is code.run, if this helps.

=======

james.co...@gmail.com

unread,
May 30, 2016, 6:29:58 AM5/30/16
to AMPL Modeling Language, 4...@ampl.com
Thanks for looking into it. Any help would be great.

I can get around it by writing the model with hour specific constraints and then adding them and dropping them manually as needed, but this approach isn't as conceptually 'pretty'. Making use of dynamic sets and making the constraints dynamic makes the code easier to read.

Robert Fourer

unread,
May 31, 2016, 9:46:59 PM5/31/16
to am...@googlegroups.com
There was an option "infeas_clear" to tell AMPL what to do when presolve detects an infeasibility, but it was accidentally dropped from the log of updates (http://www.ampl.com/dl/ampl.updates.html). Now this option has been restored and extended so that it has four settings:

0 ==> always suppress "solve" and "write"
1 ==> allow a second "solve" or "write" to proceed when reading stdin in interactive mode (default)
2 ==> always allow a second "solve" or "write" to proceed
3 ==> always allow "solve" or "write" to proceed.

In your script you would use "option infeas_clear 2;" if you want presolve to report infeasibility on a first solve, and then send the problem to the solver if there is a second solve following. You could also use "option infeas_clear 3;" to force all problems found infeasible by presolve to be sent to the solver immediately.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of james.co...@gmail.com
Sent: Tuesday, May 24, 2016 11:00 AM
To: AMPL Modeling Language

james.co...@gmail.com

unread,
Jun 1, 2016, 8:39:00 AM6/1/16
to AMPL Modeling Language, 4...@ampl.com
Thanks for the help; this works.

kind regards
James
Reply all
Reply to author
Forward
0 new messages