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.
Topic
This topic has been locked.
11 replies
Latest Post
 20121128T04:14:43Z by SystemAdmin
ACCEPTED ANSWER
Pinned topic Non linear constraints in linear objective function
20121116T18:05:50Z

Answered question
This question has been answered.
Unanswered question
This question has not been answered yet.
Updated on 20121128T04:14:43Z at 20121128T04:14:43Z by SystemAdmin

ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121120T08:44:48Z in response to SystemAdminCan 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 tworow 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 nonlinear 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 :(
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121120T18:08:19Z in response to SystemAdminThanks 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 nonlinear 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
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121121T07:19:37Z in response to SystemAdminThese 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.
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121121T14:39:08Z in response to SystemAdminThank you very much. I do appreciate it. 
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121121T14:56:38Z in response to SystemAdminHi 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
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121122T07:45:55Z in response to SystemAdminAgain, 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.Updated on 20140324T22:45:45Z at 20140324T22:45:45Z by ironman 
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121122T11:19:40Z in response to SystemAdminSorry, 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).Updated on 20140324T22:45:41Z at 20140324T22:45:41Z by ironman
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121122T21:42:39Z in response to SystemAdminThank 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. 
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121127T03:48:25Z in response to SystemAdminHi 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.
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121127T07:26:05Z in response to SystemAdminThe 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.Updated on 20140324T22:45:14Z at 20140324T22:45:14Z by ironman
ACCEPTED ANSWER
Re: Non linear constraints in linear objective function
20121128T04:14:43Z in response to SystemAdminThank 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.






