Printing information into a text file

69 views
Skip to first unread message

Mario

unread,
Jan 19, 2021, 9:37:43 AM1/19/21
to AMPL Modeling Language
Hi,

I am executing a model file for different data files in a for loop. I am using CPLEX to solve the problem. At every iteration of the for loop I want to print the following data into a text file:
  1. Number of explored branch and bound nodes
  2. Optimality gap in the cases when the solver does not finish in a time limit
  3. Linear programming relaxation gap
I do not know how to print these values into a text file using the print or printf command. I apreciate if you could provide me information regarding this aspect.

Regards,
Mario

AMPL Google Group

unread,
Jan 20, 2021, 11:01:09 AM1/20/21
to AMPL Modeling Language
Here's how to write expressions for the values that you want. Then it is straightforward to write the values of these expressions to a text file using print or printf.

1. After solving, the number of nodes explored is reported by CPLEX in a short message like this:

CPLEX 20.1.0.0: optimal integer solution; objective 235625
308 MIP simplex iterations
50 branch-and-bound nodes


This message is also stored in the built-in parameter solve_message. You can use the following expression to extract the number of nodes from solve_message:

num0(substr(solve_message,match(solve_message,"s\n")+2))

2. Tell CPLEX to return gap values, by setting

option cplex_options 'return_mipgap=3';

(or if you are already setting a cplex_options string, by adding return_mipgap=3 to it). Then the relative and absolute mip gaps will be returned in the expressions <obj>.relmipgap and <obj>.absmipgap -- where you replace <obj> by the actual name of your objective function.

3. You will need to solve again with nodelim=0 added to the above cplex_options string, to get the gap values at the end of the root node processing.


--
Robert Fourer
am...@googlegroups.com
{#HS:1400387837-98730#}
Reply all
Reply to author
Forward
0 new messages