Non negative binding does not work

The optimized parameter b (k) is greater than or equal to a positive number, but in each iteration, the non negative constraint on b (k) does not work. Why is this? Please help to clarify, thank you very much.

clc;
clear;
noise = 10^(-13);
load('tur1_50.mat')   
k_lam = 0.1514;   
lamda = 530*10^-9; 
rho = 0.9 * 1.6 * 10^-19 / (6.626 * 10^-34 * 3 * 10^8 / lamda); 

K = 2;
Pt = 2;
tolerance = 1e-4;
tPrevious = -inf;

for k = 1: K + 1
    dist_d = 10;
    var_d(k) = tur1_30(dist_d, 2); 
    pathl_r(k) = 0.01 * 0.9 * 0.9 / (2 * pi) / (1 - cos(10/180 * pi)) / cos(10/180 * pi) / dist_d.^2 * exp(-k_lam * dist_d);
    
    dist_e = 35;
    var_e(k) = tur1_30(dist_e, 2); 
    pathl_e(k) = 0.01 * 0.9 * 0.9 / (2 * pi) / (1 - cos(10/180 * pi)) / cos(10/180 * pi) / dist_e.^2 * exp(-k_lam * dist_e);
end

%% Initial value
maxIter = 30;
for i = 1 : K + 1
    p_pre(i) = 1;
    b_pre(i) = exp(4 * var_e(i)) * (rho * p_pre(i) * pathl_e(i))^2 + noise;
end

%% CVX
for iter = 1:maxIter
    cvx_begin quiet
    cvx_solver sdpt3
    variable p(1, K + 1) nonnegative;
    variable t;
    variable b(1, K + 1) nonnegative;

    maximize(t)  % The goal is to maximize t
    subject to
    rth = 1;

    for k = 1:K+1
         
        p(k) >= 0;
        
        % !!B (k) is displayed as a negative value after each optimization
        % !!On the right side of the inequality is a positive value
        % !!The constraint did not work
        b(k) >= exp(4 * var_e(k)) * (rho * p(k) * pathl_e(k))^2 + noise;
       
        2^t <= (2 * (exp(4 * var_d(k)) * (rho * pathl_r(k))^2 * p(k) * p_pre(k)) + 2 * noise) / b_pre(k) - (noise + exp(4 * var_d(k)) * (rho * pathl_r(k) * p_pre(k))^2 ) * b(k) / b_pre(k)^2;
        
        2^rth <= (2 * (exp(4 * var_d(k)) * (rho * pathl_r(k))^2 * p(k) * p_pre(k)) + 2 * noise) / b_pre(k) - (noise + exp(4 * var_d(k)) * (rho * pathl_r(k) * p_pre(k))^2 ) * b(k) / b_pre(k)^2;

    
    end

    sum(p) <= Pt;  % power

    cvx_end

    if abs(t - tPrevious) <= tolerance
        break;
    end

% Record the current value for the next round
    b_pre = b;
    tPrevious = t;
    p_pre = p;
end

disp('MAX-ASC:');
disp(t);
disp('p:');
disp(p);

You haven’t told us exactly what you mean by “the non negative constraint on b (k) does not work”. Declaring a variable b nonnegative is the same as imposing the constraint b >= 0. If CVX says the problem is solved to optimality, then all elements of b should be within solver feasibility tolerance of being >= 0. So, for instance, b(2) = -1e-9 could be the “optimal” solution, and the solver, and hence CVX would consider that to satisfy the nonnengativity constraint. If you want to ensure b is actually nonnegative (or perhaps positive), you could use a constraint such as b >= 1e-5 instead of declaring it nonnegative.

Until you have things working correctly, you should not use quiet, and should look at the solver and CVX output on each iteration to see how things are going.

1 Like

Thank you for your reply. I can understand that CVX has included b (2)=-1e-9 within an acceptable range for optimal operation. The non negative constraint of b (x) can be simply understood as>=1e-13, but the optimal solution of b (x)=-1e-12 does not satisfy the constraint in the code, so I was confused before. Although there is only a slight difference, it has resulted in a significant difference between the subsequent optimization results MAX_ASC and the actual condition input value, which is about greater than 2. Do you have any good methods regarding this issue?

Either constrain b >= small_positive_number, such as 1e-5 or 1e-6, or adjust b after CVX completes. neither method is perfect. It’s just the reality of double precision optimization solvers.

1 Like

Thank you for providing the solution. If it can effectively solve my problem, I will continue to record it here.