Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Cplex API: .Solve()

    Posted 05/25/20 02:10 AM
    Hello,

    I built a .lp model through CPLEX API, and then solved it directly through CPLEX API .Solve() in the same C# project. I set the MIP tolerance mipgap as 0 and time limit one hour to solve the problem, but it couldn't output an optimal solution in time.

    I tried to solve the same .lp model, which is generated from the same C# project, by command line (Interactive) with same mipgap and time limit setting, and then it only took less than 10 minutes to get the optimal. 

    Besides, I had another case that it took 6 minutes through .Solve() and 2 minutes through command line by solving the same .lp model.

    I would like to know what's the difference in solving the same model between CPLEX API .Solve() and command line (Interactive)?
    How can I solve the model efficiently by calling CPLEX API .Solve() in C# project same as via command line?

    ------------------------------
    Chia-Yuan Wu
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Cplex API: .Solve()

    Posted 05/25/20 02:22 AM
    *Log of solving model via API .Solve():

    CPXPARAM_TimeLimit 3600
    CPXPARAM_WorkMem 51200
    CPXPARAM_MIP_Tolerances_MIPGap 0
    CPXPARAM_MIP_Strategy_File 0
    Aggregator has done 225570 substitutions...
    Aggregator has done 227679 substitutions...
    Aggregator has done 227777 substitutions...
    Aggregator has done 227818 substitutions...
    Tried aggregator 31 times.
    MIP Presolve eliminated 585103 rows and 519182 columns.
    MIP Presolve added 1934 rows and 0 columns.
    MIP Presolve modified 138994 coefficients.
    Aggregator did 227820 substitutions.
    Reduced MIP has 544239 rows, 585253 columns, and 3045506 nonzeros.
    Reduced MIP has 26961 binaries, 0 generals, 0 SOSs, and 0 indicators.
    Presolve time = 64.64 sec. (41957.00 ticks)
    Found incumbent of value 1.7478287e+15 after 85.14 sec. (54626.22 ticks)
    Probing fixed 0 vars, tightened 81864 bounds.
    Probing time = 2.31 sec. (367.43 ticks)
    Tried aggregator 6 times.
    MIP Presolve eliminated 15637 rows and 8521 columns.
    MIP Presolve modified 25927 coefficients.
    Aggregator did 200 substitutions.
    Reduced MIP has 528402 rows, 576532 columns, and 3003279 nonzeros.
    Reduced MIP has 26952 binaries, 0 generals, 0 SOSs, and 0 indicators.
    Presolve time = 9.89 sec. (3102.10 ticks)
    Probing fixed 0 vars, tightened 1658 bounds.
    Probing time = 1.91 sec. (88.61 ticks)
    MIP emphasis: balance optimality and feasibility.
    MIP search method: dynamic search.
    Parallel mode: deterministic, using up to 24 threads.
    Root relaxation solution time = 51.86 sec. (17412.45 ticks)

    MIP Gap: 4.46337534065237E-06 when time's out (1 hour)

    *Log of solving model via command line:

    CPXPARAM_MIP_Tolerances_MIPGap 0
    Aggregator has done 225569 substitutions...
    Aggregator has done 227698 substitutions...
    Aggregator has done 227794 substitutions...
    Aggregator has done 227834 substitutions...
    Tried aggregator 31 times.
    MIP Presolve eliminated 585184 rows and 519274 columns.
    MIP Presolve added 1934 rows and 0 columns.
    MIP Presolve modified 139270 coefficients.
    Aggregator did 227837 substitutions.
    Reduced MIP has 544141 rows, 585144 columns, and 3045099 nonzeros.
    Reduced MIP has 26959 binaries, 0 generals, 0 SOSs, and 0 indicators.
    Presolve time = 61.23 sec. (42138.72 ticks)
    Found incumbent of value 1.7592866e+15 after 79.94 sec. (54124.77 ticks)
    Probing fixed 0 vars, tightened 81857 bounds.
    Probing time = 2.03 sec. (367.42 ticks)
    Tried aggregator 3 times.
    MIP Presolve eliminated 15638 rows and 8501 columns.
    MIP Presolve modified 25923 coefficients.
    Aggregator did 179 substitutions.
    Reduced MIP has 528324 rows, 576464 columns, and 3002949 nonzeros.
    Reduced MIP has 26948 binaries, 0 generals, 0 SOSs, and 0 indicators.
    Presolve time = 8.38 sec. (2237.69 ticks)
    Probing fixed 0 vars, tightened 1511 bounds.
    Probing time = 1.67 sec. (88.68 ticks)
    MIP emphasis: balance optimality and feasibility.
    MIP search method: dynamic search.
    Parallel mode: deterministic, using up to 24 threads.
    Root relaxation solution time = 51.77 sec. (18081.07 ticks)

    Nodes Cuts/
    Node Left Objective IInf Best Integer Best Bound ItCnt Gap

    * 0+ 0 1.08346e+14 -1.49830e+14 238.29%
    0 0 1.07650e+14 105 1.08346e+14 1.07650e+14 118106 0.64%
    * 0+ 0 1.07665e+14 1.07650e+14 0.01%
    0 0 1.07650e+14 61 1.07665e+14 Cuts: 506 118292 0.01%
    0 0 1.07650e+14 54 1.07665e+14 Cuts: 125 118469 0.01%
    * 0+ 0 1.07662e+14 1.07650e+14 0.01%
    0 0 1.07650e+14 53 1.07662e+14 Cuts: 57 118527 0.01%
    0 0 1.07650e+14 53 1.07662e+14 Cuts: 3 118530 0.01%
    * 0+ 0 1.07662e+14 1.07650e+14 0.01%
    * 0+ 0 1.07662e+14 1.07650e+14 0.01%
    * 0+ 0 1.07650e+14 1.07650e+14 0.00%
    0 2 1.07650e+14 53 1.07650e+14 1.07650e+14 118530 0.00%
    Elapsed time = 290.27 sec. (163933.47 ticks, tree = 0.01 MB, solutions = 7)
    1 3 1.07650e+14 52 1.07650e+14 1.07650e+14 118565 0.00%
    3 5 1.07650e+14 50 1.07650e+14 1.07650e+14 118603 0.00%
    4 3 1.07650e+14 52 1.07650e+14 1.07650e+14 118575 0.00%
    6 4 1.07650e+14 51 1.07650e+14 1.07650e+14 118584 0.00%
    9 5 1.07650e+14 50 1.07650e+14 1.07650e+14 118602 0.00%
    17 9 1.07650e+14 50 1.07650e+14 1.07650e+14 118747 0.00%
    27 12 1.07650e+14 49 1.07650e+14 1.07650e+14 118882 0.00%
    41 32 1.07650e+14 42 1.07650e+14 1.07650e+14 119172 0.00%
    52 10 1.07650e+14 50 1.07650e+14 1.07650e+14 118781 0.00%
    106 66 1.07650e+14 35 1.07650e+14 1.07650e+14 119510 0.00%
    Elapsed time = 303.58 sec. (167478.89 ticks, tree = 8.24 MB, solutions = 7)
    142 125 1.07650e+14 34 1.07650e+14 1.07650e+14 120012 0.00%
    * 143+ 47 1.07650e+14 1.07650e+14 0.00%
    * 146+ 95 1.07650e+14 1.07650e+14 0.00%
    * 156+ 75 1.07650e+14 1.07650e+14 0.00%
    177 111 1.07650e+14 42 1.07650e+14 1.07650e+14 119900 0.00%
    235 196 1.07650e+14 31 1.07650e+14 1.07650e+14 120401 0.00%
    251 211 1.07650e+14 32 1.07650e+14 1.07650e+14 120526 0.00%
    302 267 1.07650e+14 37 1.07650e+14 1.07650e+14 120855 0.00%
    365 319 1.07650e+14 35 1.07650e+14 1.07650e+14 121299 0.00%
    412 349 1.07650e+14 38 1.07650e+14 1.07650e+14 121599 0.00%
    * 414+ 251 1.07650e+14 1.07650e+14 0.00%
    * 440+ 324 1.07650e+14 1.07650e+14 0.00%
    449 376 1.07650e+14 26 1.07650e+14 1.07650e+14 122209 0.00%
    485 235 1.07650e+14 29 1.07650e+14 1.07650e+14 122298 0.00%
    542 218 1.07650e+14 35 1.07650e+14 1.07650e+14 122516 0.00%
    Elapsed time = 351.88 sec. (177196.72 ticks, tree = 15.47 MB, solutions = 34)
    587 222 1.07650e+14 20 1.07650e+14 1.07650e+14 122634 0.00%
    * 604+ 214 1.07650e+14 1.07650e+14 0.00%
    623 258 1.07650e+14 17 1.07650e+14 1.07650e+14 123109 0.00%
    676 291 1.07650e+14 24 1.07650e+14 1.07650e+14 123502 0.00%
    718 302 cutoff 1.07650e+14 1.07650e+14 124259 0.00%
    761 342 1.07650e+14 6 1.07650e+14 1.07650e+14 124787 0.00%
    * 787+ 308 1.07650e+14 1.07650e+14 0.00%
    800 359 1.07650e+14 11 1.07650e+14 1.07650e+14 125022 0.00%
    809 242 1.07650e+14 20 1.07650e+14 1.07650e+14 123056 0.00%
    810 236 1.07650e+14 1322 1.07650e+14 1.07650e+14 240600 0.00%
    812 351 1.07650e+14 1259 1.07650e+14 1.07650e+14 247747 0.00%
    813 310 1.07650e+14 20 1.07650e+14 1.07650e+14 121269 0.00%
    Elapsed time = 441.19 sec. (207102.65 ticks, tree = 0.01 MB, solutions = 47)
    814 235 1.07650e+14 1272 1.07650e+14 1.07650e+14 122264 0.00%
    816 275 1.07650e+14 1198 1.07650e+14 1.07650e+14 120879 0.00%
    817 220 1.07650e+14 1177 1.07650e+14 1.07650e+14 234483 0.00%

    Implied bound cuts applied: 12
    Flow cuts applied: 103
    Mixed integer rounding cuts applied: 141
    Gomory fractional cuts applied: 87

    Root node processing (before b&c):
    Real time = 285.15 sec. (163677.48 ticks)
    Parallel b&c, 24 threads:
    Real time = 173.83 sec. (54437.11 ticks)
    Sync time (average) = 32.47 sec.
    Wait time (average) = 3.10 sec.
    ------------
    Total (root+branch&cut) = 458.98 sec. (218114.60 ticks)

    Solution pool: 48 solutions saved.

    MIP - Integer optimal solution: Objective = 1.0764965208e+14
    Solution time = 459.00 sec. Iterations = 482413 Nodes = 818
    Deterministic time = 218118.41 ticks (475.20 ticks/sec)

    ------------------------------
    Chia-Yuan Wu
    ------------------------------



  • 3.  RE: Cplex API: .Solve()

    Posted 05/25/20 06:25 AM
    As you can see, different things happen in presolve depending on whether you solve with C# or the interactive. This indicates that you are not solving the same model. What happens if you export the model to SAV file format rather than LP format and then solve with the interactive? Also, what happens if you read the LP file into C# and then solve? Does this give the same behavior?

    The reported objective value is 1e14. That is huge. Are you using a lot of small and big numbers in your model? This might cause numerical issues which might also explain the differing behavior. Could you attach your model here? If not, could you at least show the output of
    CPLEX> disp prob stats
    from the interactive optimizer?

    ------------------------------
    Daniel Junglas
    ------------------------------



  • 4.  RE: Cplex API: .Solve()

    Posted 05/25/20 06:41 AM

    Hi Danial,

    Thanks for your reply!
    I can't understand that even that I solve via interactive, the .lp is from the C#, why the presolve is different? Why the model is not the same one?... Is it due to the different solving environment: interactive and C#? Is there any method to help me solve the model more efficient via C#?

    "What happens if you export the model to SAV file format rather than LP format and then solve with the interactive? Also, what happens if you read the LP file into C# and then solve? Does this give the same behavior?"

    ==> I will try this later and reply to you once I have the answer.

    Problem statistics are as following:

    Objective sense : Minimize
    Variables : 1332534 [Box: 1087703, Binary: 244831]
    Objective nonzeros : 167165
    Linear constraints : 1355228 [Less: 669232, Greater: 146277, Equal: 539719]
    Nonzeros : 5916751
    RHS nonzeros : 233146

    Variables : Min LB: 0.0000000 Max UB: 2.147484e+09
    Objective nonzeros : Min : 1.000000 Max : 3.716000e+07
    Linear constraints :
    Nonzeros : Min : 1.362212e-07 Max : 7341000.
    RHS nonzeros : Min : 1.000000 Max : 7341000.



    ------------------------------
    Chia-Yuan Wu
    ------------------------------



  • 5.  RE: Cplex API: .Solve()
    Best Answer

    Posted 05/25/20 06:54 AM
    Exporting to LP file format may truncate floating point numbers. So the numbers in the LP file may be different than what you have in memory in C#. The export may also change the order of variables. So you may not be solving the same model. Using SAV instead of LP avoids these issues.

    The statistics show that in your constraints you have numbers like 1e-7 and 1e6. Mixing numbers of this wide range (1e13) is almost guaranteed to cause numerical problems. You should try to narrow down that range.

    ------------------------------
    Daniel Junglas
    ------------------------------



  • 6.  RE: Cplex API: .Solve()

    Posted 05/26/20 01:55 AM
    Hi Daniel,

    "Exporting to LP file format may truncate floating point numbers." => Oh... Now, I get it!!

    I output .sav model from my C#, and then solve it via interactive. The presolve log is same as what I get from my C#, and the running time is long, too. This time, I believe it's the same model...

    I will refer to your suggestion and see if I can fix my model. Thanks, Danial.

    ------------------------------
    Chia-Yuan Wu
    ------------------------------