资源简介
强化学习算法,实现强化学习对网络资源的分配,目的是频谱利用最大化
代码片段和文件信息
% Program
%
% enfor.m
%
% Simulation program to realize enforcement algorithm
%
% Programmed by Kang
%
%%%%%%%%%%%%%%%% preparation part %%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear;
M = 4; %信道数
T = 400; %迭代次数
S = 8; %第二用户数
e=2.71828;
sum=0; %存放和
%ch = zeros(1S); %每步信道选择矩阵
n0 =0.01; %白噪声干扰
r = 5; %覆盖半径
ts=20;
p=0.5;%power !!!!!!!!
u = zeros(ST); % 存放各信道各次迭代的结果
w = zeros(ST); %信道i在t时刻对用户的吸引值
f=zeros(ST);%
h=zeros(SSM);
ww = zeros(MST);
alpha = 10; %信道衰落因子
fsel=[1 2 3 4];
cq=[1 1.1 1.2 1.3];
ps=0.4;%parament
%%%%%%%%%%%%%%%%% 初 始 化 %%%%%%%%%%%%%%%%%%%%%%%%%
for x=1:S
for y=1:M
f(1:21)=fsel(1);
f(3:41)=fsel(2);
f(5:61)=fsel(3);
f(7:81)=fsel(4);
w(:1)=3.0;%????几,任何信道下,用户的w都初始化1
ww(1:1)=1.0;
ww(2:1)=1.5;%在信道2上,任何SU的效益是1.5
ww(3:1)=2.0;
ww(4:1)=2.5;
u(:1)=1.0;%?????自己设定几
end
end
pos_tx=position(rS); %创建发射节点图产生5个发射节点
pos_rv=position(rS); %创建接收节点图,产生5个接收节点
dis=distance(pos_txpos_rvS); %创建各发射到接收的距离矩阵
H=loss(disalphaS); %H变化区间大
H1=1./((exp(-pi*((H).^2)))*10+10)*10;%H1元素的值比较接近 二维的
for ii=1:M
h(::ii)=H1.*cq(ii);%4维的
end %各信道下各用户间衰落,信道增益Hij
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 画图 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure() %画网络图
for ii=1:S
x1=pos_tx(ii1);
y1=pos_tx(ii2);
x2=pos_rv(ii1);
y2=pos_rv(ii2);
xx=[x1x2];
yy=[y1y2];
plot(xxyy‘--bo‘‘LineWidth‘2...
‘MarkerEdgeColor‘‘k‘...
‘MarkerFaceColor‘‘w‘...
‘MarkerSize‘5)
hold on
legend(‘认知用户‘)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%% 算 法 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
temp=0;
%sir_node_sum=0;
flag=-1000000000;
for t=2:T
for x=1:S%次级用户数
for y=1:M%信道数
if y==f(xt-1)%!!!!w与信道有关的吧
ww(yxt)=(1-ps)*w(xt-1)+ps*u(xt-1);
else
ww(yxt)=ww(yxt-1);
end
if ww(yxt)>flag % find max
flag=ww(yxt);
wmax=ww(yxt);%?????写维数吗ww是暂时存储量
cha=y;
end
end
f(xt)=cha;
w(xt)=wmax;%用户1经历4个信道 选出4个ww中最大的给w
%[chawmax]=sir(ftMSh);%1!!!!!!
flag=-1000000000; %完成在时刻t某个用户遍历4个信道后的选择
end
for x=1:S
for a=1:S
if a~=x %a不是用户m
if f(at)==f(xt) %a选的信道和当前的策略一致
temp=temp+p*h(axf(at));%h与*无关,是个数
评论
共有 条评论