CVX error, It does not accept this constraint


(mohamed) #1

I have this problem

max sum(u_i)
s.t
r_i^2<=A+M1(1-u_i)

where u_i={0,1},
r_i=sqrt([x_i-xd]^2+[y_i-yd]^2). This is the distance between the point (x_i,y_i) and (xd,yd)
The optimization variables are xd,yd and u_i.

The following is my formulation

function [xd,yd,u]=Fun3(Gamma,x,y)

     global NofUsers
     M1=1e4;
     %cvx_begin
     cvx_begin quiet
     cvx_solver Mosek
     variable u(NofUsers) binary
     variables xd yd
     maximize(sum(u))
     for i=1:NofUsers
         (norm([x(i) y(i)] - [xd yd]))^2 <=Gamma + M1 * (1-u(i));
         %((x(i)-xd11)^2 + (y(i)-yd11)^2)^2 <=Gamma + M1 * (1-u(i))
     end
     cvx_end
   
    % NofUsers_in=cvx_optval;
     %NofUsers_in=sum(u)

end

When I run the code it gives me an error

Error using cvx/pow_cvx (line 142)
Disciplined convex programming error:
Illegal operation: {convex} .^ {2}
(Consider POW_P, POW_POS, or POW_ABS instead.)

Error in .^ (line 55)
z = pow_cvx( x, y, ‘power’ );

Error in ^ (line 9)
z = power( x, y );

Error in Fun3 (line 12)
(norm([x(i) y(i)] - [xd11 yd11]))^2 <=Gamma + M1 * (1-u(i));

Error in ProgPtLoctnFor1Density (line 70)
[xd,yd,u3]=Fun3(Gamma,x,y);


(Mark L. Stone) #2

(sum_square([x(i) y(i)] - [xd yd])) <=Gamma + M1 * (1-u(i));
or
(square_pos(norm([x(i) y(i)] - [xd yd]))) <=Gamma + M1 * (1-u(i));
or
(pow_pos(norm([x(i) y(i)] - [xd yd])),2) <=Gamma + M1 * (1-u(i));
should work.

Neither pow_p nor pow_abs will work in this case because norm in the argument is not affine.


(irem) #3

Do you really need the square of the norm? u is just a binary variable, so I believe you can use the square of Gamma, which is just a constant.


(Mark L. Stone) #4

This could work either with or without squaring the norm, as long as Gamma and M1 are given the required values, which will differ depending on whether or not norm is squared. - see How to formulate a MILP in CVX .

It probably would have been better to post this question in that existing thread.