Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

cplexmilp in matlab

  • 1.  cplexmilp in matlab

    Posted Thu January 05, 2012 12:11 PM

    Originally posted by: adriana_v


    Hi,
    I am new to CPLEX. Currently, I am working with cplexmilp in Matlab . The displayed output is the following:
    exitflag=5;
    cplexstatus: 102
    cplexstatusstring: 'integer optimal, tolerance'
    iterations: 3681
    algorithm: 12
    time: 13.369
    message: 'Solution with numerical issues'.
    Exitflag =5, it is positive, hence I have a solutions, but with some numerical issues.
    My questions are: where can I find more information about what exitflag number means?
    Given that cplexstatus is 102 (aka solution with numerical issues), how much cautious should I be when I interpret the results.
    Is anything I can do to get the cplexstatus =101? I should specify that my optimization problem is large.
    I would appreciate any prompt reply.
    Thanks,
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: cplexmilp in matlab

    Posted Fri January 06, 2012 11:53 AM

    Originally posted by: EdKlotz


    > adriana_v wrote:
    > Hi,
    > I am new to CPLEX. Currently, I am working with cplexmilp in Matlab . The displayed output is the following:
    > exitflag=5;
    > cplexstatus: 102
    > cplexstatusstring: 'integer optimal, tolerance'
    > iterations: 3681
    > algorithm: 12
    > time: 13.369
    > message: 'Solution with numerical issues'.
    > Exitflag =5, it is positive, hence I have a solutions, but with some numerical issues.
    > My questions are: where can I find more information about what exitflag number means?
    > Given that cplexstatus is 102 (aka solution with numerical issues), how much cautious should I be when I interpret the results.
    > Is anything I can do to get the cplexstatus =101? I should specify that my optimization problem is large.
    > I would appreciate any prompt reply.
    > Thanks,
    CPLEX's optimization toolkit tries to mimic the MATLAB optimization functions as much as possible,
    so that user's of the MATLAB optimization functions can try the CPLEX optimizers simply by replacing
    the MATLAB optimization functions (e.g. linprog, bintprog, etc.) with the corresponding CPLEX
    optimization toolkit function. Unfortunately, sometimes there is no correspondence between the
    two, and the message you got here is one case. CPLEX statuses 102, 5 and 6 all map to the same
    exitflag value of 5 and message of "solution with numerical issues", but this message is more accurate
    for statuses 5 and 6. So, as long as your CPLEX status is 102, your solution is optimal within the
    MIP gap (the default being .0001) and you need not concern yourself with numerical issues. In
    this case I don't think you need to be concerned about the solution quality. However, if you want
    to confirm that, try exporting your model to a SAV file (using the 'ExportModel' option in
    cplexoptimset), running the SAV file in interactive CPLEX, and checking the solution quality
    there using the 'display solution quality' command.

    When using the optimization toolkit, if the CPLEX status and the associated message returned
    have different implications regarding the final result, I recommend you pay closer attention
    to the CPLEX status. Nonetheless, we'll have a look at this and see if we can clarify the
    correspondence in this case.

    Regarding obtaining status 101 instead of 102, try reducing the relative MIP gap parameter from
    its default value of .0001 to 0. This may require additional nodes in the branch and bound
    algorithm, but in most cases that increase in computational effort is not excessive.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: cplexmilp in matlab

    Posted Sat January 07, 2012 12:23 AM

    Originally posted by: adriana_v


    hi,
    thanks for replying and suggestions.
    I run Cplex interactive ( it takes much less time to run than in Matlab). Matlab takes around 20 minutes to display the solution.
    I have some additional questions.
    One of the messages Matlab displays is:
    Nodes Cuts/
    Node Left Objective IInf Best Integer Best Bound ItCnt Gap

    • 0+ 0 1.07350e+008 3634 ---
    • 0+ 0 5.20382e+007 3634 ---
    0 0 7159021.8036 2 5.20382e+007 7159021.8036 3634 86.24%
    • 0+ 0 7159194.7016 7159021.8036 3634 0.00%

    How should I interpret the Gap value of 86.24%.

    Cplex Interactive displays the following:
    <header
    problemName="finet.lp"
    solutionName="incumbent"
    solutionIndex="-1"
    objectiveValue="7159194.70163"
    solutionTypeValue="3"
    solutionTypeString="primal"
    solutionStatusValue="102"
    solutionStatusString="integer optimal, tolerance"
    solutionMethodString="mip"
    primalFeasible="1"
    dualFeasible="0"
    MIPNodes="0"
    MIPIterations="3633"
    writeLevel="1"/>
    <quality
    epInt="1e-05"
    epRHS="1e-06"
    maxIntInfeas="0"
    maxPrimalInfeas="8.48134277031676e-07"
    maxX="4.8188"
    maxSlack="8.48134277031676e-07"/>

    The second question would be how should I interpret 'solutionIndex="-1"'

    Thanks again,
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: cplexmilp in matlab

    Posted Mon January 09, 2012 02:25 AM

    Originally posted by: SystemAdmin


    The gap displayed in the log (86.24%) is the relative difference between the best integer feasible solution (5.20382e+007) seen so far and the minimum of the optimal solution of all the LP relaxations of all open nodes (7159021.8036). The definition of this can be found in the reference documentation here:
    |bestnode-bestinteger|/(1e-10+|bestinteger|)
    


    The XML output you quoted is from a '.sol' file that you created from the optimal solution, correct?
    The first thing I see is that your model file seems to be an LP file (finet.lp), not a SAV file as Ed suggested. Exporting a model from matlab into an LP file may introduce small round-off errors, re-ordering of variables etc. These minor changes may result in dramatic changes of solution times and this may be the reason why interactive is much faster than matlab: you are just solving to (slightly) different problems.
    The "solutionIndex" attribute provides an index into the solution pool of CPLEX. By default CPLEX keeps all solutions it finds in the solution pool. The best solution found is the incumbent solution and is stored at index -1. If you want to store all solutions found you can use
    write solutions.sol all
    

    In the created file you will see the best solution with solutionIndex=-1 and other solution with index 0, 1, etc.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: cplexmilp in matlab

    Posted Mon January 09, 2012 10:38 AM

    Originally posted by: EdKlotz


    > The first thing I see is that your model file seems to be an LP file (finet.lp), not a SAV file as Ed suggested. Exporting a model from matlab into an LP file may introduce small round-off errors, re-ordering of variables etc. These minor changes may result in dramatic changes of solution times and this may be the reason why interactive is much faster than matlab: you are just solving to (slightly) different problems.
    To see if this indeed explains the difference in performance you see, compare the node logs of
    the MATLAB run with the interactive CPLEX run. By examining how the branch and cut algorithm
    diverged in the two runs, you can often assess what happened. Looking at the optimization output posted so far, we
    do see that solutions are found by node heuristics. Heuristics depend on the integer infeasibilities
    of the node relaxation solutions at which they are applied. So, models where heuristics are essential
    to finishing the optimization tend to show more performance variability.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: cplexmilp in matlab

    Posted Mon January 09, 2012 11:37 AM

    Originally posted by: adriana_v


    Thanks again. It took me a while to figure it out I was using the LP format and how to set the migap=0. Here is the Interactive Cplex output

    <?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
    <CPLEXSolutions version="1.2">
    <CPLEXSolution version="1.2">
    <header
    problemName="trading.sav"
    solutionName="incumbent"
    solutionIndex="-1"
    objectiveValue="7159021.8035918"
    solutionTypeValue="3"
    solutionTypeString="primal"
    solutionStatusValue="101"
    solutionStatusString="integer optimal solution"
    solutionMethodString="mip"
    primalFeasible="1"
    dualFeasible="1"
    MIPNodes="138420"
    MIPIterations="157708"
    writeLevel="1"/>
    <quality
    epInt="1e-05"
    epRHS="1e-06"
    maxIntInfeas="4.56572625877128e-06"
    maxPrimalInfeas="1.000001415008e-09"
    maxX="4.8188"
    maxSlack="1.000001415008e-09"/>

    At the same time, in Matlab, following Edd's suggestion I tried to set up the the mipgap=0 (I am trying to get the 101 status).
    I did the following:
    the toolbox case
    options = cplexoptimset('Diagnostics', 'on', 'TolXInteger', 0);
    xt, fval, exitflag, output] = cplexmilp(C,Aineq,Bineq,Aeq,Beq,[,],[,lb,ub,ctype,[],options)
    the API model:
    cplex=Cplex('finetrading1');
    cplex.Model.name = 'finetrading1';
    cplex.Model.obj = C; % your objective vector
    cplex.Model.A = Aineq; Aeq;
    cplex.Model.lhs = -inf*ones(size(Bineq)); Beq;
    cplex.Model.rhs = Bineq;Beq;
    cplex.Model.ctype =ctype;
    cplex.Model.lb = lb; % if you don't have variable lower bounds
    cplex.Model.ub = ub; % if you don't have variable upper bounds

    cplex.Parm.mip.tolerances.miprelgap.Cur=0;
    cplex.solve()

    In spite of these (cplex.Parm.mip.tolerances.miprelgap.Cur=0; and 'TolXInteger', 0), the solution status is the same , 102. Do I have to increase the number of nodes , too?

    I managed to read the solution from .sol file in Matlab, but it would more handier to get the solution directly from Matlab.

    Thanks,
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: cplexmilp in matlab

    Posted Mon January 09, 2012 11:56 AM

    Originally posted by: SystemAdmin


    'TolXInteger' is not what you want, I think. I think you need
    options = cplexoptimset('Diagnostics', 'on', 'mip.tolerances.mipgap', 0);
    

    to set the relative MIP gap parameter. Maybe even
    options = cplexoptimset('Diagnostics', 'on', 'mip.tolerances.mipgap', 0, 'mip.tolerances.absmipgap', 0);
    

    to set the absolute gap to 0 as well. Can you try this? Does it work any better?
    As long as you do not specify a node limit yourself there is no node limit. So there should be no need to increase that.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: cplexmilp in matlab

    Posted Mon January 09, 2012 04:12 PM

    Originally posted by: adriana_v


    None of these suggestions works, the solution status is unchanged 102.
    A side question , the kappa number displayed by cplex interactive is 9.4482e+11, and the percent of stable basis is 98.97, while the percentage of suspicious bases is .97, and the unstable one 0.06% (324 ). How should I read these numbers.
    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: cplexmilp in matlab

    Posted Tue January 10, 2012 01:29 AM

    Originally posted by: John Cui


    How about this kind options:
    options = cplexoptimset('cplex');
    options.mip.tolerances.absmipgap = 0;
    options.mip.tolerances.mipgap = 0;
    


    Then use this options to cplexmilp.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: cplexmilp in matlab

    Posted Tue January 10, 2012 10:34 AM

    Originally posted by: adriana_v


    Hi,
    I tried your suggestions, instead of
    options = cplexoptimset('Diagnostics', 'on', 'mip.tolerances.mipgap', 0, 'mip.tolerances.absmipgap', 0);
    I used

    options = cplexoptimset('cplex');
    options.mip.tolerances.absmipgap = 0;
    options.mip.tolerances.mipgap = 0;

    and it... works (exitflag =1; status 101). However, something strange happens (at least for me).

    Next, I tried options = cplexoptimset('mip.tolerances.mipgap', 0, 'mip.tolerances.absmipgap', 0); without Diagnostic options. It works too. But as soon as I add 'Diagnostics', 'on' or 'Display' 'iter', I am back to the 102 status. Plus, with either of these two options, the solution converges must faster than without having them.

    Thanks, your are doing such a wonderful job helping people like me.
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: cplexmilp in matlab

    Posted Tue January 10, 2012 10:42 AM

    Originally posted by: John Cui


    Then how about replace Diagnostic by diagnostic?
    Because we provide 2 kind options to users, one is cplexoptimset(); the other is cplexoptimset('cplex').
    If you use the return value of cplexoptimset(), you should use Diagnostic, but if you use cplexoptimset('cplex'), you should use diagnostic.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: cplexmilp in matlab

    Posted Tue January 10, 2012 12:14 PM

    Originally posted by: SystemAdmin


    Does any of the following work:
    options = cplexoptimset('diagnostics', 'on', 'mip.tolerances.migap', 0, 'mip.tolerances.absmipgap', 0);
    

    or
    options = cplexoptimset('cplex');
    options.diagnostics = 'on';
    options.mip.tolerances.mipgap = 0;
    options.mip.tolerances.absmipgap = 0;
    

    Note that lower case 'd' in 'diagnostics' (like John mentioned).
    If you specify one of the parameters in the 'xxx.yyy.zzz.' format (as in the first code snippet) you have to use lower case 'd'.
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: cplexmilp in matlab

    Posted Tue January 10, 2012 12:55 PM

    Originally posted by: adriana_v


    It works!!! Thank you,
    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  cplexmilp and Langragian multipliers

    Posted Tue April 10, 2012 10:41 AM

    Originally posted by: adriana_v


    Could anyone tell me how to display the Lagrangian multipliers for cplexmilp? (Matlab and interactive interface)

    Thank you,
    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: cplexmilp and Langragian multipliers

    Posted Tue April 10, 2012 01:07 PM

    Originally posted by: T_O


    Are you talking about pure linear programs or (mixed-)integer linear programs?

    Remember that there is no (easy) duality theory for the latter ones, so you cannot obtain useful dual variables.

    Best regards,
    Thomas
    #CPLEXOptimizers
    #DecisionOptimization