Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  DOCplex (Python): Change variable type

    Posted 06/06/18 10:43 AM

    Originally posted by: Dickiedoda


    I've created a MIP model using DOCplex (Python) and I'm interested in obtaining the continuous relaxation value so that I can compute the integrality gap. Is there a method to change the variable type from binary to continuous?  I know this can be accomplished in the Python API, but I cannot find a method in DOCplex to convert a variable type.  Specifically, I'm declaring  x = m.binary_var_list(n), and I would like to convert this to continuous variable list so that I can resolve to obtain the continuous relaxation.

     

    However, if there is an easier way to obtain the continuous relaxation (root node) value that would be great.

     

    Thanks!


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: DOCplex (Python): Change variable type

    Posted 06/07/18 12:49 PM

    Originally posted by: Dickiedoda


    Well I managed to answer my own question so I figured I would post the solution.  The model was defined as:

     

    m = Model(name='linearization')
    x = m.binary_var_list(n)

    ...

    After solving the MIP I converted the binary variables to continuous as follows:

     

    for i in range(n):
         m.set_var_type(x[i],m.continuous_vartype)

     

    I then resolve to obtain the continuous relaxation which I used to compute the integrality gap.

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: DOCplex (Python): Change variable type

    Posted 06/08/18 03:53 AM

    I am glad you figured this out but I am wondering whether it is actually necessary to do that. After solving the MIP, the dual bound should be available in m.get_solve_details() as m.get_solve_details().best_bound.

    This bounds includes cuts etc. so it might be better than what you get from the pure relaxation. Also, solving the model as LP is not exactly the same as getting the value of the initial relaxation for the MIP: MIP presolve can do more things than LP presolve since it can exploit integrality of variables. Hence the bound you get from the initial LP relaxation in MIP may be better than what you get by just solving the model with the relaxed variables.


    #CPLEXOptimizers
    #DecisionOptimization