MIP output

147 views
Skip to first unread message

Karmel

unread,
Feb 17, 2017, 9:15:34 AM2/17/17
to AMPL Modeling Language
Hi everyone, 

Can anyone help me in finding out how to save each of the following output in different parameter? suppose run my code 10 times, I want to be able to save the following in each iteration and each in separate parameter, for example 

for i=1,....iteration, solve then save 

332 MIP simplex iterations= MIP [i]

0 branch-and-bound nodes=BB[i]

absmipgap = 7.10543e-14 = abs[i]

relmipgap = 9.50355e-16= rely[i]

No basis.


Thanks,


Robert Fourer

unread,
Feb 20, 2017, 3:40:40 PM2/20/17
to am...@googlegroups.com
Set option 'return_mipgap=7' in your cplex_options string, as in this example:

ampl: option solver cplex;
ampl: option cplex_options 'return_mipgap 7';
ampl: solve;
CPLEX 12.7.0.0: return_mipgap 7
CPLEX 12.7.0.0: optimal integer solution; objective 4460739.221
448 MIP simplex iterations
73 branch-and-bound nodes
No basis.

suffix relmipgap OUT;
suffix absmipgap OUT;
ampl:

(If you are already setting a cplex_options string, then add 'return_mipgap 7' to it.) Then use the following expressions to get the values you want:

MIP[i]: num(substr(solve_message,match(solve_message,"\n")+1,
match(solve_message,"MIP")-match(solve_message,"\n")-2));

BB[i]: num(substr(solve_message,match(solve_message,"s\n")+2,
match(solve_message,"branch")-match(solve_message,"s\n")-3));

abs[i]: Current.absmipgap
rel[i]: Current.relmipgap

Bob Fourer
am...@googlegroups.com

=======

K

unread,
Feb 23, 2017, 5:00:40 PM2/23/17
to AMPL Modeling Language, 4...@ampl.com
Hi Bob,

Thanks a lot t worked for me.

However the only thing that didn't work is  abs[i]: Current.absmipgap 
   rel[i]: Current.relmipgap it gives me the following message 
Bad suffix .absmipgap for Initial
Possible suffix values for Initial.suffix:
astatus   exitcode   message   relax
result    sstatus    stage  

thanks for your help :)

Robert Fourer

unread,
Feb 23, 2017, 11:11:23 PM2/23/17
to am...@googlegroups.com
This error occurs when CPLEX did not receive the directive 'return_mipgap 7' in cplex_options, and so did not define the suffixes relmipgap and absmipgap. To get more help, post a transcript from your AMPL session (what you typed, and the messages AMPL and CPLEX displayed); also if you included a run file, attach that to your message.

K

unread,
Feb 24, 2017, 8:02:42 AM2/24/17
to AMPL Modeling Language, 4...@ampl.com
Hi Bob thanks of your great help;

here is the code : 
option cplex_options 'timing=1 return_mipgap=7 
some lines to define parameters and load models
param absMIPgap{j in 1..iter}; 
for {j in 1..iteration}{

code;
solve;
let MIP[j]:= num(substr(solve_message,match(solve_message,"\n")+1, 

                      match(solve_message,"MIP")-match(solve_message,"\n")-2)); 

  let BB[j]:= num(substr(solve_message,match(solve_message,"s\n")+2, 

                     match(solve_message,"branch")-match(solve_message,"s\n")-3))
let absMIPgap[j]:=Current.absmipgap;;

}
I can get MIP and BB without the line let absMIPgap[j]:=Current.absmipgap;; but once I add it I get the following message 
Bad suffix .absmipgap for Initial
Possible suffix values for Initial.suffix:
astatus   exitcode   message   relax
result    sstatus    stage 

Thank you very much;
K



On Thursday, February 23, 2017 at 11:11:23 PM UTC-5, Robert Fourer wrote:
This error occurs when CPLEX did not receive the directive 'return_mipgap 7' in cplex_options, and so did not define the suffixes relmipgap and absmipgap.  To get more help, post a transcript from your AMPL session (what you typed, and the messages AMPL and CPLEX displayed); also if you included a run file, attach that to your message.

Bob Fourer
am...@googlegroups.com


Robert Fourer

unread,
Feb 24, 2017, 11:22:00 PM2/24/17
to am...@googlegroups.com
You can fix this problem by putting the following commands before your loop:

suffix relmipgap OUT;
suffix absmipgap OUT;

for {j in 1..iteration} {
...

Normally the solver tells AMPL to define these two suffixes. But when the solve is in a loop, AMPL processes all the statements in the loop before executing them; as a result AMPL rejects relmipgap and absmipgap before the solver has a chance to define them. In this situation you need to define these two suffixes explicitly before the loop.

Bob Fourer
am...@googlegroups.com

=======

K

unread,
Mar 5, 2017, 4:58:00 PM3/5/17
to AMPL Modeling Language, 4...@ampl.com
Thanks a lot for your great help, it worked for me finally 
Reply all
Reply to author
Forward
0 new messages