Skip to main content

Difference objective function in code yields difference result which one is the correct one?

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
  • Marika Karbstein
    • Gurobi Staff

    In your code (version 1), you have model.setObjective() before the model definition model=gp.Model(). If you do not get an error, the model object is probably defined earlier (as well as variables delta_ij). With the next call model=gp.Model(), the model is overwritten, i.e., an empty model is created.
    So, I guess in the first version you have a 0 objective, and in the second version the objective is considered.

    To troubleshoot, I would recommend writing your model into an LP file with model.write("Test.lp") directly before calling model.optimize(). In this way, you can check what model is actually optimized and you could compare the lp files (name them differently) for both of your versions.

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

    Hi, Thank you for your reply and insight.

    I already solve the problem after troubleshooting again. Thank you for the direction once again!

    0

Post is closed for comments.