主要内容

本页采用了机器翻译。点击此处可查看英文原文。

优化 Wi-Fi 网络

本例演示了如何在某个区域内部署接入点 (AP),以确保 Wi-Fi 网络中的每个无线站 (STA) 都能获得所需的吞吐量。STA 的位置是固定的。问题在于确定一组接入点 (AP) 的部署位置,以满足吞吐量要求。要建模该问题,请使用 基于问题的优化工作流 来定义最小化所需接入点 (AP) 数量的问题,并使用 WLAN Toolbox™ 函数来计算 STA 的吞吐量。然后使用 surrogateopt 函数 (Global Optimization Toolbox) 来求解由此产生的问题。

无线系统

假设网络配置如下:

  • 每个接入点 (AP) 在 5 GHz 频段内使用一个专用的 20 MHz 信道,而每个站 (STA) 则使用与其距离最近(按欧几里得距离计算)的关联接入点相同的信道。

  • 每个 WLAN 节点均采用固定的 MCS 值 9、单个空间流以及 10 dBm 的发射功率。根据 IEEE® 802.11ax™ 规范,在这些条件下,节点可提供最高 97.5 Mbps 的物理层 (PHY) 数据速率。

  • 每个接入点都会产生连续的下行全缓冲应用流量。

  • 该示例使用 hSLSTGaxMultiFrequencySystemChannel 辅助函数,创建了节点之间的随机 TGax 衰落信道模型。

要仿真该网络,请使用位于本示例末尾simulateWLANNetwork 辅助函数。该函数利用了 WLAN Toolbox 的 System-Level Simulation (WLAN Toolbox) 功能。如需了解更多信息,请参阅示例 Get Started with WLAN System-Level Simulation in MATLAB (WLAN Toolbox)。在此示例中,请在吞吐量计算中仿真 1 秒。

simulationTime = 1;

无线基站位置

该问题包含 16 个 STA,它们位于一个 40 米×40 米的正方形区域内,分布在伪随机位置上。假设每个 STA 的 z 坐标均为 3。

rngSeed = 1;
rng(rngSeed,"combRecursive") % For reproducibility
numSTAs = 16;
staPositions = [randi([0,40],numSTAs,2) 3*ones(numSTAs,1)]; % 16 random 2-D integer points from 0 to 40, z = 3

优化变量

假设该系统最多可配备 7 个接入点。每个 AP 的 x 坐标和 y 坐标均为 0 到 40 之间的整数,z 坐标均为 3。创建表示每个接入点 (AP) 的 x 和 y 坐标的优化变量。

maxNumAPs = 7;
apXPosition = optimvar("apXPosition",maxNumAPs,LowerBound=0,UpperBound=40,Type="integer");
apYPosition = optimvar("apYPosition",maxNumAPs,LowerBound=0,UpperBound=40,Type="integer");
apPositions = [apXPosition apYPosition 3*ones(maxNumAPs,1)]; % z-coordinate is fixed at 3

创建一个逻辑优化变量向量,用于指示哪些接入点 (AP) 可供使用。在哪些情况下可以使用 apEnable(i) = 1AP(i),又在哪些情况下不能使用 apEnable(i) = 0AP(i)

apEnable = optimvar("apEnable",maxNumAPs,LowerBound=0,UpperBound=1,Type="integer");

创建优化问题

需要最小化的目标函数是启用的接入点 (AP) 数量。

problem = optimproblem(Objective=sum(apEnable));

主要约束是每个 STA 的吞吐量必须至少为 20 Mbps。要制定该约束条件,请使用 fcn2optimexpr 函数将吞吐量计算转换为优化表达式,该函数可将函数句柄转换为优化表达式。为了提高此计算的效率,请将 ReuseEvaluation 名称-值参量设置为 true。通过将 Analysis 名称-值参量设置为 "off",表明该计算是一种仿真,而非解析函数。通过指定 OutputSize 参量可节省时间;若未指定该参量,软件必须进行一次试验以确定该函数的输出尺寸。

[staThroughput,numSTAsPerAP] = fcn2optimexpr(@simulateWLANNetwork,...
    apEnable,apPositions,staPositions,simulationTime,rngSeed,...
    ReuseEvaluation=true,Analysis="off",OutputSize={[1 numSTAs],[maxNumAPs 1]});

吞吐量计算现在已成为一个优化表达式。将吞吐量约束纳入 problem 中。

problem.Constraints.LowerLimitofSTAThroughput = (staThroughput >= 20);

添加一条约束条件,即至少有一个接入点 (AP) 必须处于启用状态;并添加另一条约束条件,即每个启用的接入点 (AP) 必须为至少一个站台设备 (STA) 提供服务。

problem.Constraints.MustHaveOneAP = (sum(apEnable) >= 1);
problem.Constraints.NumSTAsPerAP = (numSTAsPerAP >= apEnable);

求解优化问题

该问题包含整数变量和一个非线性目标函数。有两个优化求解器适用于该问题:surrogateoptga。由于该问题的目标函数和约束相对耗时,因此 surrogateopt 可能是最佳的求解器选择。为节省时间,请将选项设置为使用并行计算。为了提高找到良好解的概率,请将初始样本点数设置为大于默认值。

opts = optimoptions("surrogateopt", ...
    MaxFunctionEvaluations=500, ... % Maximum evaluations of the objective before stopping
    MinSurrogatePoints=40, ... % Minimum number of initial sample points
    UseParallel=true); % Parallel evaluations

为了辅助求解器,请指定一个初始可行设计,其中所有接入点均已启用,并均匀分布在正方形周围。

x0 = struct(apEnable=ones(maxNumAPs,1),...
    apXPosition=[0;12;28;40;28;12;20],...
    apYPosition=[20;0;0;20;40;40;20]);

调用 surrogateopt 求解器,并记录解过程所用时间。

tic
[sol,fval] = solve(problem,x0,Solver="surrogateopt",Options=opts)
Solving problem using surrogateopt.

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: 5, xlabel Iteration, ylabel Function value contains 2 objects of type scatter. These objects represent Best function value, Best function value (infeasible).

surrogateopt stopped because it exceeded the function evaluation limit set by 
'options.MaxFunctionEvaluations'.
sol = struct with fields:
       apEnable: [7×1 double]
    apXPosition: [7×1 double]
    apYPosition: [7×1 double]

fval = 
5
toc
Elapsed time is 12875.599167 seconds.

优化后的配置中有五个已启用的接入点,比最初的七个少了两个。显示已启用的接入点。

sol.apEnable
ans = 7×1

    0
    1
    0
    1
    1
    1
    1

查看已优化的接入点 (AP) 位置,这些位置与 STA 的位置一同绘图在图上。

xpos = sol.apXPosition(logical(sol.apEnable))
xpos = 5×1

     5
     7
    38
     2
    26

ypos = sol.apYPosition(logical(sol.apEnable))
ypos = 5×1

    28
    22
    36
    38
     0

plot(xpos,ypos,"o",staPositions(:,1),staPositions(:,2),"*")
legend("AP","STA",Location="best")

Figure Optimization Plot Function contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent AP, STA.

总而言之,surrogateopt 成功地减少了为服务 STA(用 * 表示)所需的 AP(用 o 表示)数量。

辅助函数

以下代码创建 simulateWLANNetwork 辅助函数。

function [stationThroughput,numSTAsPerAP] = simulateWLANNetwork(enableAP,apPositions,staPositions,simulationTime,rngSeed)
%simulateWLANNetwork Simulate Wi-Fi network
%
%   [stationThroughput,numSTAsPerAP] = simulateWLANNetwork(enableAP,
%   apPositions,staPositions,simulationTime,rngSeed) simulates the Wi-Fi
%   network with the specified layout of APs and STAs.
%
%   stationThroughput is a vector representing the throughput values in
%   Mbps.
%
%   numSTAsPerAP is a vector representing the number of STAs served by each AP.
%
%   enableAP is specified as an M-by-1 array of logical values, where 0
%   indicates that the AP is disabled and 1 indicates that the AP is
%   enabled. This variable is an optimization variable in the example.
%
%   apPositions is specified as an M-by-3 array of integers, where M
%   indicates the maximum number of APs and 3 indicates the number of
%   dimensions (x-, y-, and z-coordinates). This variable is an optimization
%   variable in the example.
%
%   staPositions is specified as an N-by-3 array of integers, where N
%   indicates the number of STAs and 3 indicates the number of dimensions
%   (x-, y-, and z-coordinates). This variable is a fixed variable in the example.
%
%   simulationTime is the duration of the simulation in seconds.
%
%   rngSeed is the seed used for the random number generator.

numAPs = size(apPositions,1);
numSTAs = size(staPositions,1);
numSTAsPerAP = zeros(numAPs,1); % Number of STAs associated with each AP
stationThroughput = zeros(1,numSTAs);

% Return if no APs are enabled
if sum(enableAP) == 0
    return
end

% Simulation configuration
rng(rngSeed,"combRecursive");
mcsIndex = 9;
txPower = 10;

% For each AP, assign a 20 MHz channel in the 5 GHz band.
channels = [36 40 44 48 52 56 60 64 100 104 108 112 116 120 124 128 132 136 140 144 149 153 157 161 165 169 173 177];
numChannels = numel(channels);
if numAPs <= numChannels
    apOperatingChannels = [5*ones(numAPs,1) channels(1:numAPs)'];
else % When the number of APs exceeds the number of available channels, reuse channels.
    numLoops = floor(numAPs/numChannels);
    for idx=1:numLoops
        apOperatingChannels(1+numChannels*(idx-1):idx*numChannels,:) = [5*ones(numChannels,1) channels(1:numChannels)'];
    end
    numExtraAPs = mod(numAPs,numChannels);
    if numExtraAPs > 0
        apOperatingChannels(1+numChannels*numLoops:numExtraAPs+numChannels*numLoops,:) = [5*ones(numExtraAPs,1) channels(1:numExtraAPs)'];
    end
end

% Initialize the wireless network simulator.
networkSimulator = wirelessNetworkSimulator.init;

% Configure the APs.
for idx = 1:numAPs
    accessPointCfg = wlanDeviceConfig(Mode="AP",MCS=mcsIndex,...
        TransmitPower=txPower,BandAndChannel=apOperatingChannels(idx,:)); % AP device configuration
    accessPoint(idx) = wlanNode(Name="AP" + idx,Position=apPositions(idx,:),...
        DeviceConfig=accessPointCfg);
end

% Configure the STAs.
for staId = 1:numSTAs
    % Find the nearest enabled AP and associate with that AP
    enabledAPIndices = find(enableAP);
    apID = findNearestAP(apPositions,staPositions(staId,:),enabledAPIndices);

    % Create the STA.
    stationCfg = wlanDeviceConfig(Mode="STA",MCS=mcsIndex,...
        TransmitPower=txPower,BandAndChannel=apOperatingChannels(apID,:)); % STA device configuration
    station(staId) = wlanNode(Name="STA" + staId,Position=staPositions(staId,:),...
        DeviceConfig=stationCfg);

    % Associate the station with the selected AP.
    associateStations(accessPoint(apID),station(staId),FullBufferTraffic="DL");
    numSTAsPerAP(apID) = numSTAsPerAP(apID) + 1;
end

% Set of WLAN nodes
nodes = [accessPoint station];

% Add the channel model.
% hSLSTGaxMultiFrequencySystemChannel.m is a supporting file when you run this example.
channel = hSLSTGaxMultiFrequencySystemChannel(nodes);
addChannelModel(networkSimulator,channelFunction(channel))

% Add nodes to the simulator and run the simulation.
addNodes(networkSimulator,nodes);
run(networkSimulator,simulationTime);

% Get statistics.
stats = statistics(nodes);

% Calculate the MAC layer throughput (in Mbps) at the STAs. Use the
% 'ReceivedPayloadBytes' statistic, which counts the total number of MSDU
% (MAC service data unit) bytes sent to an STA and received at the MAC layer.
% bytes of payload
for idx = 1:numSTAs
    stationThroughput(idx) = (stats(idx+numAPs).MAC.ReceivedPayloadBytes*8)/(simulationTime*1e6);
end
end

该代码创建了 findNearestAP 辅助函数,该函数被包含在前面的辅助函数中。

function nearestAPIndex = findNearestAP(apPositions,stationPosition,enabledAPIndices)
% findNearestAP Returns the index of the nearest enabled AP for each
% specified STA position.
%
%   nearestAPIndex = findNearestAP(apPositions,stationPosition,
%   enabledAPIndices) takes a list of AP positions and finds the position
%   that is nearest to the specified station position.
%
%   nearestAPIndex is the index of the AP in the specified apPositions vector
%   that is nearest to the stationPosition.
%
%   apPositions is a matrix of size M-by-3 representing a list of AP
%   positions, where M is the number of points and 3 is the number of
%   dimensions (x-, y-, and z- coordinates).
%
%   stationPosition is a vector of size 1-by-3 representing a specific
%   station position, where 3 is the number of dimensions (x-, y-, and
%   z- coordinates).
%
%   enabledAPIndices specifies the indices of the APs in apPositions that are
%   enabled for use.

% Initialize the variables.
minDistance = Inf;
nearestAPIndex = -1;

% Find the nearest enabled AP.
for apID = enabledAPIndices'
    % Calculate the distance for each reference point.
    distance = norm(apPositions(apID, :) - stationPosition);
    if distance < minDistance
        minDistance = distance;
        nearestAPIndex = apID;
    end
end
end

另请参阅

主题