Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

help~matlab cplex toolbox- cplexqcp - Quadratic constraints

  • 1.  help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Sun January 16, 2011 07:55 AM

    Originally posted by: SystemAdmin


    Hi,all
    I use cplex12.2 to solve a QCP problem under matlab cplex toolbox.
    when I write the Quadratic constraints,it says Too many input arguments.then I use 'cplexint' ,it's ok.
    I just write like this:
    QC(i).l=...;QC(i).r=...;QC(i).Q=...;
    x, fval, exitflag, output] = cplexqcp (H,f,Aineq,bineq,[,http://],QC.l,QC.Q, QC.r, lb,ub,[,options);

    I found if there is only one Quadratic constraint,it's ok;But if more than one,it's wrong.So I want to know how to write Quadratic constraints under cplex toolbox?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Sun January 16, 2011 10:17 PM

    Originally posted by: John Cui


    If you want to generate 3 QCs as below:

    QC(1).l = [0 0 0]'
    QC(1).Q = [1 0 0;0 1 0;0 0 1]
    QC(1).r = 1.0
     
    QC(2).l = [1 0 0]'
    QC(2).Q = [1 0 0;0 1 0;0 0 1]
    QC(2).r = 2.0
     
    QC(3).l = [0 1 0]'
    QC(3).Q = [1 0 0;0 1 0;0 0 1]
    QC(3).r = 3.0
    


    Then you should write l, Q, r by:
    l = [0 0 0;1 0 0;0 1 0]'
             Q = {[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]}
             r = [1.0 2.0 3.0]
    

    and pass them to cplexqcp or cplexmiqcp.

    Please give a try, and tell me the result, thanks.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Mon January 17, 2011 12:52 AM

    Originally posted by: SystemAdmin


    Hi,John Cui
    Thank you very much for your reply.
    In fact ,I just write the constraints as you write below.But,Unfortunately, it doesn't work.
    I use the matlab toolbox ,then it is wrong.I have used the another method in matlab ,just
    using statement'cplex.addQCs',it can be work.

    'Col,ng,nt 'is constant
    %%%%%%%%%%%%%%%%%% wrong
    ...
    ...
    ...
    for i=1:1:ng
    for j=1:1:nt
    QC((i-1)*nt+j).L=zeros(1,Col*ng*nt);
    QC((i-1)*nt+j).r=0;
    I=zeros(3,1);
    J=zeros(3,1);
    S=zeros(3,1);
    I(1)=(i-1)*nt+j;J(1)=2*ng*nt+(i-1)*nt+j;S(1)=-0.5;
    I(2)=ng*nt+(i-1)*nt+j;J(2)=ng*nt+(i-1)*nt+j;S(2)=1;
    I(3)=2*ng*nt+(i-1)*nt+j;J(3)=(i-1)*nt+j;S(3)=-0.5;
    QC((i-1)*nt+j).Q=sparse(I,J,S,ng*nt*Col,ng*nt*Col);
    end
    end
    x, opt, status] = cplexmiqcp([,F,Aineq,Bineq,Aeq,Beq,QC.L,QC.Q,QC.r,],[,],lb,ub,ctype,[,options);
    %%%%%%%%%%%%% right
    ...
    ...
    ...
    for i=1:1:ng
    for j=1:1:nt
    a=zeros(Col*ng*nt,1);
    I=zeros(3,1);J=zeros(3,1);S=zeros(3,1);
    I(1)=(i-1)*nt+j;J(1)=2*ng*nt+(i-1)*nt+j;S(1)=-0.5;
    I(2)=ng*nt+(i-1)*nt+j;J(2)=ng*nt+(i-1)*nt+j;S(2)=1;
    I(3)=2*ng*nt+(i-1)*nt+j;J(3)=(i-1)*nt+j;S(3)=-0.5;
    Q=sparse(I,J,S,ng*nt*Col,ng*nt*Col);
    cplex.addQCs(a, Q, 'L' , 0);
    end
    end
    cplex.solve();

    My Cplex version is 12.2.0.0 ,and yesterday I found update in 12.2.0.2:
    CPLEX RS00503 The lower triangles of the q matrices of quadratic constraints are not extracted in the Matlab connector

    Maybe it can explain the problem.
    Thank you!
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Mon January 17, 2011 01:02 AM

    Originally posted by: SystemAdmin


    Hi,John Cui
    I'm sorry for that TI'm carefully read your reply.Thank you very much for your reply.After I use the statement as below ,the problem is solved.The error due to my custom in cplexint.
    I suggest that matlab cplex example should write more carefully.The Quadratic constraint in example only has one,in maybe mislead the user.

    Thank you!
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Mon January 17, 2011 01:20 AM

    Originally posted by: John Cui


    Glad to hear it works and thanks for your suggestion.

    BTW, could you please put your code inside \{code\} and \{code\} then your code will have better readability.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Mon April 18, 2011 09:19 PM

    Originally posted by: Student2011


    Hello,

    We input the following into Matlab:

    f = [1 1 1];
    l = [0 0 0;1 0 0;0 1 0]';
    Q = {[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]};
    r = [1.0 2.0 3.0];
    x = cplexmiqcp([],f,[],[],[],[],l,Q,r)
    

    and get the following error:
    ??? Error using ==> cplexmiqcp at 584
    Error: incorrect l,Q,r.
    


    Is there something we are doing wrong?

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Mon April 18, 2011 10:27 PM

    Originally posted by: John Cui


    f should be:
    f = [1 1 1]';
    


    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Tue April 19, 2011 06:40 PM

    Originally posted by: Student2011


    Thank you for your response.

    By transposing f we still get the same error:

    ??? Error using ==> cplexmiqcp at 584
    Error: incorrect l,Q,r.
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Wed April 20, 2011 12:54 AM

    Originally posted by: John Cui


    Sorry, Q also should be:

    Q = {[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]};
    


    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Wed April 20, 2011 03:39 PM

    Originally posted by: Student2011


    Hi. We greatly appreciate your help but since the documentation is limited we are having trouble deciphering the error messages.

    Entering the code, with the changes you've suggested, as follows

    f = [1 1 1]';
    l = [0 0 0;1 0 0;0 1 0]';
    Q = {[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]};
    r = [1.0 2.0 3.0];
    x = cplexmiqcp([],f,[],[],[],[],l,Q,r)
    


    We now get the following error:

    ??? Error using ==> cplexmiqcp at 584
    Error: qc not a valid  model qc.a.
    


    Thank you.
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Thu April 21, 2011 04:34 AM

    Originally posted by: John Cui


    Which version CPLEX are you using? The latest one is 12.2.0.2.
    And your code works in this version:

    >> f = [1 1 1]';
    l = [0 0 0;1 0 0;0 1 0]';
    Q = {[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]};
    r = [1.0 2.0 3.0];
    x = cplexmiqcp([],f,[],[],[],[],l,Q,r)
     
    x =
     
       -0.5774
       -0.5774
       -0.5773
    


    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Thu April 21, 2011 08:09 PM

    Originally posted by: Student2011


    Thank you for you help. We did not realize we were missing an upgrade fix. We were on version 12.2. We have downloaded the fix and now the code works.

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Tue July 28, 2015 05:43 AM

    Originally posted by: mena2011


    Hi all

    I am working with a quadratic objective function quadratic constraints and I am using opl cplex 12.6 . after run the problem cplex gives message  error 5002 Q in objective not positive my problem is

    constraints

    6<=x<=50

    0<=y<=30

    x^2+y^2<=80

    how can I tackle this problem please

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: help~matlab cplex toolbox- cplexqcp - Quadratic constraints

    Posted Tue July 28, 2015 12:35 PM

    There are many threads on this forum that mention this error code.  I would recommend searching "This Forum" for "5002" using the search box above to see if you can find the answer to your question using those past responses.  If that doesn't help, you may get more attention if you create a new thread for your problem.

     


    #CPLEXOptimizers
    #DecisionOptimization