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

Re: Non linear constraints in linear objective function
20121120T08:44:48ZThis is the accepted answer. This is the accepted answer.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 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 :( 
Re: Non linear constraints in linear objective function
20121120T18:08:19ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121120T08:44:48Z
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 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 :(
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 
Re: Non linear constraints in linear objective function
20121121T07:19:37ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121120T18:08:19Z
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 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 
Re: Non linear constraints in linear objective function
20121121T14:39:08ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121121T07:19:37Z
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. 
Re: Non linear constraints in linear objective function
20121121T14:56:38ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121121T07:19:37Z
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.
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 
Re: Non linear constraints in linear objective function
20121122T07:45:55ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121121T14:56:38Z
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' 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 
Re: Non linear constraints in linear objective function
20121122T11:19:40ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121121T14:56:38Z
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
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 
Re: Non linear constraints in linear objective function
20121122T21:42:39ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121122T11:19:40Z
Sorry, this time I messed up the tags. Reposting ...
I guess your code is
<pre class="java dw" dataeditorlang="java" datapbcklang="java" dir="ltr">cplex.addIndicators(5, 1, 1 2 3 4 5 6', 'E', 100, {'indc3'}); </pre>
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).
I am make sure to wrap the code into '{code}' tags next time.
I am new to this forum, sorry about that. 
Re: Non linear constraints in linear objective function
20121127T03:48:25ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121122T11:19:40Z
Sorry, this time I messed up the tags. Reposting ...
I guess your code is
<pre class="java dw" dataeditorlang="java" datapbcklang="java" dir="ltr">cplex.addIndicators(5, 1, 1 2 3 4 5 6', 'E', 100, {'indc3'}); </pre>
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).
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. 
Re: Non linear constraints in linear objective function
20121127T07:26:05ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121127T03:48:25Z
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.
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 
Re: Non linear constraints in linear objective function
20121128T04:14:43ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121127T07:26:05Z
The code
<pre class="java dw" dataeditorlang="java" datapbcklang="java" dir="ltr">cplex.addIndicators(i,1,vv,'G',0); </pre>
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.
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.