Decision Optimization

 View Only

Cplex Python API vs docplex lhs.add

  • 1.  Cplex Python API vs docplex lhs.add

    Posted Fri March 10, 2023 08:27 AM
    Edited by s charaf Fri March 10, 2023 08:28 AM

    I moved from docplex to CPLEX Python API and I see that 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 cs.lhs += var

    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 cplx.variables.add(columns=[[[4, 5],[-1, -1]]], names=['Alpha_4', 'Alpha_5'])

    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.

    I am doing this in a branch and price fashion so this is a small example. I noticed that docplex is quite slow when it comes to adding variables to a constraint. So I moved to CPLEX Python API however the results are different, and I need to replicate the same results.
    Is there a way to add the new variables in CPLEX Python API in the same order as in docplex? thanks



    ------------------------------

    ------------------------------