Could anyone help me solve the problem below that i am facing

1 次查看(过去 30 天)
Output argument "generatedPackets" (and possibly others) not assigned a value in the execution with
"LTE_Traffic_Model.Generate_Traffic_Model" function.
Error in LTE_Traffic_Model.Ecac (line 150)
simTraffic_E = LTE_Traffic_Model.Generate_Traffic_Model(numberOfUEs,percentageOfRT_Connections,percentageOfNRT_Connections,totalSimulationTime_E,'VoIP','FTP');
Error in LTE_Call_Function (line 5)
obj.Ecac

采纳的回答

Image Analyst
Image Analyst 2023-12-14
You have a function (method) of a class and when you execute that function, for some reason, the output variable never gets assigned. Use the debugger to step through it, just like we'd all do.
A good practice is to assign some default for the output IMMEDIATELY as soon as you get into the function. Like the first line of the function should be something like
generatedPackets = nan;
Same for all of the output variables. You may get other errors after that because the results are not what is required, but at least you won't get that particular error.
  1 个评论
izuchukwu
izuchukwu 2023-12-16
When i did that, the error stopped but the 1*120 packets that were displaying did not display again and i want the packets to display. Because what i want to see is the results of the admitted RT and NRT traffics. I will post the full codes now. Please help me check where the error is and tell me waht to do to correct it.
See the codes:
% // Calls Classification and Prioritization module
classdef LTE_Traffic_Model < Packet
methods(Static)
function generatedPackets = Generate_Traffic_Model(noUE,pRT,pNRT,simTime,rtType,nrtType)
%LTE_TRAFFIC_MODEL class Generate Traffic for simulation
if (pRT + pNRT) == 100
exp_packs_simTime = noUE * 0.02 * simTime;
numPack = exp_packs_simTime/4;
r1 = randi([1 2500],1,numPack);
r2 = randi([2501 5000],1,numPack);
r3 = randi([5001 7500],1,numPack);
r4 = randi([7501 10000],1,numPack);
nRT = (pRT/100) * exp_packs_simTime;
nNRT = (pNRT/100) * exp_packs_simTime;
packetsAT = horzcat(r1,r2,r3,r4);
numPackets = numel(packetsAT);
for k = 1:numPackets
if mod(k,2) == 0
if nRT > 0
dLine = packetsAT(k) + 100; % arrival of RT plus latency
generatedPackets(k) = Packet(1054,'RT',packetsAT(k),dLine); %generate RT packet
elseif nNRT > 0
dLine = packetsAT(k) + 100;%arrival of NRT plus latency(latency is 100, packetsAT(k) is arrival
generatedPackets(k) = Packet(1054,'NRT',packetsAT(k),dLine);%generate NRT packet
end
else
if nNRT > 0
dLine = packetsAT(k) + 100;%packet arrival plus latency(100)
generatedPackets(k) = Packet(1054,'NRT',packetsAT(k),dLine);%generate NRT packet
elseif nRT > 0
dLine = packetsAT(k) + 100; %packet arrival plus latency(100)
generatedPackets(k) = Packet(1054,'RT',packetsAT(k),dLine);%generate RT packet
end
end
end
else
disp('Sum of Percentages Must be 100')
end
end
%Packets Queue
function simPac = emptyQueue(simPackets)
n = numel(simPackets);%get total number of packets
for c = 1:n
if numel(simPackets) > 0
simPackets(1) = [];
end
end
simPac = simPackets;
end
%packets bandwidth
function adaptedBW = adaptBw(simPackets,cSimTime)
n= numel(simPackets);
adBW = 0;
if n > 0
for k = 1:n
cStatus = simPackets(k).packet_status;
cCompletedTime = simPackets(k).packet_completed_time;
if cSimTime <= cCompletedTime && strcmp(cStatus,'on') == 1
pbw = simPackets.packet_allocated_bandwidth;
adBW = adBW + pbw;
simPackets(k).packet_status = 'Completed';
end
end
end
adaptedBW = adBW;
end
%Prioritization of calls
function packk = Prioritize_AT(Packet)
packk = Packet;
n = numel(Packet);
ind = n;
for i = 0:n-1
m = numel(Packet);
%m was commented in the material. I will put comment back
%but let me see what value m will display before commenting
%it as was done in the material.
disp(m)
maxInd = 1;
for k = 1:m
a = Packet(maxInd).packet_arrival_time;
b = Packet(k).packet_arrival_time;
if a < b
maxInd = k;
end
end
%maxInd was commented in the material. I will comment
%maxInd but that will be after seeing the value of maxInd
%displayed and also put semicolon infront of maxInd after
%the comment.
disp(maxInd)
packk(ind) = Packet(maxInd);
ind = ind - 1;
Packet(maxInd).packet_arrival_time = -1;
end
%disp(numel(packk)) was commented in the material. I will
%comment it later but that will be after seeing the values of
%total packk displayed. Remember to put semicolon in front of
%disp(numel(packk)) when you comment it.
disp(numel(packk))
end
% // CAC Procedure Module
%Implementation of the algorithms of Enhanced Adaptive call admission control scheme with Bandwidth Reservation for
%LTE networks.
%ECAC.
function Ecac()
for w = 1:5
%This numberOFUEs = numUEs(w) was commented in the material but i will
%comment it back after seeing what the values are.
numUEs = [20,40,60,80,100,120]; %Inserted by Izuchukwu.
percentageOfRT_Connections = 0.6;%Inserted by Izuchukwu.
percentageOfNRT_Connections = 0.4;%Inserted by Izuchukwu.
numberOfUEs = numUEs(w);
dg = 0;
totalSimulationTime_E = 10000; %in mili seconds
availableBandwidth_E = 360000;
%admittedRT_Connections;
%admittedNRT_Connections;
admittedRT_Connections_E(1) = Packet(9,'D',4,6);
admittedNRT_Connections_E(1) = Packet(9,'D',4,6);
%blockedRT_Connections;
%blockedNRT_Connections;
droppedRT_Connections_E(1) = Packet(9,'D',4,6);
droppedNRT_Connections_E(1) = Packet(9,'D',4,6);
simTraffic_E = []; %simTraffic_E is here
%Generate simulation traffics
disp('Generating Simulation Traffics>>>>>>>>>>>>>>>>>>>>')
% % %
%In the material, simTraffic was written as simTraffic instead of simTraffic_E. I
%will write simTraffic_E to see what will happen. I will
%change it to simTraffic if nothing happen when
%simTraffic_E was written.
%VoIP is the type of RT Traffic while FTP is the type of
%NRT Traffic.
%generating traffic to be simulated
simTraffic_E = LTE_Traffic_Model.Generate_Traffic_Model(numberOfUEs,percentageOfRT_Connections,percentageOfNRT_Connections,totalSimulationTime_E,'VoIP','FTP');
if w == 1
simTraffic_E = simT1;
elseif w == 2
simTraffic_E = simT2;
elseif w == 3
simTraffic_E = simT3;
elseif w == 4
simTraffic_E = simT4;
else
simTraffic_E = simT5;
end
disp(numel(simTraffic_E));
%Why did he comment on this one below simTraffic:
%disp(numel(simTraffic));
simTraffic_E = Prioritize_AT(simTraffic_E);
disp(numel(simTraffic_E));
%He commented on this one below that has to do with packet_type. I will comment it later
%but that will be after seeing the value it displays.
disp(simTraffic_E(5).packet_type);
%Start CAC Procedure
disp('Starting Simulation>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
admittedRT_Connections_E(1) = [];
admittedNRT_Connections_E(1) = [];
droppedRT_Connections_E(1) = [];
droppedNRT_Connections_E(1) = [];
for cSimTime_E = 1:totalSimulationTime_E
%He commented on adRTBW and adNRTBW but i will not
%comment it now but i will comment it later after
%seeing what they do.
adRTBW = 0; adNRTBW = 0;
% % %
adRTBW = LTE_Traffic_Model.adaptBw(admittedRT_Connections_E,cSimTime_E);
% % %
adNRTBW = LTE_Traffic_Model.adaptBw(admittedNRT_Connections_E,cSimTime_E);
%%%
%He commented on sAdb = adRTBW +adNRTBW, I will comment
%it later after seeing what happens.
sAdb = adRTBW + adNRTBW;
%He also commented on availablebandwidth_E =
%availablebandwidth_E + sAdb in the material. I may
%comment it back if it is not needed.
availableBandwidth_E = availableBandwidth_E + sAdb;
if numel(simTraffic_E) > 0
nextConnection_E = simTraffic_E(1);
pType_E = nextConnection_E.packet_type;
arrTime_E = nextConnection_E.packet_arrival_time;
if cSimTime_E >= arrTime_E
%re-try admission of RT
if dg == 0
br = 300;
else
br = 200;
end
simTraffic_E(1) = [];
if strcmp(pType_E,'RT') == 1
%Start of RT admission
if availableBandwidth_E >= br
disp(fprintf('Allocated RT DBW = %d',br));
%Admit RT connection
x_E = numel(admittedRT_Connections_E) + 1;
nextConnection_E.packet_allocated_bandwidth = br;
psize = nextConnection_E.packet_size;
pBurstTime = psize/br;
nextConnection_E.packet_completed_time = pBurstTime + cSimTime_E;
admittedRT_Connections_E(x_E) = nextConnection_E;
availableBandwidth_E = availableBandwidth_E - br;
nextConnection_E(1) = [];
else
%Degradation for RT Traffic
dgrRT = 0; dgrNRT = 0; allBW_E1 = 0; nn = 0; mme = 0;
%He commented on allBW_E1 = 0, I will
%comment it later but that will be
%after seeing what it offers.
nn = numel(admittedRT_Connections_E);
mme = numel(admittedNRT_Connections_E);
if nn > 0
for e = 1:nn
allBW_E1 = admittedRT_Connections_E(e).packet_allocated_bandwidth;
if allBW_E1 > 200
dgrRT = dgrRT + (allBW_E1 - 200);
admittedRT_Connections_E(e).packet_allocated_bandwidth = 200;
end
end
end
if mme > 0
allBW_E2 = 0;
for q = 1:mme
allBW_E2 = admittedNRT_Connections_E(q).packet_allocated_bandwidth;
if allBW_E2 > 200
dgrNRT = dgrNRT + (allBW_E2 - 200);
admittedNRT_Connections_E(q).packet_allocated_bandwidth = 200;
end
end
end
vb = 0;
vb = dgrNRT + dgrRT;
availableBandwidth_E = availableBandwidth_E + vb;
disp('Degradation Has Occurred...')
disp(vb)
dg = 1;
%re-try admission of RT Traffic
if availableBandwidth_E >= 200
p = numel(admittedRT_Connections_E) + 1;
nextConnection_E.packet_allocated_bandwidth = 200;
psize = nextConnection_E.packet_size;
pBurstTime = psize/br;
nextConnection_E.packet_completed_time = pBurstTime + cSimTime_E;
admittedRT_Connections_E(p) = nextConnection_E;
availableBandwidth_E = availableBandwidth_E - 200;
nextConnection_E(1) = [];
else
h = numel(droppedRT_Connections_E) + 1;
droppedRT_Connections_E(h) = nextConnection_E;
nextConnection_E(1) = [];
end %End of Degradation
end %End of RT admission
else %End of RT admission
if dg == 0
br2 = 300;
else
br2 = 200;
end
if availableBandwidth_E >= br2
disp(fprintf('Allocated NRT DBW = %d',br2))
%Admit NRT Connection
y = numel(admittedNRT_Connections_E) + 1;
nextConnection_E.packet_allocated_bandwidth = br2;
psize = nextConnection_E.packet_size;
pBurstTime = psize/br2;
nextConnection_E.packet_completed_time = pBurstTime + cSimTime_E;
admittedNRT_Connections_E(y) = nextConnection_E;
availableBandwidth_E = availableBandwidth_E - br2;
nextConnection_E(1) = [];
else %Perform Degradation procedure
dgrRT2 = 0; dgrNRT2 = 0; allBW_E1x = 0; nn2 = 0; mm2 = 0;
nn2 = numel(admittedRT_Connections_E);
mm2 = numel(admittedNRT_Connections_E);
if nn2 > 0
for u = 1:nn2
allBW_E1x = admittedRT_Connections_E(u).packet_allocated_bandwidth;
if allBW_E1x > 200
dgrRT2 = dgrRT2 + (allBW_E1x - 200);
admittedRT_Connections_E(u).packet_allocated_bandwidth = 200;
end
end
end
if mm2 > 0
allBW_E2x = 0;
for a = 1:mm2
allBW_E2x = admittedNRT_Connections_E(a).packet_allocated_bandwidth;
if allBW_E2x > 200
dgrNRT2 = dgrNRT2 + (allBW_E2x - 200);
admittedNRT_Connections_E(a).packet_allocated_bandwidth = 200;
end
end
end
availableBandwidth_E = availableBandwidth_E + (dgrNRT2 + dgrRT2);
dg = 1;
%re-try admission of NRT Traffic
if availableBandwidth_E >= 200
disp('Degradation Has Occurred>>>>>>>')
y = numel(admittedNRT_Connections_E) + 1;
nextConnection_E.packet_allocated_bandwidth = 200;
psize = nextConnection_E.packet_size;
pBurstTime = psize/br;
nextConnection_E.packet_completed_time = pBurstTime + cSimTime_E;
admittedNRT_Connections_E(y) = nextConnection_E;
availableBandwidth_E = availableBandwidth_E - 200;
nextConnection_E(1) = [];
else
dn = numel(droppedNRT_Connections_E) + 1;
droppedNRT_Connections_E(dn) = nextConnection_E;
nextConnection_E(1) = [];
end %End of Degradation
end
end
end
end
end
disp('Getting the Admitted and Dropped RT and NRT calls...... ')
arrayAdmittedRT_E(w) = numel(admittedRT_Connections_E);
arrayAdmittedNRT_E(w) = numel(admittedNRT_Connections_E);
arrayDroppedRT_E(w) = numel(droppedRT_Connections_E);
arrayDroppedNRT_E(w) = numel(droppedNRT_Connections_E);
disp('Displaying the results of Admitted and Dropped RT and NRT Calls>>>>>>>>')
disp(numel(arrayAdmittedRT_E))
disp(numel(arrayAdmittedNRT_E))
disp(numel(arrayDroppedRT_E))
disp(numel(arrayDroppedNRT_E))
disp(fprintf('%d ECAC------------------------------------',w))
disp(fprintf('Admitted RT = %d',numel(admittedRT_Connections_E)))
disp(fprintf('Admitted NRT = %d',numel(admittedNRT_Connections_E)))
disp(fprintf('Dropped RT = %d',numel(droppedRT_Connections_E)))
disp(fprintf('Dropped NRT = %d',numel(droppedNRT_Connections_E)))
disp(fprintf('Queued Packets = %d',numel(simTraffic_E)))
disp('Getting Queue of Admitted and Dropped RT and NRT Calls...............')
admittedRT_Connections_E = LTE_Traffic_Model.emptyQueue(admittedRT_Connections_E);
admittedNRT_Connections_E = LTE_Traffic_Model.emptyQueue(admittedNRT_Connections_E);
droppedRT_Connections_E = LTE_Traffic_Model.emptyQueue(droppedRT_Connections_E);
droppedNRT_Connections_E = LTE_Traffic_Model.emptyQueue(droppedNRT_Connections_E);
disp('Displaying the results of Queued Admitted and Dropped RT and NRT Calls>>>>>')
disp(fprintf('Queued Admitted RT = %d',numel(admittedRT_Connections_E)))
disp(fprintf('Queued Admitted NRT = %d',numel(admittedNRT_Connections_E)))
disp(fprintf('Queued Dropped RT = %d',numel(droppedRT_Connections_E)))
disp(fprintf('Queued Dropped NRT = %d',numel(droppedNRT_Connections_E)))
totalSimulationTime_E = 0; %in mili seconds
availableBandwidth_E = 0;
br = 0;
dg = 0;
end
end
end
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Mobile Fundamentals 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by