Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Optimal solutions

  • 1.  Optimal solutions

    Posted 02/17/11 09:07 AM

    Originally posted by: pfaut


    Hello,

    How can I assure, that the solution cplex computed is optimal?
    My current method is minimizing the sum of a number of integer variables (which are restricted to 0 and 1). And attempts to detect all possible alternate solutions (using the populate method).

    I then add constraints which remove these solutions from the possible solutions to the problem, and solve it again.

    This should (to my understanding) lead to a constantly rising objective value in each 'iteration'.

    What happened now is the following:
    I got solutions with objective 2,3 and 4. After adding the constraints a new solution with objective 3 was found.

    I'm programming using the c++ api and have the following parameters which are not set to default:
    cplex.setParam(IloCplex::RootAlg, IloCplex::MIP);
    cplex.setParam(IloCplex::NodeAlg, IloCplex::MIP);
    cplex.setParam(IloCplex::EpRHS, 1e-9);
    cplex.setParam(IloCplex::ParallelMode, IloCplex::Opportunistic);
    cplex.setParam(IloCplex::MIPEmphasis, IloCplex::MIPEmphasisOptimality);
    cplex.setParam(IloCplex::SolnPoolAGap, 0);
    cplex.setParam(IloCplex::PopulateLim, 210000);
    cplex.setParam(IloCplex::SolnPoolIntensity, 4);
    cplex.setParam(IloCplex::SolnPoolCapacity, 210000);

    Does anyone have any Idea, what could go wrong or suggest any way how I could assure, that the solution is surely optimal?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Optimal solutions

    Posted 02/18/11 01:14 AM

    Originally posted by: SystemAdmin


    First, my apologies if I am misunderstanding your question. The process you describe sounds like a technique often used in the field of Constraint Programming (CP). If by chance you are coming at this problem from a CP point of view, you might be better served by trying the CP Optimizer engine that is a part of the IBM ILOG CPLEX Optimization Studio. The Forum for that engine is found at http://www.ibm.com/developerworks/forums/forum.jspa?forumID=2066 and you might wish to re-post your question there.

    I will assume from here on that you do actually mean to use Mathematical Programming techniques traditionally associated with CPLEX, and also that the process you described is being done for research purposes. If, in your initial question, you simply want CPLEX to determine an optimal solution, I'll risk stating the obvious that it is necessary only to declare the constraints and the objective function, and then call the solve() function, rather than constructing your own search algorithm using function populate().

    In the process you described, with the parameter settings as you show, I would expect more than three integer feasible solutions to be found by a single call to populate(). If indeed only three were found, then that would mean only three exist. When you then add constraints that remove these solutions, the result from the next call to the populate() function should be a declaration of infeasibility, not a new solution.

    Let me illustrate with a very trivial example:

    Maximize
    x+y
    subject to
    binaries
    x y
    end

    This has four feasible solutions, (0,0), (0,1), (1,0), and (1,1). Under the maximum setting of the pool intensity parameter, as you have indicated, the populate function does find all four of these solutions. If I next add the following constraints to remove these solutions ...
    -x-y<=-1
    -x+y<=0
    x-y<=0
    x+y<=1
    ... it results in an infeasible model. If I omit any one of these four constraints, the associated solution is again feasible to this restricted model.

    So, I don't understand how you got a feasible model if you added constraints that remove all the solutions found by populate() under its aggressive setting.

    Now, on most models, it is not practical to attempt to generate all feasible solutions - there will be combinatorially many of them. If you run populate() for a while, stop and eliminate via new constraints the solutions that were found, and then run again, there won't be any guarantee of a constantly improving objective function, because it is not predictable in which order populate will find solutions, and also because a model may contain multiple solutions with a given objective function value. In the above example, with the populate limit set to 1 for explanatory purposes, populate could happen to find the solution (1,0) first, giving an objective function value of 1. If x-y<=0 is added to the model, the next call to populate might happen to find (0,0) or (0,1), giving either a worse answer or an answer of equal quality to the one just eliminated, or it might find (1,1).

    (On such a simple example, the above order of solutions found isn't likely, but the point is that you can't predict the ordering.)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Optimal solutions

    Posted 02/18/11 04:24 AM

    Originally posted by: SystemAdmin


    John,

    I think that you missed the important parameter setting
    cplex.setParam(IloCplex::SolnPoolAGap, 0);
    


    Using this parameter setting in combination with the largest intensity and (virtually) infinite solution pool and populate limits should indeed give the required behavior, namely that each populate call will produce all optimal solutions of the current model. Thus, if you then explicitly exclude those solutions by adding constraints, the next populate call should yield all optimal solutions of the next quality level.

    Taking your example, if I do this in the interactive, I indeed get the intended behavior:
    CPLEX> enter
    Enter name for problem: test
    Enter new problem ['end' on a separate line terminates]:
    max x+y                                                 
    binaries                                                
    x                                                       
    y                                                       
    end                                                     
    CPLEX> set mip pool intens 4                            
    New value for intensity for populating the MIP solution pool: 4
    CPLEX> set mip lim pop 210000000                               
    New value for solutions limit for each populate call: 210000000
    CPLEX> set mip pool absgap 0                                   
    New value for absolute objective gap: 0                        
    CPLEX> pop                                                     
    ...
    CPLEX> disp sol list -
                                                 Change from
    Solution Name       Objective Value            Incumbent
    p1                           2.0000                0.00%
    CPLEX> add                                              
    Enter new constraints and bounds ['end' terminates]:    
    x+y <= 1                                                
    end                                                     
    Problem addition successful.                            
    CPLEX> pop                                              
    ...
    CPLEX> disp sol list -
                                                 Change from
    Solution Name       Objective Value            Incumbent
    p1                           1.0000                0.00%
    p2                           1.0000              100.00%
    CPLEX> add
    Enter new constraints and bounds ['end' terminates]:
    x - y <= 0
    -x + y <= 0
    end
    Problem addition successful.
    CPLEX> pop
    CPLEX> disp sol list -
                                                 Change from
    Solution Name       Objective Value            Incumbent
    p1                           0.0000                0.00%
    CPLEX> add
    Enter new constraints and bounds ['end' terminates]:
    x + y >= 1
    end
    Problem addition successful.
    CPLEX> pop
    ...
    Populate - Integer infeasible.
    


    Conclusion: there seems to be a bug somewhere, either in CPLEX or in the user code. We have to investigate this.
    To get started, it would be useful to save two MIPs as *.sav file to disk, namely the one for which populate returned a solution value of 4, and the next one for which, after adding additional constraints, populate returned a solution value of 3. Then, in the interactive CPLEX version we can check what the optimal solution values should be using a regular optimization.
    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Optimal solutions

    Posted 02/18/11 06:38 PM

    Originally posted by: SystemAdmin


    Tobias, thanks for cleaning up my mess. :)
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Optimal solutions

    Posted 02/25/11 09:46 AM

    Originally posted by: pfaut


    Any news yet?

    Or, as a possible fix to my problem: Is there a way to guarantee, that cplex will find the optimal solution apart from the MIPEmphasis/MIPEmphasisOptimality Parameter?
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Optimal solutions

    Posted 02/25/11 12:20 PM

    Originally posted by: SystemAdmin


    Sorry. I was very busy during this week and now I am sick and do not have enough brain power to deal with this properly. I hope I will find the time next week to look at your issue. From what you report, I am pretty sure that it is either a bug on our side, on your side, or a numerical issue.

    If anyone else is interested in this, please step in.
    Sorry for the delay...

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Optimal solutions

    Posted 02/18/11 04:29 AM

    Originally posted by: pfaut


    First of all, thanks for the answer. Probably I am asking in the wrong forum and I will post it on the other forum too.

    I understood, that the SolnPoolAGap parameter will, if set to zero, not allow any non optimal solution in the Solution pool (see : http://www-01.ibm.com/support/docview.wss?uid=swg21399929 ), since it should assure, that there is no gap in the objective function between the solutions in the pool.

    What I would like to do in your example is the following:

    In the first iteration the solver should find x=1,y=1 as the optimal solution and, given the gap constraint no additional solution should be returned by populate().
    After that iteration I would add the constraint:
    x+y <= 1
    and solve again finding 2 solutions (1,0) and (0,1) as optimal solutions with objective value 1.
    I will then add the constraints x<=0 and y<=0 and find the final solution (0,0) in the last iteration.

    However, given your example, for some reason cplex managed to find the solutions in the order (1,1), (0,1), (0,0), (1,0).

    (This will obviously not happen, if you solve this simple problem, but my problems are a little too complex to just state them.)

    For better understanding what happens:
    Problem 1:
    Maximize
    x+y
    subject to
    binaries
    x y
    end
    Solution: (1,1)

    Problem 2:
    Maximize
    x+y
    subject to
    x+y<=1
    binaries
    x y
    end
    Solution: (1,0)

    Problem 3:
    Maximize
    x+y
    subject to
    x+y<=1
    x<=0
    binaries
    x y
    end
    Solution: (0,0) <--- this is not correct since the Algorithm is bound to find the optimal solution and should therefore in this iteration find a solution with objective value 1 compared to the current 0

    Problem 4:
    Maximize
    x+y
    subject to
    x+y<=1
    x<=0
    x+y=>1
    binaries
    x y
    end
    Solution: (0,1) <-- this solution has objective value 1 again (which should have been found in iteration 2 (or in case populate was unable to find it it should have been found in iteration 3 instead of the (0,0) solution.)
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Optimal solutions

    Posted 02/18/11 04:31 AM

    Originally posted by: pfaut


    tobias:

    I will provide the problems as soon as possible. However I only got them in lp format and since I am using the opportunistic parameter I cannot guarantee that they will look the same if I rerun the program. In fact I cant guarantee, that cplex will reproduce the bug.
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Optimal solutions

    Posted 02/18/11 04:46 AM

    Originally posted by: SystemAdmin


    LP format is fine as well. Maybe at least for development mode you should switch to deterministic parallel mode. For deployment of your application, you should eventually test whether opportunistic parallel mode gives you a significant performance boost and switch modes if this is the case, but development is much simpler if things stay deterministic.
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Optimal solutions

    Posted 02/18/11 05:03 AM

    Originally posted by: pfaut


    Well, I switched to opportunistic after i noticed, that it was a lot faster in most cases on my problems. I will switch back and test if the same error appears again but for now I attached the respective problem and solution files. (the additional constraints that I include are the ones after the XYZ_Reverse constraints.)

    The code generating the Problem looks much like the following:
    The general problem is:
    max Sum(z_i)
    s.t.
    M*v = 0 (linear system)
    One int variable z_i restricted to 0 and 1 for each v_i;
    v_i are restricted to values between 0 and 99999 or -99999 and 99999 depending on some conditions;
    Four constraints for each v_i:
    IloIfThen bound(environment_, z_i == 0) , v_i == 0));
    IloIfThen bound(environment_, v_i == 0) , z_i == 0));

    IloIfThen bound(environment_, z_i == 1) , v_i != 0));
    IloIfThen bound(environment_, v_i != 0) , z_i == 1));

    Some additional constraints forbidding certain z_i combinations.

    Regards

    Thomas
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Optimal solutions

    Posted 02/18/11 05:06 AM

    Originally posted by: pfaut


    Oh and 1 constraint forcing at least 1 z_i to be 1.
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Optimal solutions

    Posted 02/18/11 05:43 AM

    Originally posted by: pfaut


    Ok, I rerun it with the deterministic mode. A similar problem occured even earlier with solutions of with objective 2 being found after solutions with objective 3.

    The lp files and the Solution files are attached.
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: Optimal solutions

    Posted 03/02/11 04:00 AM

    Originally posted by: SystemAdmin


    I tried to reproduce the issue but failed.

    As far as I understand, your problem is that CPLEX reports an optimal solution of value 3 to the problem "FurtherConstraints.lp" in your "Problem_Deterministic.tar.gz" tarball.

    I tried CPLEX 12.2.0.0 on an x86-64 Linux machine with 2 cores and the following parameter settings:
    emphasis mip 2                                              
    mip limits populate 210000                                  
    mip pool absgap 0                                           
    mip pool capacity 210000                                    
    mip pool intensity 4                                        
    simplex tolerances feasibility 1e-09
    

    Using the "optimize" command of the interactive, i.e., CPXmipopt() in the C API, CPLEX finds the optimal solution of value 2 after about 90 seconds and 2003 nodes.
    Maybe you are facing a numerical issue here. When activating the "mipkappa" feature of CPLEX 12.2, I observe the following condition number statistics:
    Incumbent solution:
    MILP objective                                 2.0000000000e+00
    MILP solution norm |x| (Total, Max)            9.06000e+03  1.00000e+00
    MILP solution error (Ax=b) (Total, Max)        3.94915e-19  2.42615e-19
    MILP x bound error (Total, Max)                3.01737e-09  4.44777e-10
    MILP x integrality error (Total, Max)          3.63709e-13  4.21885e-15
    MILP slack bound error (Total, Max)            7.27695e-14  7.27596e-14
    MILP indicator slack bound error (Total, Max)  9.08635e-08  4.44777e-10
     
    Branch-and-cut subproblem optimization:
    Max condition number:             1.1509e+17
    Percentage of stable bases:       15.9%
    Percentage of suspicious bases:   77.8%
    Percentage of unstable bases:     6.1%
    Percentage of ill-posed bases:    0.1%
    Attention level:                  0.027162
    CPLEX encountered numerical difficulties while solving this model.
    

    The solution looks pretty nice, but the condition numbers of the LP bases encountered during the MIP search are pretty large, which points to numerical difficulties.

    You have some pretty nasty indicator constraints in the model, namely if-and-only-if constraints that involve a continuous variable. For example:
    i1:    id32526 = 1 <-> R_12PPDt  = 0
    

    with continuous variable -99999 <= R_12PPDt <= 99999. The issue with such indicator constraints is that this is equivalent to
    i1a:   id32526 = 1 -> R_12PPDt  = 0
     i1b:   id32526 = 0 -> R_12PPDt != 0
    

    and the strict inequality in i1b cannot be modeled in the math programming framework (this can only deal with less-or-equal and greater-or-equal but not with strict less-than and greater-than). Therefore, CPLEX would interpret this as
    i1a:   id32526 = 1 -> R_12PPDt  = 0
     i1b:   id32526 = 0 -> (R_12PPDt <= -1e-3 or R_12PPDt >= 1e-3)
    

    The other source of numerical issues seems to come from the bounds 99999 of the variables. During presolve, they enter the constraint matrix, such that the presolved model has these statistics:
    Variables            :   12699  [Box: 1198,  Binary: 11501]
    Objective nonzeros   :    1369
    Linear constraints   :   10498  [Less: 5947,  Greater: 1780,  Equal: 2771]
      Nonzeros           :   27793
      RHS nonzeros       :    7629
    Indicator constraints:    8763  [Less: 4107,  Equal: 2328,  Greater: 2328]
      Complemented       :    1186
      Nonzeros           :    8763
      RHS nonzeros       :    4656
     
    Variables            : Min LB: -99999.00        Max UB: 99999.00
    Objective nonzeros   : Min   : 1.000000         Max   : 1.000000
    Linear constraints   :
      Nonzeros           : Min   : 0.0002000000     Max   : 9999.900
      RHS nonzeros       : Min   : 0.0002000000     Max   : 9999.900
    Indicator constraints:
      Nonzeros           : Min   : 1.000000         Max   : 1.000000
      RHS nonzeros       : Min   : 0.001000000      Max   : 0.001000000
    

    The pretty big range of 9999.9/0.0002 = 5e+7 for the non-zero coefficients may cause some headaches in the linear system solves.
    #CPLEXOptimizers
    #DecisionOptimization