You are on page 1of 6

Name: Mahesh A Abnave BEIT 500862

Title: Multi Server System simulation using MS Excel Macros

Macros:

Sub MSQAT()
' Calculate the "Time between Arrival" and "CLK for Arrival" for Multi server queue problem.
For custCount = 28 To 46
rnIAT = Range("B" + CStr(custCount)).Value

For iatTable = 4 To 8
minRange = "D"
minRange = minRange + CStr(iatTable)

Trim (minRange)
maxRange = "E" + CStr(iatTable)
Trim (maxRange)

If rnIAT <= Range(maxRange).Value Then


rowNo = iatTable
Exit For
End If

If Range(maxRange).Value = 0 Then
rowNo = iatTable
End If
Next iatTable

Range("A" + CStr(rowNo)).Select
Selection.Copy

Range("C" + CStr(custCount)).Select
ActiveSheet.Paste

'generate the CLK for Arrival


Range("D" + CStr(custCount)).Value = Range("D" + CStr(custCount - 1)).Value + Range("C" +
CStr(custCount)).Value

Next custCount
End Sub

Sub MSQST()
' This macro generates last seven columns in the MSQ problem, namely Time Service Begins, Service
Time, Time Service Ends for both Able and Baker and Time in Queue column.

'The first customer will be served by the Able. Thus, initialize Ables' first row
Range("F27").Value = 0
Range("G27").Value = GetStforAble(Range("E27").Value)
Range("H27").Value = GetStforAble(Range("E27").Value)

For custCount = 28 To 46 'For all customers


Dim ableTSE As Integer 'TSE => Time Service Ends
Dim bakerTSE As Integer

blnTrue = True 'dummy variable used for construccinfinite loop

'get the previous service end time for Able


tempCustCount = custCount
Do While blnTrue = True
If (Range("H" + CStr(tempCustCount - 1)) = 0) Then 'If previous request is not served
'by the Baker
tempCustCount = tempCustCount - 1 'look for the row above the
'previous one
Else
ableTSE = Range("H" + CStr(tempCustCount - 1)).Value 'copy the value when the
'Able was freed of work

1
Exit Do
End If
If (tempCustCount = 27) Then 'if the loop reaches the row of first customer
ableTSE = 0 'this means Baker did not served any request yet
'(though this condition never occurs, it occues for Baker)
Exit Do
End If
Loop

'get the previous service end time for Baker


tempCustCount = custCount

Do While blnTrue = True


If (Range("K" + CStr(tempCustCount - 1)) = 0) Then 'If previous request is not served
'by the Baker
tempCustCount = tempCustCount - 1 'look for the row above the
'previous one
Else
bakerTSE = Range("K" + CStr(tempCustCount - 1)).Value 'copy the value when the
Baker was freed of work
Exit Do
End If
If (tempCustCount = 27) Then 'if the loop reaches the row of first customer
bakerTSE = 0 'this means Baker did not served any request yet
Exit Do
End If
Loop

Dim clkArrival As Integer


clkArrival = Range("D" + CStr(custCount)).Value
Dim st As Integer
st = Range("E" + CStr(custCount)).Value

If (ableTSE <= clkArrival) Then 'Check if Able is free


Range("F" + CStr(custCount)).Value = clkArrival 'Service begin = arrival time
Range("G" + CStr(custCount)).Value = GetStforAble(st) 'service time from ables table
Range("H" + CStr(custCount)).Value = Range("F" + CStr(custCount)).Value + Range("G" +
CStr(custCount)).Value 'service time end = sum of above two
Range("L" + CStr(custCount)).Value = 0 'Request was immediately served, thus nowaiting
'in queue
ElseIf (bakerTSE <= clkArrival) Then 'Check if Baker is free
Range("I" + CStr(custCount)).Value = clkArrival 'Service begin = arrival time
Range("J" + CStr(custCount)).Value = GetStforBaker(st) 'service time from ables table
Range("K" + CStr(custCount)).Value = Range("I" + CStr(custCount)).Value + Range("J" +
CStr(custCount)).Value 'service time end = sum of above two
Range("L" + CStr(custCount)).Value = 0 'Request was immediately served, thus nowaiting
'in queue
Else 'Neither Able is free nor Baker
If (ableTSE <= bakerTSE) Then 'If Able frees before or at the same time as Baker
Range("F" + CStr(custCount)).Value = ableTSE 'Service begin = arrival time
Range("G" + CStr(custCount)).Value = GetStforAble(st) 'service time from ables
'table
Range("H" + CStr(custCount)).Value = Range("F" + CStr(custCount)).Value + Range("G"
+ CStr(custCount)).Value 'service time end = sum of above two
Range("L" + CStr(custCount)).Value = ableTSE - clkArrival 'Wait in Queue = Time
'Able Freed (ableTSE) - Arrival Clock time
Else 'Baker frees before Able
Range("I" + CStr(custCount)).Value = bakerTSE 'Service begin = arrival time
Range("J" + CStr(custCount)).Value = GetStforBaker(st) 'service time from Ables
'table
Range("K" + CStr(custCount)).Value = Range("I" + CStr(custCount)).Value + Range("J"
+ CStr(custCount)).Value 'service time end = sum of above two
Range("L" + CStr(custCount)).Value = bakerTSE - clkArrival 'Wait in Queue = Time
'Baker Freed (bakerTSE) - Arrival Clock time
End If
End If
Next custCount
End Sub

2
'This function returns the Service time for the Able provided the Random Number(RN) for service
'time as input
Function GetStforAble(ByVal rnst As Integer) As Integer 'rnst => Random Number for Service Time

For stAbleTable = 12 To 15 'For all entries in Ables' Service Time Table


minRange = "D" + CStr(stAbleTable) 'Get the cell number for the Minimum Value for
'Current Range Interval
Trim (minRange)

maxRange = "E" + CStr(stAbleTable) 'Get the cell number for the Maximum Value for
Current Range Interval
Trim (maxRange)

If rnst <= Range(maxRange).Value Then


rowNo = stAbleTable 'copy the row no. in Ables' Service table
Exit For 'Exit to loop, no need to continue
End If
If Range(maxRange).Value = 0 Then 'For final entry in Ables' Service table, Max
value for Range is 0 (in say 89-00)
rowNo = stAbleTable 'copy the row no. in Ables' Service table
End If
Next stAbleTable

retValCell = "A" + CStr(rowNo) 'Form the cell no. containing the needed service time

retVal = Range(retValCell).Value 'get the service time

GetStforAble = retVal 'Return. This is VB syntax: Function_name = value. There


'is another syntax similar to what we use in Java.
End Function

'This function returns the Service time for the Able provided the Random Number for service time as
'input
'Similar to GetStforAble, get the help from its comments
Function GetStforBaker(ByVal rnst As Integer) As Integer 'rdst => Random Digit for Service Time

For stBakerTable = 19 To 22
minRange = "D" + CStr(stBakerTable)
Trim (minRange)

maxRange = "E" + CStr(stBakerTable)


Trim (maxRange)

If rnst <= Range(maxRange).Value Then


rowNo = stBakerTable
Exit For
End If

If Range(maxRange).Value = 0 Then
rowNo = stBakerTable
End If
Next stBakerTable

retValCell = "A" + CStr(rowNo)


retVal = Range(retValCell).Value
GetStforBaker = retVal

End Function

Sub CalcStats()
' CalcStats Macro
'Calculating Total Serivice Time for Able

Dim noCustWait As Integer


noCustWait = 0

Dim ttlServiceAbleTime As Integer

3
ttlServiceAbleTime = 0
For custCount = 27 To 46
If (Range("G" + CStr(custCount)).Value <> 0) Then
ttlServiceAbleTime = ttlServiceAbleTime + Range("G" + CStr(custCount)).Value
End If
Next custCount
Range("G47").Value = "Total ST = " & ttlServiceAbleTime

'Calculating Total Serivice Time for Baker


Dim ttlServiceBakerTime As Integer
ttlServiceBakerTime = 0
For custCount = 28 To 46
If (Range("J" + CStr(custCount)).Value <> 0) Then
ttlServiceBakerTime = ttlServiceBakerTime + Range("J" + CStr(custCount)).Value
End If
Next custCount
Range("J47").Value = "Total ST = " & ttlServiceBakerTime

'Calculating Total Time In Queue


Dim ttlQueueWaitTime As Integer
ttlQueueWaitTime = 0
For custCount = 28 To 46
If (Range("L" + CStr(custCount)).Value <> 0) Then
noCustWait = noCustWait + 1
ttlQueueWaitTime = ttlQueueWaitTime + Range("L" + CStr(custCount)).Value
End If
Next custCount
Range("L47").Value = "Total Time in Queue: " & ttlQueueWaitTime

'Time Able busy


If (Range("H46").Value <> 0) Then
Range("A50").Value = "Time Able was busy: " & ttlServiceAbleTime & " Min" & " (" &
(ttlServiceAbleTime / Range("H46").Value) & " %)"
Else
Range("A50").Value = "Time Able was busy: " & ttlServiceAbleTime & " Min" & " (" &
(ttlServiceAbleTime / Range("K46").Value) & " %)"
End If

'Time Baker busy


If (Range("H46").Value <> 0) Then
Range("A51").Value = "Time Baker was busy: " & ttlServiceBakerTime & " Min" & " (" &
(ttlServiceBakerTime / Range("H46").Value) & " %)"
Else
Range("A51").Value = "Time Baker was busy: " & ttlServiceBakerTime & " Min" & " (" &
(ttlServiceBakerTime / Range("K46").Value) & " %)"
End If

'Number of Customers that have to wait in queue


Range("A52").Value = "Number of Customers need to wait: " & noCustWait & " (" & (noCustWait /
20 * 100) & " %)"

'Average waiting time for all customers:


Range("A53").Value = "Average waiting time for all customers: " & (ttlQueueWaitTime / 20)

End Sub

4
Output:
Random Digit Assignment to Interarrival Time
IAT Probablity Cum Probability R.N. (Min) R.N. (Max) R.N. Range
1 0.05 0.05 01 05 1-5
2 0.25 0.3 06 30 6-30
3 0.3 0.6 31 60 31-60
4 0.25 0.85 61 85 61-85
5 0.15 1 86 00 86-0

Random Digit Assignment to service time of Able


Service Time Probability Cum Probability R.N.(Min) R.N.(Max) R.N. Range
2 0.2 0.2 01 20 1-20
3 0.35 0.55 21 55 21-55
4 0.3 0.85 56 85 56-85
5 0.15 1 86 00 86-0

Random Digit Assignment to service time of Baker


Service Time Probability Cum Probability R.N.(Min) R.N.(Max) R.N. Range
3 0.38 0.38 01 38 1-38
4 0.25 0.63 39 63 39-63
5 0.18 0.81 64 81 64-81
6 0.19 1 82 00 82-0

Simulation table for Able-Baker Carhop Problem


Able Baker
Time CLK RD Time
RD for Time Time Time Time
Customer Between for for Service Service In
Arrival Service Service Service Service
arrival Arrival Service Time Time Queue
Begin Ends Begin Ends

1 25 0 3 3
2 95 5 5 38 5 3 8 0
3 26 2 7 61 7 4 11 0
4 43 3 10 52 10 3 13 0
5 71 4 14 1 14 2 16 0
6 12 2 16 47 16 3 19 0
7 51 3 19 72 19 4 23 0
8 80 4 23 89 23 5 28 0
9 68 4 27 39 27 4 31 0
10 34 3 30 64 30 4 34 0
11 62 4 34 90 34 5 39 0
12 7 2 36 2 36 3 39 0
13 81 4 40 82 40 4 44 0
14 97 5 45 44 45 3 48 0
15 76 4 49 19 49 2 51 0
16 33 3 52 75 52 4 56 0
17 49 3 55 51 55 4 59 0
18 21 2 57 97 57 5 62 0
19 5 1 58 31 59 3 62 1
20 22 2 60 73 62 4 66 2
Total
Time
in
Queue:
Total ST = 54 Total ST = 18 3

Queuing Statistics
Time Able was busy: 54 Min (0.818181818181818 %)

5
Time Baker was busy: 18 Min (0.272727272727273 %)
Number of Customers need to wait: 2 (10 %)
Average waiting time for all customers: 0.15