现在我正在尝试为这个最优问题添加一个松弛变量:http: //ask.cvxr.com/t/why-does-the-optimal-value-become-nan-sometimes/6035
这是我在本网站https://yalmip.github.io/debugginginfeasible/中添加 slack 变量第 6 节的参考
这是该网站的松弛代码。有些事情我不明白。
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
我对这个例子的问题是:
如果我有三个约束,我是否需要产生三个松弛变量?
我还需要构建 Constraints = [slack2>=0] 吗?
他的示例代码中的“某事”是什么意思?它是一个值、一个向量、一个矩阵还是一个公式?
我如何定义 N?在一个约束中,不仅有一个向量,还有另一个向量,有些向量可能是 5 x 1,有些可能是 4 x 1,所以我不知道我应该为 N 假设什么值?
下面是我的代码,我不认为这是正确的,除非我知道我问的问题的解释,NI假设是4,因为我只有一种向量;4乘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