1
$\begingroup$

I solving a MILP problem as given below using Python 3.8 and CPLEX 12.20. I want to obtain the number of nodes and nodes left. The details of the codes are as follows:


n_xvars=2 n_yvars=2

#Create model: my_MILP=Model(name='MILP example')

Defining variables:

x_vars={i+1:my_MILP.continuous_var(name='x_{}'.format(i+1),lb=-20,ub=20) for i in range(n_xvars)}

y_vars={i+1:my_MILP.integer_var(name='y_{}'.format(i+1),lb=-20,ub=20) for i in range(n_yvars)}

Adding constraints:

my_MILP.add_constraint(x_vars[1]+4x_vars[2]>=-5) my_MILP.add_constraint(x_vars[1]-y_vars[2]<=5) my_MILP.add_constraint(x_vars[1]+3y_vars[1]-10y_vars[2]<=10) my_MILP.add_constraint(x_vars[1]+2x_vars[2]-3y_vars[1]+4y_vars[2]<=2)

Defining objective function:

obj=x_vars[1]+5x_vars[2]+6y_vars[1]-2*y_vars[2] my_MILP.minimize(obj)

Model information

my_MILP.print_information() print(my_MILP.export_as_lp_string())

Solving and solution

my_MILP.solve() my_MILP.print_solution()


I have used a few codes such as

nd_count=my_MILP.get_solve_details().nodes_processed nd_left=my_MILP.get_solve_details().nodes_left

but I am getting errors like

AttributeError: 'SolveDetails' object has no attribute 'nodes_left' AttributeError: 'SolveDetails' object has no attribute 'nodes_processed'

I request the community to please help me obtain the node count and nodes left for MILP, IP, etc.

Thanks

$\endgroup$

1 Answer 1

2
$\begingroup$

I think what you want can be seen in the CPLEX log as follows:

Tried aggregator 1 time. 
Presolve time =    0.00 sec. (0.00 ticks)
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: none, using 1 thread.
Root relaxation solution time = 0.00 sec (0.00 ticks)

         Nodes                                 Cuts/   
   Node  Left     Objective  IInf  Best Integer     Best Bound    ItCnt    Gap
*     0+    0                            0.0000     3261.8212        8     ---
*     0+    0                         3148.0000     3261.8212        8    3.62%
      0     0     3254.5370     7     3148.0000       Cuts: 5       14    3.38%
      0     0     3246.0185     7     3148.0000       Cuts: 3       24    3.11%
*     0+    0                         3158.0000     3246.0185       24    2.79%
      0     0     3245.3465     9     3158.0000       Cuts: 5       27    2.77%
      0     0     3243.4477     9     3158.0000       Cuts: 5       32    2.71%
      0     0     3242.9809    10     3158.0000     Covers: 3       36    2.69%
      0     0     3242.8397    11     3158.0000     Covers: 1       37    2.69%
      0     0     3242.7428    11     3158.0000       Cuts: 3       39    2.68%
      0     2     3242.7428    11     3158.0000     3242.7428       39    2.68%
     10    11     3199.1875     2     3158.0000     3215.1261       73    1.81%
*    20+   11                         3168.0000     3215.1261       89    1.49%
     20    13     3179.0028     5     3168.0000     3215.1261       89    1.49%
     30    15     3179.9091     3     3168.0000     3197.5227      113    0.93%
*    39     3      integral     0     3186.0000     3197.3990      126    0.36%
     40     3     3193.7500     1     3186.0000     3197.3990      128    0.36% 

Cover cuts applied:  9
Zero-half cuts applied:  2
Gomory fractional cuts applied:  1

Solution pool: 5 solutions saved. 
MIP-Integer optimal solution:  Objective =   3.1860000000e+03
Solution time =    0.01 sec.  (0.00 ticks)  Iterations = 131   Nodes = 44

The first and the second columns most likely are what you are looking for. In the above example, CPLEX found the optimal objective function value of 3.1860000000e+03 after exploring 44 nodes and performing 131 (dual simplex) iterations. Also, as far as I know, the log information can still be invoked through the optimization process via its appropriate callbacks.

$\endgroup$
4
  • $\begingroup$ For more details please, see this link. $\endgroup$
    – A.Omidi
    Oct 2, 2023 at 8:04
  • $\begingroup$ Many thanks A.Omidi. Since I am running optimization processes in a loop that is why I think of callbacks commands to get them Do you have any idea for it? $\endgroup$ Oct 3, 2023 at 6:32
  • $\begingroup$ @MohammadSamiullah, I do not have more experience with log callback, but I think what you are looking for would be an informational callback. Also, this link is a good starting point. Also, mipex4.py in your CPLEX directory is an introduction to this. $\endgroup$
    – A.Omidi
    Oct 3, 2023 at 7:27
  • $\begingroup$ Thank you so much, A.Omidi. $\endgroup$ Oct 4, 2023 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.