matlabcvx

Still don't understand how to add a slack variable in optimal problem


Now I am trying to add a slack variable to this optimal problem: http://ask.cvxr.com/t/why-does-the-optimal-value-become-nan-sometimes/6035

And here is my reference about adding slack variable section 6 in this website https://yalmip.github.io/debugginginfeasible/

And here is the slack code of the website. There are somethings I don't understand about it.

slack1 = sdpvar(N,1);
slack2 = sdpvar(N,1);
Constraints = [slack1>=0]
for i = 1:N
 Constraints = [Constraints, something1 <= slack1(i)];
 Constraints = [Constraints, something2 == slack2(i)];
end

My questions about the example are:

  1. If I have three constraints, do I need to produce three slack variables?

  2. Do I need to build Constraints = [slack2>=0] also?

  3. What does the "something" mean in his example code? Is it a value, a vector, a matrix or a formula?

  4. How do I define the N? In one constraint there is not only one vector but also the other vector, some vectors may be 5 by 1, some may be 4 by 1, so I don't know what value I should assume for N?

Here is my code below, I don't think this is correct, unless I know the explanation of the question I ask, the N I assume is 4, because I only have one kind of vector; 4 by 1 vector

slack_for_C3 = sdpvar(4,1);
slack_for_C5  = sdpvar(4,1);
slack_for_C10  = sdpvar(4,1);
Constraints = [ slack_for_C3 >=0]
for i = 1:4
 Constraints = [Constraints, something1 <= slack_for_C3(i)];
 Constraints = [Constraints, something2 == slack_for_C5(i)];
 Constraints = [Constraints, something3 == slack_for_C10(i)];
end

My optimal problem code and formula are as below

enter image description here

 hat_p_up=0.0824
%OP4
%declare
K=4;
N=4;
L=5;%distance between RX & TX
xi=10^-4%tolerence between 
nois_var_hk_2pow=0.1*(L^(-2.5));%W,0.1*(L^(-2.5)),if this unit is dbm
nois_var_ak_2pow=[1.0000e-10 1.0000e-10 1.0000e-10 1.0000e-10 ];
nois_var_dk_2pow=[1.0000e-08 1.0000e-08 1.0000e-08 1.0000e-08 ];
bar_r=[10 10 10 10]
P_T=10

h_1=normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])+1i*normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])
h_2=normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])+1i*normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])
h_3=normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])+1i*normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])
h_4=normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])+1i*normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])
h_kk=cat(2,h_1 ,h_2 ,h_3, h_4)
 for n=1:4
    h_k{n}=h_kk(1:4 , n);
    n=n+1;
 end

%==========================
cvx_begin

    variable FNNK_up(N,N,K) semidefinite;%c7
    variable rho_k_up(1,1,K) semidefinite;
%==========================
%combine lots of Fkk
Fkk_up=cat(2,FNNK_up);

    up=0
   for o_up=1:4
       Fk_up{o_up}=Fkk_up(1:4,o_up+3*up:4*o_up)
       up=up+1;
   end
   tr_ace_up=0
   for t=1:K
       tr_ace_up=tr_ace_up+trace(Fk_up{t})  
   end
%====================================    
%object function
    minimize( tr_ace_up )
%==================================== 
%Constraint 
subject to 

%Constraint3
rho_k_up<=1;

%===================================================
%
%Constraint5
       c5_left_hand_up = 0;
        for k = 1:K
            sum_5_up = 0;
            for j = 1:K
                if j ~= k  
                 sum_5_up = sum_5_up +  h_k{k}' * Fk_up{j} * h_k{k};
                end
            end      
            c5_left_hand_up = c5_left_hand_up - sum_5_up+ (h_k{k}' * Fk_up{k} * h_k{k}*inv_pos(bar_r(1)))
            c5_right_hand_up= nois_var_ak_2pow(1)+ ( nois_var_dk_2pow(1)*inv_pos(rho_k_up(k)) )
            %c5_left_hand_up  >=   c5_right_hand_up
            real( c5_left_hand_up ) >=   c5_right_hand_up
        end

%===================================================   
%Constraint10
    c10_left_hand_up = 0;
        %for k = 1:K           
            sum_10_up = 0;
            for j = 1:K                  
                 sum_10_up= sum_10_up +  h_k{k}' * Fk_up{j} * h_k{k}; 
            end
            c10_left_hand_up = c10_left_hand_up + sum_10_up+nois_var_ak_2pow(1)
            c10_right_hand_up=hat_p_up*inv_pos(1-rho_k_up(k))  
            real(c10_left_hand_up)>=  c10_right_hand_up
        %end     
cvx_end

Solution

  • To answer your questions in order:

    1. Ideally, yes (if the problem you are trying to solve relies on all three of your constraints).

    2. No. The variable Constraints is only being initialized here (by comparing if the value of the first slack variable is greater than zero), and will be a logical value (boolean value). This assumes that all slack variables will have the same array sizes.

    3. the something variables are what you are comparing your slack variables to.

    4. You can make N whatever you number you want, but I personally would define N on the first line of code.

    Your Constraints matrix will contain 0's and 1's based off what the something you will be comparing your slack variables to. Constraints will essentially be appended to every time the for loop is active.

    Read more about Array Comparisons in the MATLAB Documentation here.