Global AI and Data Science

Global AI & Data Science

Train, tune and distribute models with generative AI and machine learning capabilities

 View Only
Expand all | Collapse all

Strange issue with CPLEX - very different solutions if threads = 0 or 1

  • 1.  Strange issue with CPLEX - very different solutions if threads = 0 or 1

    Posted Mon November 06, 2023 05:12 PM
      |   view attached

    Hi, an IP model, in .lp format, is attached.

    I am getting a weird behaviour with this model: I'm on Ubuntu 22 with CPLEX 22.1.0.0. If I open cplex in terminal

    CPLEX> set threads 0
    New value for default parallel thread count: 0
    CPLEX> read bc_model.lp
    Problem 'bc_model.lp' read.
    Read time = 0.08 sec. (3.04 ticks)CPLEX> set threads 1
    New value for default parallel thread count: 1
    CPLEX> opt

    I get this solution:

    MIP - Integer optimal solution:  Objective = -2.5812367594e-03
    Solution time =    0.37 sec.  Iterations = 229  Nodes = 0
    Deterministic time = 325.28 ticks  (887.98 ticks/sec)

    Then if I do

    CPLEX> set threads 1
    New value for default parallel thread count: 1
    CPLEX> read bc_model.lp
    Problem 'bc_model.lp' read.
    Read time = 0.07 sec. (3.04 ticks)
    CPLEX> opt

    I get a completely different solution:

    MIP - Integer optimal, tolerance (0.0001/1e-06):  Objective = -4.6738470892e-03
    Current MIP best bound = -4.6733912388e-03 (gap = 4.5585e-07, 0.01%)
    Solution time =    1.33 sec.  Iterations = 1537  Nodes = 130 (14)
    Deterministic time = 1154.45 ticks  (868.27 ticks/sec)

    Why is that? I am only changing the number of threads, nothing else. The difference, -0.00467 to -0.00258 is well outside the default tolerance.

    Can anyone shed some light on why is this happening?

    Thanks!

    Cristiano



    ------------------------------
    Cristiano Arbex Valle
    ------------------------------


    #AIandDSSkills

    Attachment(s)

    lp
    bc_model.lp   8.25 MB 1 version


  • 2.  RE: Strange issue with CPLEX - very different solutions if threads = 0 or 1

    Posted Thu November 09, 2023 12:22 PM
    Edited by System Admin Fri July 26, 2024 02:22 PM

    Hello,

    There appear to be some numerical issues. The constraint "constC6" contains very small coefficients.  I would rescale it by multiplying all the coefficients by (say) 10^5.  In fact, when I do this, I get consistent results at around -2.58e-3.  Other constraints of the "constC5_*" variety could also be considered as rescaling candidates.

    Best regards,


    Paul



    ------------------------------
    Paul Shaw
    ------------------------------



  • 3.  RE: Strange issue with CPLEX - very different solutions if threads = 0 or 1

    Posted Thu November 09, 2023 01:37 PM

    Thank you very much, Paul.

    Indeed, I had tried after this message to simplify the model, with a different objective. It is a portfolio selection model with integrality constraints for lot sizes and transaction costs. This model tries to minimise Conditional Value-at-Risk. I then replaced it with maximising expected return, where the issue persisted. 

    But, with this simpler model, I came to the same conclusion! Some coefficients in the order of 1e-8 and others in the order of 1e9.

    Thank you very much!
    Best regards,
    Cristiano



    ------------------------------
    Cristiano Arbex Valle
    ------------------------------