Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello Expert I am getting failed MMCQ Validation results . Can you please help me to correct the MATALAB Code. The equations for c _

Hello Expert I am getting failed MMCQ Validation results . Can you please help me to correct the MATALAB Code. The equations for c_bar, p_state, c_util, p0_denom, and Lq are wrong. I need to get them corrected and all tests passed. Here is the matalb code.function [Ws, Wq, c_util, p_drop, p_state]= MMCQ(lambda, mu, c, Nwait)
% INPUTS:
% lambda = arrival rate
% mu = service rate
% Nwait = Number of queue elements, not including servers
% c = Number of servers
% OUTPUTS:
% Ws = Average wait in the system
% Wq = Average wait in the queue
% c_util = Average percentage of servers busy
% p_drop = probability the queue is full
% p_state = probability of each state
% Calculate traffic intensity rho
rho = lambda /(c * mu); % Calculate the traffic intensity
% Calculate p0(probability of no customers in the system)
p0_denom = sum((rho.^linspace(0, c -1, c))/ factorial(0:c-1))+(rho^c / factorial(c))* sum(rho.^linspace(c, Nwait, Nwait - c +1)/ factorial(c));
p0_denom = p0_denom +((c*rho)^c /(factorial(c)*(1-rho)))*(1-(rho^Nwait /(1- rho)));
p0=1/ p0_denom;
% n =0:(c-1);
% term1= sum((crho.^n)./ factorial(n));
% term2=((c*crho)^c /(factorial(c)*(1-crho)))*(1-(crho^Nwait /(1- crho)));
% p0=1/(term1+ term2);
% Calculate the utilization factor
c_bar =(rho^c / factorial(c))* p0/ sum((rho.^linspace(0, c -1, c))/ factorial(0:c-1))+(rho^c / factorial(c))* sum(rho.^linspace(c, Nwait, Nwait - c +1)/ factorial(c));
% System Utilization for finite call center queue systems with some probability of filling up (and rejecting users).
c_util = c_bar / c; % Calculate system utilization
% Calculate p_state
p_state = zeros(1, Nwait +1);
for n =0:Nwait
if n < c
p_state(n +1)=(rho^n / factorial(n))*((c * rho)^n / factorial(n))* p0;
else
p_state(n +1)=(rho^n / factorial(n))*((c * rho)^n / factorial(c))* p0;
end
end
% Normalize p_state to ensure probabilities sum to 1
p_state = p_state / sum(p_state);
pN = p_state(Nwait +1); % Probability of having N customers in the system
% Calculate lambda_loss and lambda_eff
lambda_loss = lambda * pN;
lambda_eff = lambda - lambda_loss;
% Calculate Lq (average number of customers in the queue)
% Lq = sum((0:Nwait).* p_state);
Lq = sum(((c*rho)^c /(factorial(c)*(1-rho)))* p0*((rho^(Nwait-c+1)*(Nwait-c+1))/(1- rho))^n / factorial(n));
% Calculate Ls (average number of customers in the system)
Ls = Lq + lambda_eff / mu;
% Calculate p_drop (probability of a customer being dropped)
p_drop = pN /(1+ pN);
% Calculate Ws and Wq
% Calculate Ws (average time a customer spends in the system(Ws))
Ws = Ls / lambda_eff;
% Calculate Wq (average time a customer spends waiting in the queue(Wq))
Wq = Lq / lambda_eff;% Run this test case to check your code
c =2; % Number of servers
lambda =2; % Average Arrival Rate per minute
mu =0.1; % Service rate
Nwait =15;
% Call the MMCQ function with the given parameters
%[Ws, Wq, c_util, p_drop, p_state]= MMCQ(lambda, mu, c, Nwait);
[Ws, Wq, c_util, p_drop, p_state]= MMCQ(1,0.5,4,5);
% Define a relative error function
rel_error = @(x, y) abs(x - y)/ y;
% Validate the results and print "PASS" or "FAIL" for each metric
if rel_error(Ws,2.1557)<0.005
fprintf('Ws =%6.3f PASS
', Ws);
else
fprintf('Ws =%6.3f FAIL
', Ws);
end
if rel_error(Wq,0.1557)<0.005
fprintf('Wq =%6.3f PASS
', Wq);
else
fprintf('Wq =%6.3f FAIL
', Wq);
end
if rel_error(c_util, 0.4986)<0.005
fprintf('c_util =%6.3f PASS
', c_util);
else
fprintf('c_util =%6.3f FAIL
', c_util);
end
if rel_error(p_drop, 0.00272)<0.005
fprintf('p_drop =%8.5f PASS
', p_drop);
else
fprintf('p_drop =%8.5f FAIL
', p_drop);
end
fprintf('p_state: %s
', num2str(p_state));
fprintf('sum(p_state): %f
', sum(p_state));
% Extra Tests: p_state
% p_state should have Nwait+1 probabilities
% disp(['The probability of being in state ', num2str(Nwait),' is ', num2str(p_state(Nwait +1))]);
disp(['The probability of being in state ',' is ', num2str(p_state)]);
% Check that the probabilities sum to 1
if abs(sum(p_state)-1)<1e-5
disp('The probabilities sum to 1. Test PASSED.');
else
disp('The probabilities do not sum to 1. Test FAILED.');
end
end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions