Decision Optimization

 View Only
  • 1.  Cplex Python API clean before re-optimizing

    Posted Mon March 06, 2023 02:50 PM
    Edited by s charaf Mon March 06, 2023 02:50 PM

    I moved from docplex to CPLEX Python API, and I want to know what is the equivalent of the clean_before_solve option in CPLEX Python API. I need this as I want to have the same results again, and I noticed that the dual variables are not the same after model re-optimization.

  • 2.  RE: Cplex Python API clean before re-optimizing

    Posted Tue March 07, 2023 02:44 AM

    Here is the method in docplex that you need to copy/paste in your code:

    cpx = self._cplex
    if cpx._is_MIP():
    # clear the pool
    # dummy change
    if cpx.variables.get_num() > 0:
    cpx.variables.set_lower_bounds(0, cpx.variables.get_lower_bounds(0))
    elif cpx.linear_constraints.get_num() > 0:
    cpx.linear_constraints.set_senses(0, cpx.linear_constraints.get_senses(0))

    Vincent Beraudier

  • 3.  RE: Cplex Python API clean before re-optimizing

    Posted Thu March 09, 2023 06:47 AM

    Thanks !

    I see that even after using this method, the results are not the same. I compared the two LP files and I noticed that when adding new variables to a constraint in the Python API they are usually added at the end of the lhs whereas in docplex they are added at the beginning. 

    example : using docplex

    Psi_1_3_0 + Psi_1_3_1 + Psi_1_3_2 + Psi_1_3_3 - 93 Alpha_4
                - 57 Alpha_5  - 35 Alpha_1 - 24 Alpha_3 = 0

    using CPLEX Python API

    Psi_1_3_0 + Psi_1_3_1 + Psi_1_3_2 + Psi_1_3_3 - 35 Alpha_1
              - 24 Alpha_3 - 93 Alpha_4 - 57 Alpha_5  = 0

    where alpha_4 and alpha_5 are new variables and were added to that constraint after the creation of that constraint.

    Is there a way to add the new variables in CPLEX Python API in the same order as in docplex? thanks