仍然不明白如何在最优问题中添加松弛变量

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

现在我正在尝试为这个最优问题添加一个松弛变量:http://ask.cvxr.com/t/why-does-the-optimal-value-become-nan-sometimes/6035

这是我在本网站中添加松弛变量第 6 节的参考 https://yalmip.github.io/debugginginfeasible/

这是网站的松弛代码。有些地方我不明白。

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

我对这个例子的问题是:

  1. 如果我有三个约束,是否需要生成三个松弛变量?

  2. 我还需要构建 Constraints = [slack2>=0] 吗?

  3. 他的示例代码中的"something"是什么意思?它是一个值、一个向量、一个矩阵还是一个公式?

  4. 如何定义N?在一个约束中,不仅有一个向量,还有另一个向量,有些向量可能是 5 x 1,有些可能是 4 x 1,所以我不知道我应该为 N 假设什么值?

下面是我的代码,我不认为这是正确的,除非我知道我问的问题的解释,我假设的 N 是 4,因为我只有一种向量; 4 x 1 向量

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

我的最优问题代码和公式如下

 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

按顺序回答您的问题:

  1. 理想情况下,是的(如果您要解决的问题依赖于您的所有三个约束)。

  2. 没有。变量 Constraints 仅在此处初始化(通过比较第一个松弛变量的值是否大于零),并且将是一个逻辑值(布尔值)。这假设所有松弛变量都具有相同的数组大小。

  3. something 变量是您要与松弛变量进行比较的变量。

  4. 你可以让N任何你想要的数字,但我个人会在代码的第一行定义N

您的 Constraints 矩阵将包含 0 和 1,具体取决于您将与松弛变量进行比较的 something。每次 for 循环处于活动状态时,基本上都会附加约束。

在 MATLAB 文档中阅读有关数组比较的更多信息 here