1% O. Gursoy, K. A. Mehr, N. Akar:
2% The MAP/M/s + G Call Center Model with Generally Distributed Patience Times: Steady-state Solution and First Passage Time Distribution
3% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4% Steady-state and first passage time solver
for MAP/M/s + G queues
7%-----------------------------
8% -SOLUTION: Solution type(steady state or first passage actual/
virtual)
9% -SERVERSIZE: server size of the call center problem
13% -MAPSIZE: Order of MAP(C,D) distribution, Service Rate(mu)
14% -QUANTIZATION: number of regimes that will quantize abandonment function ga
15% -BoundaryLevels: Boundary levels of Regimes
16% -ga: Abandonment Probability in Each Regime (starts with a 0 value)
17% -gabanfunction:
for continious abandonment functions enter ccdf of abandonement as a function of x
20% INPUTS
for first passage times(these are not necessary
for steady state
22%-----------------------------
25% -CMEorErlang: indicator of which distribution
is chosen
for approximation
26% -OrderofPHCME: order of the chosen approximator (25, 51 or 101)
27% -pi0: initial server occupancy distribution
28% -theta0: initial MAP state distribution
31%---------------------------
32% -steadyStateResult: 1x7 steady state result vector including PR{W=0}
33% PR{W=0|S} PR{A} E{W|S} Var{W|S} Fw|s,w>0(.1) Fw|s,w>0(.2)
34% respectively(when SOLUTION=1).
36% -FirstPassageTimeofVirtual: First passage time probability
for the
virtual waiting time(when SOLUTION=2).
38% -FirstPassageTimeofActual: First passage time probability
for the actual
39% waiting time(when SOLUTION=3).
44% For first passage time cases the initial wait time, a=0.
47%_________________________________________________________________
56%INPUTS___________________________________________________________
59%solution=1
if steady state, solution=2
if first passage distribution of
virtual waiting time,
60%solution=3
if first passage distribution of actual waiting time,
63%server size, state size of MAP(C,D), service rate and QUANTIZATION (regime count)
69% C,D matrices (2 state MAP(C,D)
is default)
70%-------------------------------------------
76 mean_arrival = 1/(S*mu*rho);
79 p_1 = 0.5*(1 + sqrt((C_onsquared-1)/(C_onsquared+1)));
81 mu_1 = 2*p_1 / mean_arrival;
82 mu_2 = 2*p_2 / mean_arrival;
85 T = [-mu_1 0;0 -mu_2];
89 lambda = 1/mean_arrival;
91 D1 = (1-decay)*T0*v - decay*T1 ;
99%abandonment prob
for regimes (ga) and boundary levels (BoundaryLevels)
100%---------------------------------------------------------------------
101%(piecewise constant abandonment function
is default)
102BoundaryLevels = linspace(0,10,QUANTIZATION);
103ga=0.10*floor(BoundaryLevels);
105BoundaryLevels(end+1)=10000000;
109%Uncomment
for continious abandonment function**
110% interval=1/(QUANTIZATION);
112%
for k=1:QUANTIZATION
113% ga(k+1)=interval*k+ga(1);
118% %enter ccdf of abandonement as a function of x**
119% gabanfunction=1-exp(-x)-x*exp(-x)-x^2*exp(-x)/2;
120%
if (ga(regime+1)+tol>gabanfunction)&&(ga(regime+1)-tol<gabanfunction)
121% BoundaryLevels(regime)=x;
122%
if regime<QUANTIZATION
129% gatemp(i)=(ga(i-1)+ga(i))/2;
135%
if first passage distribution
is chosen (SOLUTION=3) enter the parameters**
136%------------------------------------------------------------
139%initial server occupancy distribution
140pi0=[1 0 0 0 0 0 0 0 0 0 0];
141%initial MAP state distribution
143%CMEorErlang=1 for CME approximation and CMEorErlang=0 for Erlangization
145%order of PH or CME, order=25 if OrderofPHCME=1, order=51 if OrderofPHCME=2, order=101 if OrderofPHCME=3,
148%END OF INPUTS _______________________________________________________
152%CALCULATIONS_____________________________________________________
155%construction of infinitesial generators and drift matrices for both regimes (Qy,ydriftregimes)and
156%boundaries (Qybounds,ydriftbounds)
158Qy0=zeros((SERVERSIZE+1)*size(I,1),(SERVERSIZE+1)*size(I,1));
159Qy=zeros((SERVERSIZE+1)*size(I,1),(SERVERSIZE+1)*size(I,1),QUANTIZATION);
160Rydiag=-ones(1,size(Qy0,1));
161Rydiag(size(Qy0,1)-size(I,1)+1:size(Qy0,1))=-Rydiag(size(Qy0,1)-size(I,1)+1:size(Qy0,1));
163for row=1:SERVERSIZE+1
165 Qy0((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE)=C;
166 Qy0((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row)*MAPSIZE+1: (row)*MAPSIZE+MAPSIZE)=D;
167 elseif row==SERVERSIZE+1
168 Qy0((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE)=-(row-1)*mu*I;
169 Qy0((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row-2)*MAPSIZE+1: (row-2)*MAPSIZE+MAPSIZE)=(row-1)*mu*I;
171 Qy0((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE)=C-(row-1)*mu*I;
172 Qy0((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row-2)*MAPSIZE+1: (row-2)*MAPSIZE+MAPSIZE)=(row-1)*mu*I;
173 Qy0((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row)*MAPSIZE+1: (row)*MAPSIZE+MAPSIZE)=D;
177for regimecount=1:QUANTIZATION
178 for row=SERVERSIZE:SERVERSIZE+1
180 Qy((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE,regimecount)=(ga(regimecount+1))*D+C;
181 Qy((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row)*MAPSIZE+1: (row)*MAPSIZE+MAPSIZE,regimecount)=(1-(ga(regimecount+1)))*D;
182 elseif row==SERVERSIZE+1
183 Qy((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE,regimecount)=-(row-1)*mu*I;
184 Qy((row-1)*MAPSIZE+1: (row-1)*MAPSIZE+MAPSIZE, (row-2)*MAPSIZE+1: (row-2)*MAPSIZE+MAPSIZE,regimecount)=(row-1)*mu*I;
187 ydriftregimes(regimecount,:)=Rydiag;
188 Ryregimes(:,:,regimecount)=Ry;
190Qybounds=cat(3,Qy0,Qy);
191ydriftbounds=cat(1,Rydiag,ydriftregimes);
192Rybounds=cat(3,Ry,Ryregimes);
196elseif OrderofPHCME==2
198elseif OrderofPHCME==3
202%Based on the chosen SOLUTION make adjustments for the input of MRMFQ solver
204 driftbound=ydriftbounds;
205 driftregimes=ydriftregimes;
208 BoundaryLevelsLast=BoundaryLevels;
212 [MESystem,cv]= CMEParameterCalculator(n,tau);
217 alpha=zeros(1,OrderofPH);
219 ss=-ones(1,OrderofPH);
229 while BoundaryLevels(count)<b
232 BoundaryLevelsLast=BoundaryLevels(1:count);
233 BoundaryLevelsLast(count)=b;
235 for reg=1:length(BoundaryLevelsLast)
236 eTilde= ones(1,length(Qybounds(:,:,reg+1)));
237 eTilde(end-MAPSIZE+1:end)=0;
240 Qz(:,:,reg)=[0 zeros(1,length(kron(alpha,kron(pi0,theta0))));kron(S0,diag(Itilde)) (kron(eye(length(S)),Qy(:,:,reg))+kron(S,Itilde))];
241 Qzbounds(:,:,reg+1)=[0 zeros(1,length(kron(alpha,kron(pi0,theta0))));kron(S0,diag(Itilde)) (kron(eye(length(S)),Qybounds(:,:,reg+1))+kron(S,Itilde))];
243 Rz(:,:,reg)=diag([-1 ones(1,size(kron(eye(length(S)),Ryregimes(:,:,reg)),1))* kron(eye(length(S)),Ryregimes(:,:,reg))]);
244 Rzbounds(:,:,reg+1)=diag([-1 ones(1,size(kron(eye(length(S)),Rybounds(:,:,reg+1)),1))* kron(eye(length(S)),Rybounds(:,:,reg+1))]);
246 Qzbounds(:,:,1)=[-1 kron(alpha,kron(pi0,theta0));kron(S0,diag(Itilde)) (kron(eye(length(S)),Qybounds(:,:,1))+kron(S,Itilde))];
247 Rzbounds(:,:,1)=diag([-1 ones(1,size(kron(eye(length(S)),Rybounds(:,:,1)),1))* kron(eye(length(S)),Rybounds(:,:,1))]);
248 Qzbounds(:,:,end)=[0 zeros(1,length(kron(alpha,kron(pi0,theta0)))); ones(size(Qzbounds(:,:,1),1)-1,1) -eye(size(Qzbounds(:,:,1),1)-1)];
249 Rzbounds(:,:,end)=Rzbounds(:,:,1).*0;
250 Rzbounds(1,1,end)=-1;
254 driftbound(1,:)=[diag(Rzbounds(:,:,1))'];
256 for reg=1:length(BoundaryLevelsLast)
257 driftregimes(reg,:)=[diag(Rz(:,:,reg))'];
258 driftbound(reg+1,:)=[diag(Rzbounds(:,:,reg+1))'];
264 [MESystem,cv]= CMEParameterCalculator(n,tau);
269 alpha=zeros(1,OrderofPH);
271 ss=-ones(1,OrderofPH);
281 while BoundaryLevels(count)<b
284 BoundaryLevelsLast=BoundaryLevels(1:count);
285 BoundaryLevelsLast(count)=b;
286 BoundaryLevelsLast(count+1: length(BoundaryLevels)+1)=BoundaryLevels(count: length(BoundaryLevels));
288 Ryboundstemp=Rybounds;
290 Qyboundstemp=Qybounds;
291 Rytemp(:,:,end+1)=Ry;
292 Ryboundstemp(:,:,end+1)=Ry;
293 Qytemp(:,:,count+1:end+1)=Qy(:,:,count:end);
294 Qyboundstemp(:,:,count+2:end+1)=Qybounds(:,:,count+1:end);
295 Qyboundstemp(:,:,count+1)=Qybounds(:,:,count+1);
297 for reg=1:length(BoundaryLevelsLast)
298 eTilde= ones(1,length(Qybounds(:,:,reg)));
299 eTilde(end-MAPSIZE+1:end)=0;
302 QzTilde(:,:,reg)=[0 0 zeros(1,length(kron(alpha,kron(pi0,theta0))));0 0 zeros(1,length(kron(alpha,kron(pi0,theta0))));zeros(length(kron(S0,diag(ITilde))),1) kron(S0,diag(ITilde)) (kron(eye(length(S)),Qytemp(:,:,reg))+kron(S,ITilde))];
303 QzboundsTilde(:,:,reg+1)=[0 0 zeros(1,length(kron(alpha,kron(pi0,theta0))));0 0 zeros(1,length(kron(alpha,kron(pi0,theta0))));zeros(length(kron(S0,diag(ITilde))),1) kron(S0,diag(ITilde)) (kron(eye(length(S)),Qyboundstemp(:,:,reg+1))+kron(S,ITilde))];
305 RzTilde(:,:,reg)=diag([-1 -1 ones(1,size(kron(eye(length(S)),Rytemp(:,:,reg)),1))* kron(eye(length(S)),Rytemp(:,:,reg))]);
306 RzboundsTilde(:,:,reg+1)=diag([-1 -1 ones(1,size(kron(eye(length(S)),Ryboundstemp(:,:,reg+1)),1))* kron(eye(length(S)),Ryboundstemp(:,:,reg+1))]);
308 QzboundsTilde(:,:,1)=[-1 1 zeros(1,length(kron(alpha,kron(pi0,theta0))));0 -1 kron(alpha,kron(pi0,theta0));zeros(length(kron(S0,diag(ITilde))),1) kron(S0,diag(ITilde)) (kron(eye(length(S)),Qybounds(:,:,1))+kron(S,ITilde))];
309 RzboundsTilde(:,:,1)=diag([-1 -1 ones(1,size(kron(eye(length(S)),Ryboundstemp(:,:,1)),1))* kron(eye(length(S)),Ryboundstemp(:,:,1))]);
312 Qbounds=QzboundsTilde;
314 driftbound(1,:)=[diag(RzboundsTilde(:,:,1))'];
316 for reg=1:length(BoundaryLevelsLast)
317 driftregimes(reg,:)=[diag(RzTilde(:,:,reg))'];
318 driftbound(reg+1,:)=[diag(RzboundsTilde(:,:,reg+1))'];
320 for reg=count+1:length(BoundaryLevelsLast)
322 index=2+(d-1)*size(Qy,2)+size(Qy,2)-2*MAPSIZE+1;
323 Qbounds(index:index+MAPSIZE-1,1,reg)=Qbounds(index:index+MAPSIZE-1,index+MAPSIZE:index+2*MAPSIZE-1,reg)*ones(MAPSIZE,1);
324 Qbounds(index:index+MAPSIZE-1,index+MAPSIZE:index+2*MAPSIZE-1,reg)=zeros(MAPSIZE,MAPSIZE);
325 Qregimes(index:index+MAPSIZE-1,1,reg)=Qregimes(index:index+MAPSIZE-1,index+MAPSIZE:index+2*MAPSIZE-1,reg)*ones(MAPSIZE,1);
326 Qregimes(index:index+MAPSIZE-1,index+MAPSIZE:index+2*MAPSIZE-1,reg)=zeros(MAPSIZE,MAPSIZE);
329 Qbounds(index:index+MAPSIZE-1,1,end)=Qbounds(index:index+MAPSIZE-1,index+MAPSIZE:index+2*MAPSIZE-1,end)*ones(MAPSIZE,1);
330 Qbounds(index:index+MAPSIZE-1,index+MAPSIZE:index+2*MAPSIZE-1,end)=zeros(MAPSIZE,MAPSIZE);
336[coefficients,boundaries,Lzeromulti,Lnegmulti,Lposmulti,Anegmulti,Aposmulti]=MRMFQSolver(Qregimes,Qbounds,driftregimes,driftbound,BoundaryLevelsLast);
351%OUTPUT CALCULATION_______________________________________________________
353%Based on the chosen SOLUTION get the results from the outputs of MRMFQ solver
355 zeromass=boundaries{1};
356 integral(1,:) =coefficients{1}*[Lzeromulti{1}*(B(1)-0); Anegmulti{1}\(expm(Anegmulti{1}*((B(1)-0)))-eye(size(Anegmulti{1},1)))*Lnegmulti{1};(Aposmulti{1})\(eye(size(Aposmulti{1},1))-expm((-Aposmulti{1})*(B(1)-0)))*Lposmulti{1}];
357 waitintegral(1,:) =(B(1)/2)*(1-(ga(2)))*coefficients{1}*[Lzeromulti{1}*(B(1)-0); Anegmulti{1}\(expm(Anegmulti{1}*((B(1)-0)))-eye(size(Anegmulti{1},1)))*Lnegmulti{1};(Aposmulti{1})\(eye(size(Aposmulti{1},1))-expm((-Aposmulti{1})*(B(1)-0)))*Lposmulti{1}];
358 abandonintegral(1,:) =(ga(2))*coefficients{1}*[Lzeromulti{1}*(B(1)-0); Anegmulti{1}\(expm(Anegmulti{1}*((B(1)-0)))-eye(size(Anegmulti{1},1)))*Lnegmulti{1};(Aposmulti{1})\(eye(size(Aposmulti{1},1))-expm((-Aposmulti{1})*(B(1)-0)))*Lposmulti{1}];
359 successfulintegral(1,:) =(1-(ga(2)))*coefficients{1}*[Lzeromulti{1}*(B(1)-0); Anegmulti{1}\(expm(Anegmulti{1}*((B(1)-0)))-eye(size(Anegmulti{1},1)))*Lnegmulti{1};(Aposmulti{1})\(eye(size(Aposmulti{1},1))-expm((-Aposmulti{1})*(B(1)-0)))*Lposmulti{1}];
361 integral(d,:) =coefficients{d}*[Lzeromulti{d}*(B(d)-B(d-1)); Anegmulti{d}\(expm(Anegmulti{d}*((B(d)-B(d-1))))-eye(size(Anegmulti{d},1)))*Lnegmulti{d};(Aposmulti{d})\(eye(size(Aposmulti{d},1))-expm((-Aposmulti{d})*(B(d)-B(d-1))))*Lposmulti{d}];
362 waitintegral(d,:) =((B(d)+B(d-1))/2)*(1-(ga(d+1)))*coefficients{d}*[Lzeromulti{d}*(B(d)-B(d-1)); Anegmulti{d}\(expm(Anegmulti{d}*((B(d)-B(d-1))))-eye(size(Anegmulti{d},1)))*Lnegmulti{d};(Aposmulti{d})\(eye(size(Aposmulti{d},1))-expm((-Aposmulti{d})*(B(d)-B(d-1))))*Lposmulti{d}];
363 abandonintegral(d,:) =(ga(d+1))*coefficients{d}*[Lzeromulti{d}*(B(d)-B(d-1)); Anegmulti{d}\(expm(Anegmulti{d}*((B(d)-B(d-1))))-eye(size(Anegmulti{d},1)))*Lnegmulti{d};(Aposmulti{d})\(eye(size(Aposmulti{d},1))-expm((-Aposmulti{d})*(B(d)-B(d-1))))*Lposmulti{d}];
364 successfulintegral(d,:) =(1-(ga(d+1)))*coefficients{d}*[Lzeromulti{d}*(B(d)-B(d-1)); Anegmulti{d}\(expm(Anegmulti{d}*((B(d)-B(d-1))))-eye(size(Anegmulti{d},1)))*Lnegmulti{d};(Aposmulti{d})\(eye(size(Aposmulti{d},1))-expm((-Aposmulti{d})*(B(d)-B(d-1))))*Lposmulti{d}];
368 ArrivalsWaitLessThanX=zeros(length(x),size(integral,2));
375 int=(1-(ga(count+1)))*coefficients{count}*[Lzeromulti{count}*(x(d)-B(count-1)); Anegmulti{count}\(expm(Anegmulti{count}*(x(d)-B(count-1)))-eye(size(Anegmulti{count},1)))*Lnegmulti{count};(Aposmulti{count})\(expm((-Aposmulti{count})*(B(count)-x(d)))-expm((-Aposmulti{count})*(B(count)-B(count-1))))*Lposmulti{count}];
377 int=(1-(ga(count+1)))*coefficients{count}*[Lzeromulti{count}*(x(d)-0); Anegmulti{count}\(expm(Anegmulti{count}*(x(d)-0))-eye(size(Anegmulti{count},1)))*Lnegmulti{count};(Aposmulti{count})\(expm((-Aposmulti{count})*(B(count)-x(d)))-expm((-Aposmulti{count})*(B(count)-0)))*Lposmulti{count}];
381 ArrivalsWaitLessThanX(d,:)=ArrivalsWaitLessThanX(d,:)+successfulintegral(l-1,:);
384 ArrivalsWaitLessThanX(d,:)=ArrivalsWaitLessThanX(d,:)+int;
387 for r=1:length(zeromass)
388 ArrivalsWaitLessThanXmapped(:,r)=ArrivalsWaitLessThanX(:,r)*lmap(rem(r-1,2)+1);
389 IntegralMapped(:,r)=integral(:,r)*lmap(rem(r-1,2)+1);
390 AbandonIntegralMapped(:,r)=abandonintegral(:,r)*lmap(rem(r-1,2)+1);
391 WaitIntegralMapped(:,r)=waitintegral(:,r)*lmap(rem(r-1,2)+1);
392 ZeroMassMapped(r)=zeromass(r)*lmap(rem(r-1,2)+1);
394 normalization=SERVERSIZE*MAPSIZE;
396 w0=sum(ZeroMassMapped)/(sum(sum(IntegralMapped(:,1:normalization)))+sum(ZeroMassMapped));
397 AbandonProb=sum(sum(AbandonIntegralMapped(:,1:normalization)))/(sum(ZeroMassMapped)+sum(sum(IntegralMapped(:,1:normalization))));
398 w0s=sum(ZeroMassMapped)/((sum(sum(IntegralMapped(:,1:normalization)))+sum(ZeroMassMapped))*(1-AbandonProb));
399 ProbArrivalsWaitLessThan01=sum(ArrivalsWaitLessThanXmapped(1,1:normalization))/((sum(sum(IntegralMapped(:,1:normalization)))+sum(ZeroMassMapped))*(1-AbandonProb)*(1-w0s));
400 ProbArrivalsWaitLessThan02=sum(ArrivalsWaitLessThanXmapped(2,1:normalization))/((sum(sum(IntegralMapped(:,1:normalization)))+sum(ZeroMassMapped))*(1-AbandonProb)*(1-w0s));
401 ExpectedWait=sum(sum(WaitIntegralMapped(:,1:normalization)))/((sum(ZeroMassMapped)+sum(sum(IntegralMapped(:,1:normalization))))*(1-AbandonProb));
403 VarianceIntegral(1,:) =((B(1)/2)-ExpectedWait)^2*(1-(ga(2)))*coefficients{1}*[Lzeromulti{1}*(B(1)-0); Anegmulti{1}\(expm(Anegmulti{1}*((B(1)-0)))-eye(size(Anegmulti{1},1)))*Lnegmulti{1};(Aposmulti{1})\(eye(size(Aposmulti{1},1))-expm((-Aposmulti{1})*(B(1)-0)))*Lposmulti{1}];
405 VarianceIntegral(d,:) =(((B(d)+B(d-1))/2)-ExpectedWait)^2*(1-(ga(d+1)))*coefficients{d}*[Lzeromulti{d}*(B(d)-B(d-1)); Anegmulti{d}\(expm(Anegmulti{d}*((B(d)-B(d-1))))-eye(size(Anegmulti{d},1)))*Lnegmulti{d};(Aposmulti{d})\(eye(size(Aposmulti{d},1))-expm((-Aposmulti{d})*(B(d)-B(d-1))))*Lposmulti{d}];
407 for r=1:length(zeromass)
408 VarianceIntegralMapped(:,r)=VarianceIntegral(:,r)*lmap(rem(r-1,2)+1);
410 Variance=(sum(sum(VarianceIntegralMapped(:,1:normalization)))+sum(ZeroMassMapped)*ExpectedWait^2)/((sum(ZeroMassMapped)+sum(sum(IntegralMapped(:,1:normalization))))*(1-AbandonProb));
412 steadyStateResult=[w0 w0s AbandonProb ExpectedWait Variance ProbArrivalsWaitLessThan01 ProbArrivalsWaitLessThan02];
414 disp(
' PR{W=0} PR{W=0|S} PR{A} E{W|S} Var{W|S} Fw|s,w>0(.1)Fw|s,w>0(.2)')
415 disp([w0 w0s AbandonProb ExpectedWait Variance ProbArrivalsWaitLessThan01 ProbArrivalsWaitLessThan02])
430 FirstPassageTimeofVirtual=(sum(cb))/ca(1)
434 FirstPassageTimeofActual=ca(1)/ca(2)