Decision Optimization

 View Only

How to obtain nodes count and nodes left in docplex (using CPLEX 12.20 and Python 3.8)

  • 1.  How to obtain nodes count and nodes left in docplex (using CPLEX 12.20 and Python 3.8)

    Posted Fri September 29, 2023 12:56 AM
    Hello everyone,

    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]+4*x_vars[2]>=-5)
    my_MILP.add_constraint(x_vars[1]-y_vars[2]<=5)
    my_MILP.add_constraint(x_vars[1]+3*y_vars[1]-10*y_vars[2]<=10)
    my_MILP.add_constraint(x_vars[1]+2*x_vars[2]-3*y_vars[1]+4*y_vars[2]<=2)

    # Defining objective function:
    obj=x_vars[1]+5*x_vars[2]+6*y_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