repeat --while loop

240 views
Skip to first unread message

Hossein Haghighat

unread,
May 6, 2021, 10:14:25 AM5/6/21
to AMPL Modeling Language
hello,
I am using a Benders-like algorithm for solving an MILP model. the repeat-while  loop is terminated after 3 iter. but no values are recorded for variables in the last iter., say x[3]. that is, only x[1], x[2] have values. the counter of iteration is increased in each pass (j <----- j+1) 
is this happening because of the nature of  "repeat-while " nature? 

thank you in advance    

AMPL Google Group

unread,
May 6, 2021, 1:59:36 PM5/6/21
to AMPL Modeling Language
At the start of each pass through the repeat loop, the "while" condition is tested; if the condition is true, the repeat stops immediately without executing any more statements in the loop. Maybe you are not writing the loop correctly. With only the information that you give, however, it is not possible to say what the error might be.


--
Robert Fourer
am...@googlegroups.com
{#HS:1505616648-104139#}

Hossein Haghighat

unread,
May 7, 2021, 3:34:50 PM5/7/21
to am...@googlegroups.com
many thanks for the reply. I have attached the structure of the loop. 
basically, it has two "nested Benders Loops" for a specific purpose. 


--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/IGtr2gaplgY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/reply-77152-1505616648-4372019963-1620323971-584072298%40helpscout.net.

Mailtrack Sender notified by
Mailtrack 05/07/21, 10:21:52 AM
nested_loop.txt

AMPL Google Group

unread,
May 9, 2021, 2:34:34 PM5/9/21
to AMPL Modeling Language
Your example shows only one loop, the "while" loop at the beginning. So it is not clear what you mean by the "two nested Benders Loops". The one loop will test the condition "(GAP_o >= 10 || GAP_i >= 10) && (nCUT <= 10 && innCUT <= 15)" at the beginning of the first pass through the loop, and at the end of every pass through the loop, and when the condition is found to be false then the loop will terminate immediately. There are no if, break, or continue statements that would cause only part of the loop to be executed.

I can't say why "no values are recorded for variables in the last iter., say x[3]. that is, only x[1], x[2] have values". There are no variables actually named x, so it is not clear which variables are not having values recorded. In any case, be sure to check that all of the "solve" statements are showing an "optimal solution" message, since if the solver reports some other status then it may not be returning anything to AMPL.


--
Robert Fourer
am...@googlegroups.com
{#HS:1505616648-104139#}
On Fri, May 7, 2021 at 7:34 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
many thanks for the reply. I have attached the structure of the loop.
basically, it has two "nested Benders Loops" for a specific purpose.

On Thu, May 6, 2021 at 5:59 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
At the start of each pass through the repeat loop, the "while" condition is tested; if the condition is true, the repeat stops immediately without executing any more statements in the loop. Maybe you are not writing the loop correctly. With only the information that you give, however, it is not possible to say what the error might be.


--
Robert Fourer
am...@googlegroups.com

Hossein Haghighat

unread,
May 9, 2021, 7:22:35 PM5/9/21
to am...@googlegroups.com
thank you for your comments. The codes were not complete. 
The full model is attached. Please try to display "PGmp" variable. 

(p.s. please do not share the codes in the group. )

Mailtrack Sender notified by
Mailtrack 05/10/21, 02:55:40 AM

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/IGtr2gaplgY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
mip_dual_dyn_GTep.mod
mip_dual_dyn_GTep.run
mip_dyn_GTep_6node.dat

AMPL Google Group

unread,
May 11, 2021, 2:29:46 PM5/11/21
to AMPL Modeling Language
In mip_dual_dyn_GTep.run, you commented out all of the lines that set a solver. So I am not sure what solver you wanted to use. But when I uncomment the lines that set Gurobi as the solver, 3 iterations seem to run successfully. After the loop, PGmp displays like this:

ampl: display PGmp;
PGmp :=
3 1 1 1 1   2.1247
3 1 1 1 2   2.1247
3 2 1 1 1   2.48695
3 2 1 1 2   2.48695
3 3 1 1 1   2.5
3 3 1 1 2   2.5
;

But you have set "option omit_zero_rows 1;", so AMPL is showing only the PGmp variables that have nonzero values. Set "option omit_zero_rows 0;" to see a complete listing including all of the variables that have a value of 0.


--
Robert Fourer
am...@googlegroups.com
{#HS:1505616648-104139#}
On Sun, May 9, 2021 at 11:22 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
thank you for your comments. The codes were not complete.
The full model is attached. Please try to display "PGmp" variable.

(p.s. please do not share the codes in the group. )

Mailtrack
Sender notified by
Mailtrack 05/10/21, 02:55:40 AM


On Sun, May 9, 2021 at 6:34 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Your example shows only one loop, the "while" loop at the beginning. So it is not clear what you mean by the "two nested Benders Loops". The one loop will test the condition "(GAP_o >= 10 || GAP_i >= 10) && (nCUT <= 10 && innCUT <= 15)" at the beginning of the first pass through the loop, and at the end of every pass through the loop, and when the condition is found to be false then the loop will terminate immediately. There are no if, break, or continue statements that would cause only part of the loop to be executed.

I can't say why "no values are recorded for variables in the last iter., say x[3]. that is, only x[1], x[2] have values". There are no variables actually named x, so it is not clear which variables are not having values recorded. In any case, be sure to check that all of the "solve" statements are showing an "optimal solution" message, since if the solver reports some other status then it may not be returning anything to AMPL.


--
Robert Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages