Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Hoe to add several quadratic constraints using cplex for matlab

    Posted Tue January 18, 2011 08:41 PM

    Originally posted by: sarahD


    Hi!
    I use the matlab interfaces (toolbox and API) for mixed integer quadratically constrained problems in CPLEX 12.2. I am not sure how to add quadratic constraints, if there is more than one.

    1) For the Toolbox: How can I specify more than one matrix Q for cplexmiqcp.m ?
    2) For API: How do I generate a higher dimensional struct array of the type cplex.Model.qc which I can then access using cplex.Model.qc(i)?

    The examples given in the documentation unfortunately cover only single quadratic constraints!

    Thanks a lot for your help!

    Sarah
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Hoe to add several quadratic constraints using cplex for matlab

    Posted Tue January 18, 2011 08:55 PM

    Originally posted by: John Cui


    Could you please refer to below thread:
    http://www.ibm.com/developerworks/forums/thread.jspa?threadID=357875&tstart=0

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Hoe to add several quadratic constraints using cplex for matlab

    Posted Tue January 18, 2011 08:58 PM

    Originally posted by: John Cui


    For Cplex class, you can do like:
    cplex=Cplex();
    cplex.addCols([1 2 3]', [], [0 0 0]', [40 inf inf]');
    cplex.addRows(-inf, [-1  1 1], 20);
    cplex.addRows(-inf, [ 1 -3 1], 30);
    cplex.addQCs([0 0 0]', [1 0 0;0 1 0;0 0 1], 'L', 1.0);
    cplex.addQCs([0 0 0]', [1 0 0;0 1 0;0 0 1], 'L', 1.0,{'myqc2'});
    cplex.addQCs([0 0 0]', [1 0 0;0 1 0;0 0 1], 'L', 1.0);
    cplex.solve();
    


    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Hoe to add several quadratic constraints using cplex for matlab

    Posted Tue January 18, 2011 09:05 PM

    Originally posted by: John Cui


    or
    cplex.addQCs(
                     [0 0 0;1 0 0;0 1 0]',
                     {[1 0 0;0 1 0;0 0 1]
                      [1 0 0;0 1 0;0 0 1]
                      [1 0 0;0 1 0;0 0 1]},
                     'LLG',
                     [1.0 2.0 3.0],
                     {'qc1' 'qc2' 'qc3'});
    


    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  socp constraints ?

    Posted Wed January 19, 2011 09:15 PM

    Originally posted by: sarahD


    Hi again,

    First, thanks a lot, it works fine with addQCs for standard quadratic constraints. !

    But I have another question:
    As stated in the documentation, the solver detects socp constraints when given by quadratic constraints with matrices like
    -1 0 0
    0 1 0
    0 0 1
    although these matrices are nor positive semidefinite.
    For my examples, this works just under certain circumstences, hence for a single socp constraint, and only in case that the first variable belongs to this socp constraint.

    So, I works for one quadratic (socp) constraint with
    l=0, r=0, Q=

    -1 0 0 0 0 0 0 0
    0 1 0 0 0 0 0 0
    0 0 1 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0

    But not if I add a second matrix, eg:
    l2=0, r2=0,
    Q2 = 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 -1 0 0 0 0
    0 0 0 0 1 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0

    Or it also does not work for one constraint like
    l=0, r=0, Q=

    0 0 0 0 0 0 0 0
    0 -1 0 0 0 0 0 0
    0 0 1 0 0 0 0 0
    0 0 0 1 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0

    For the last two cases cplex states:
    'CPLEX Error 5002: Q in 'q2' is not positive semi-definite.'

    Can you help me? Is there a way to add several socp constraints?

    Thanks a lot!!!
    Best, Sarah
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: socp constraints ?

    Posted Wed January 19, 2011 09:55 PM

    Originally posted by: John Cui


    What I just tried:
    cplex=Cplex();
    cplex.addCols([1 2 3]', [], [0 0 0]', [40 inf inf]');
    cplex.addRows(-inf, [-1  1 1], 20);
    cplex.addRows(-inf, [ 1 -3 1], 30);
    cplex.addQCs([0 0 0]', [1 0 0;0 1 0;0 0 1], 'L', 1.0);
    cplex.addQCs([0 0 0]', [0 0 0;0 -1 0;0 0 1], 'L', 0.0,{'myqc2'});
    cplex.addQCs([0 0 0]', [-1 0 0;0 0 0;0 0 1], 'L', 0.0,{'myqc3'});
    cplex.writeModel('qc.lp')
    cplex.solve();
    


    which works fine and export below lp file:
    \Problem name: CPLEX
     
    Minimize
     obj: x1 + 2 x2 + 3 x3
    Subject To
     c1: - x1 + x2 + x3 <= 20
     c2: x1 - 3 x2 + x3 <= 30
     qc1:   [ x1 ^2 + x2 ^2 + x3 ^2 ] <= 1
     myqc2: [ - x2 ^2 + x3 ^2 ] <= 0
     myqc3: [ - x1 ^2 + x3 ^2 ] <= 0
    Bounds
     0 <= x1 <= 40
    End
    


    You got the non-psd error, because your constraints are not PSD.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: socp constraints ?

    Posted Wed January 19, 2011 10:35 PM

    Originally posted by: sarahD


    Hi!

    Investigating the printed LP- model showed that the bounds got lost on the way in my program...
    The quadratic constraint with Q=(-1000
    0100
    0010
    0001)
    is of course only an SOCP- constraints, if the first variable (with coefficient '-1') is nonnegative ;-)

    Awesome, thanks again!

    Best, Sarah
    #CPLEXOptimizers
    #DecisionOptimization