Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Non linear constraints in linear objective function

  • 1.  Non linear constraints in linear objective function

    Posted Fri November 16, 2012 01:06 PM

    Originally posted by: SystemAdmin


    Hi,

    Anyone know how to handle the non linear constraints in linear objective function?
    When I wrote the code as

    "cplex = Cplex('test');
    cplex.Model.sense = 'minimize';

    obj = 1;1;
    lb = 0;0;
    ub = inf;inf;
    ctype = ;

    cplex.addCols(obj, [], lb, ub, ctype);

    supply=[1,0;
    0,1];
    cplex.addRows(2, supply, 2);

    cplex.solve();"

    It showed the error message as
    "??? Error using ==> Cplex.addRows at 1114
    Cplex.addRows Error: incompatible matrix sizes."

    Thanks for your help.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Non linear constraints in linear objective function

    Posted Tue November 20, 2012 03:45 AM

    Originally posted by: SystemAdmin


    Can you please wrap your code into '{code}' tags? Otherwise it is hard to read.
    If I read your code correctly then the problem is that you call addRows() with a two-row matrix but the lhs and rhs vectors are only singletons. If the 'supply' matrix has two rows then each of those vectors needs to have two elements as well.
    Please take a look at the third example for addRows() in the reference documentation. This illustrates how to add multiple rows in one shot.
    Finally, I don't see anything non-linear in your model, neither in the constraints nor in the objective function. So I fail to see how your problem relates to the subject of this thread :-(
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Non linear constraints in linear objective function

    Posted Tue November 20, 2012 01:08 PM

    Originally posted by: SystemAdmin


    Thanks for you reply. Sorry for the confusion.

    Assume there are two variables: X1 and X2,
    If there is a constraint as "X1^2 + X2^2 + X1*X2<=2"
    how can I express this non-linear constraint using addRows() function.

    If there is two lhs and rhs for each vector, it will look like the linear constraints.
    Thanks for your help
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Non linear constraints in linear objective function

    Posted Wed November 21, 2012 02:20 AM

    Originally posted by: SystemAdmin


    These kind of constraints are known as "quadratic constraints" and must be added using method addQCs() instead of addRows(). Please refer to the reference documentation for addQCs() for more details.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Non linear constraints in linear objective function

    Posted Wed November 21, 2012 09:39 AM

    Originally posted by: SystemAdmin


    Thank you very much. I do appreciate it.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Non linear constraints in linear objective function

    Posted Wed November 21, 2012 09:57 AM

    Originally posted by: SystemAdmin


    Hi Daniel,

    Could you show me a case of how to use "addIndicators"?

    for example:
    '(cplex.addIndicators(5, 1, 1 2 3 4 5 6', 'E', 100, {'indc3'});)'

    Does it mean when X5 (binary variable) equal to 1, X1+X2+X3+X4+X5+X6==100?

    Thanks again.

    Aaron
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Non linear constraints in linear objective function

    Posted Thu November 22, 2012 02:46 AM

    Originally posted by: SystemAdmin


    Again, please wrap code into '
    ' tags, otherwise it is hard to read (for example because the Forum software swallows square brackets). I guess your code is
    

    cplex.addIndicators(5, 1, 1 2 3 4 5 6', 'E', 100, {'indc3'});
    {code}
    This constraints says "If x(5) is 0 then x(1)+...+x(6) must be 100". I think you misinterpreted the second argument (where you pass '1'): This argument says whether the indicator variable (first argument) should be complemented or not. If the indicator variable is complicated then the constraint is "if indicator variable is 0 then ...", otherwise it is "if indicator variable is 1 then ...".
    You can find more details about the arguments in the reference documentation for function addIndicators().
    Please also look at the examples etsp.m and foodmanu.m in the CPLEX distribution. They use indicator constraints and have comments that describe what constraints are created.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Non linear constraints in linear objective function

    Posted Thu November 22, 2012 06:20 AM

    Originally posted by: SystemAdmin


    Sorry, this time I messed up the tags. Reposting ...

    I guess your code is
    cplex.addIndicators(5, 1, 1 2 3 4 5 6', 'E', 100, {'indc3'});
    

    This constraints says "If x(5) is 0 then x(1)+...+x(6) must be 100". I think you misinterpreted the second argument (where you pass '1'): This argument says whether the indicator variable (first argument) should be complemented or not. If the indicator variable is complicated then the constraint is "if indicator variable is 0 then ...", otherwise it is "if indicator variable is 1 then ...".
    You can find more details about the arguments in the reference documentation for function addIndicators().
    Please also look at the examples etsp.m and foodmanu.m in the CPLEX distribution. They use indicator constraints and have comments that describe what constraints are created.

    Again, please wrap code into '{code}' tags, otherwise it is hard to read (for example because the Forum software swallows square brackets).
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Non linear constraints in linear objective function

    Posted Thu November 22, 2012 04:43 PM

    Originally posted by: SystemAdmin


    Thank you very much. Daniel.
    I am make sure to wrap the code into '{code}' tags next time.
    I am new to this forum, sorry about that.
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Non linear constraints in linear objective function

    Posted Mon November 26, 2012 10:48 PM

    Originally posted by: SystemAdmin


    Hi Danniel

    I wrote a code as

    '{for i=1:32
    vv=zeros(69,1);
    vv(i+32)=1;
    cplex.addIndicators(i,1,vv,'G',0);
    end}'

    I tried to express that when variable i equal to '0', the equation vv is equal to '0'.
    I try the simple example, it works.
    But when I did in my research code, it appeared infeasible. Is there something I need pay attention to when I used cplex.addIndicators?
    Thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Non linear constraints in linear objective function

    Posted Tue November 27, 2012 02:26 AM

    Originally posted by: SystemAdmin


    The code
    cplex.addIndicators(i,1,vv,'G',0);
    

    creates a 'greather or equal' constraint, not an equality constraint (like you said you want to create) but that should not affect feasibility.
    There is nothing special to observe when creating indicator constraints, so I guess the problem is somewhere within your model. To analyze infeasibility of a model the conflict refiner (see function refineConflict() here and the Infeasibility and unboundedness section in the user manual may be helpful.
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Non linear constraints in linear objective function

    Posted Tue November 27, 2012 11:15 PM

    Originally posted by: SystemAdmin


    Thank you very much. Daniel.

    I finally finish my first CPLEX research project. I used addIndicators the other way around.
    It can't be done without ur help. Thanks again.
    #CPLEXOptimizers
    #DecisionOptimization