Hi,
As per my understanding, you are looking for a workaround to simulate the "handover process",
Following the MathWorks Documentation till the latest release of R2024a, it suggests that the "handover" functionality is currently unavailable in the "5G Toolbox", therefore no direct function is available that takes the UE object and the target gNB as input and perform the handover directly.
Please refer to the following code snippet as reference as an alternate workaround:
classdef MyHandoverEnvironment < rl.env.MATLABEnvironment
properties
NumBS
NumUE
SimDuration
SimArea
SignalRange
MinBSDistance
MaxUEVelocity
RSRPThreshold
UEPositions
UEVelocities
BSPositions
UEBSConnections
timestep
handoverCount
previousHandoverCount
end
methods
function this = MyHandoverEnvironment(numBS, numUE, simDuration, simArea, signalRange, minBSDistance, MaxUEVelocity, rsrpThreshold)
% Define the observation space
observationSpace = rlNumericSpec([numUE*2 1]); % Considering UE Positions and Velocities
observationSpace.Name = 'Observation';
disp(observationSpace);
% Define the action space
actionDimension = numUE; % Assuming actionDimension = number of UEs.
actionSpace = rlFiniteSetSpec(arrayfun(@(x) 0:1, 1:actionDimension, 'UniformOutput', false));
actionSpace.Name = 'Action';
disp(actionSpace);
% Call the superclass constructor
this = this@rl.env.MATLABEnvironment(observationSpace, actionSpace);
% Initialize your class properties
this.NumBS = numBS;
this.NumUE = numUE;
this.SimDuration = simDuration;
this.SimArea = simArea;
this.SignalRange = signalRange;
this.MinBSDistance = minBSDistance;
this.MaxUEVelocity = MaxUEVelocity;
this.RSRPThreshold = rsrpThreshold;
% Initialize environment state
this.reset();
end
function observation = reset(this)
this.UEPositions = this.SimArea * rand(this.NumUE, 2);
this.UEVelocities = this.MaxUEVelocity * rand(this.NumUE, 1);
this.BSPositions = this.deployBS(this.NumBS, this.SimArea, this.MinBSDistance);
this.UEBSConnections = zeros(this.NumUE, this.SimDuration);
this.timestep = 1;
this.handoverCount = 0;
% Return the initial observation
observation = 0;
end
function [observation, reward, isDone] = step(this, action)
disp('Step function called');
isDone = false;
this.UEPositions = this.updateUEPositions(this.UEPositions, this.UEVelocities);
this.UEPositions = this.limitUEPositions(this.UEPositions, this.SimArea);
for i = 1:this.NumUE
if action(i) == 0
% Keep the current connection
reward = reward + 1;
else
distances = sqrt(sum((this.BSPositions - this.UEPositions(i, :)).^2, 2));
[~, minIndex] = min(distances);
disp(minIndex);
if this.timestep > 1 && this.UEBSConnections(i, this.timestep-1) ~= minIndex
this.UEBSConnections(i, this.timestep) = minIndex;
reward = reward - 1; % Penalty for handover
end
end
end
this.timestep = this.timestep + 1;
observation = getObservation();
if this.timestep > this.SimDuration
isDone = true;
end
end
function observation = getObservation(this)
observation = [this.UEPositions(:)];
end
function bsPositions = deployBS(this, numBS, simArea, minBSDistance)
bsPositions = zeros(numBS, 2);
for i = 1:numBS
validPosition = false;
while ~validPosition
bsPositions(i, :) = simArea * rand(1, 2);
if i > 1
distances = sqrt(sum((bsPositions(1:i-1, :) - bsPositions(i, :)).^2, 2));
if all(distances >= minBSDistance)
validPosition = true;
end
else
validPosition = true;
end
end
end
end
function uePositions = updateUEPositions(this, uePositions, ueVelocities)
timeStep = 0.1;
numUE = size(uePositions, 1);
uePositions = uePositions + (timeStep * ueVelocities) .* (0.1 * randn(numUE, 2));
end
function uePositions = limitUEPositions(this, uePositions, simArea)
uePositions(uePositions < 0) = 0;
uePositions(uePositions > simArea) = simArea;
end
end
end
For a similar workaround to achieve the 5G Handover is using the "Reinforcement Learning". Please refer to the MATLAB Answer below in reference to your question.
Hope this helps!