Skip to main content

Different Optimal Solutions from Equivalent Quadratic and Direct Formulations

Answered

Comments

2 comments

  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    Hi Muhamad,

    It is possible that the optimal solution point is the same but the objective value is different. A trivial example would be an objective with and without a constant.

    What you should check first is whether the optimal solution point is the same for both formulations. This means that you should solve formulation 1 and save the optimal solution values and then solve formulation 2 and check the solution point values against the ones of the first optimization. This can be done in a similar manner to the following pseudo code.

    # formulation 1
    # ...
    model.optimize()

    # save optimal solution for formulation 1
    sol_formulation_1 = model.getAttr("X", model.getVars())

    model.reset()
    # formulation 2
    # ...
    model.optimize()

    # save optimal solution for formulation 2
    sol_formulation_2 = model.getAttr("X", model.getVars())

    for i in range(0, len(sol_formulation_1)):
    if (math.abs(sol_formulation_1[i] - sol_formulation_2[i]) > 2e-5):
    print("SOLUTION NOT EQUAL")

    Since you did not change the contraints, the optimal solution point of each formulation has to be feasible in the other one. You could use the solution of the first formulation as a MIP Start for the second one to check it's value.

    Just to be sure, please always use the latest Gurobi version if possible.

    Best regards,
    Jaromił

    0
  • Muhamad Fikri
    • Gurobi-versary
    • Curious
    • Conversationalist

    Hi Jaromil,

    Thank you for your insight and suggestion!

    I managed to get the quadratic form to have the same optimal solution as the direct form by ignoring the Kronecker product.

    It is hilarious to know, as I thought using Kronecker product could simplify the expression and has no significant difference in the optimal solution.

    But it really does, even though I can confirm the version with Kronecker product is equivalent to the direct form.

    Thank you once again!

    0

Please sign in to leave a comment.