Constraint condition does not work

My code is as follows, and the result can be produced in the end, but the constraint condition does not work, how can I solve it。
clear all
clc
sigma2=10^(-14);%噪声功率-140dBm
alpha1=0.3;
alpha2=0.7;
beta0=10^(-6);%单位距离信道功率增益-60dB
pmax=0.2;%最大发射功率20dBm_——改为0.2
B= 10^(6);%10^(6);%带宽
S=10^(6);%数据包大小
Pos_gateway=[1500,1000];
sss=2;
pionts_in2r=[383.353104429636,515.077391288163;373.515457407451,334.609223783052];
center=[378.434280918544,424.843307535607];
cvx_begin

            %调整精确度
            cvx_solver sedumi
            cvx_precision best
            
            variable x 
            variable y
            expression lambda(sss,1)
            expression ceter_next
            expression A_temp(sss,1)
            expression D_temp(sss,1)
            expression AD_temp(sss,1)
            expression mu
            expression F_temp
            expression Z_temp
            expression FZ_temp
            expression eta_temp(sss,1)
            ceter_next=[x,y];
            ceter_temp=center;
            
            for i=1:sss
                lambda(sss)=sqrt(S*pmax)/(B*log(1+(pmax*beta0)/(sigma2*sum_square_abs(ceter_temp-pionts_in2r(sss,:))))/log(2));
                A_temp(sss)=(pmax*beta0*log(exp(1))/log(2))/(sum_square_abs(ceter_temp-pionts_in2r(sss,:))*(sigma2*sum_square_abs(ceter_temp-pionts_in2r(sss,:))+pmax*beta0));
                AD_temp(sss)=sum_square_abs(lambda(sss))*(-A_temp(sss)*(sum_square_abs(ceter_next-pionts_in2r(sss,:))-sum_square_abs(ceter_temp-pionts_in2r(sss,:))))...
                    +sum_square_abs(lambda(sss))*D_temp(sss);   
               
            end
            mu=sqrt(S*pmax)/(B*log(1+(pmax*beta0)/(sigma2*sum_square_abs(ceter_temp-Pos_gateway)))/log(2));
            F_temp=(pmax*beta0*log(exp(1))/log(2))/(sum_square_abs(ceter_temp-Pos_gateway)*((sigma2*sum_square_abs(ceter_temp-Pos_gateway))+pmax*beta0));
            Z_temp=log(1+(pmax*beta0)/(sigma2*sum_square_abs(ceter_temp-Pos_gateway)))/log(2);
            FZ_temp=sum_square_abs(mu)*(-F_temp*(sum_square_abs(ceter_next-Pos_gateway)-sum_square_abs(ceter_temp-Pos_gateway)))...
                +sum_square_abs(mu)*Z_temp;
            eta_temp=-2*alpha1*sqrt(pmax*S)*sum(lambda(sss))-2*sqrt(pmax*S)*alpha2*mu+B*alpha1*sum(AD_temp)+B*alpha2*FZ_temp;
            maximize (eta_temp)
            subject to
                for i=1:sss
                   sum_square_abs(ceter_next-pionts_in2r(sss,:))<=10000;
                end
        cvx_end
         UAV_next_top=ceter_next;

What do you mean “it dosen’t work”? Small violation of constraints can happen sometimes. It’s normal.

I mean, what’s a good way or how can I adjust the program so that it satisfies the constraints, because the constraints are important to me。

If your solution turns out violating the constraint a little bit, you can modify your constraint by adding a small value like 1e-6 to one side to force it to be strictly satisfied, then you run the whole problem again to get a new solution. It might satisfy the original constraint this time.

When I see

sigma2=10^(-14)

I immediately think there are something wrong with the scaling in the model i.e. bad choice of units for variables and constraints.

I appreciate your advice, but it still doesn’t satisfy the original constraints

I don’t understand what you mean, the units of all my variables are si units, and so are the units of variables in my constraints

What Mr.Andersen meaned is that your input data are too small like this sigma2=10^(-14) , solvers cann’t handle them stably, and they might affect how well your constraints are satisfied. So you need to change unit (换个单位) to make them close to one, not too big or too small. If they are too close to zero, set them zero if possible.

Also, I ran your code, and found that the constraints were satisfied, as shown in the following:

This is where I find it strange that when I run the code alone, the constraints are not satisfied, as shown in the following
image

I can’t reproduce your problem, and I don’t know why.

In the loop where you add these constraints you always use sss instead of i.

2 Likes

Thank you very much for your warning.