Problem with queue simulation
larry
laurence.thayer at navy.mil
Mon Oct 26 16:26:55 EDT 2009
I am trying to update the single server queue model Gillett has in his
Intro to operations research book. I scrapped his use of Randu since
that has been discredited as random number generator, however this
seems to fill up too fast and I am getting values in the results for
queue size and time in system that seem excessive. Any ideas?
Option Explicit
Public Arr_rate As Single, Service_rate As Single, Clock As Single,
Arr_time As Single, Time_Sys As Single
Public Tot_Wait_Time As Single, Tot_Idle_time As Single, Ser_time As
Single, Time_Serv_fac As Single
Public Avg_Time_Sys As Single, Avg_Time_Fac As Single, Avg_Time_Q As
Single, Avg_Time_Wait As Single, Percent_Busy As Single
Public Max_cnt As Long, No_In_Q As Integer, Total_Q As Integer, No_arr
As Integer, Max_Q As Integer
Sub q_sim()
Arr_rate = Cells(2, 2).Value
Service_rate = Cells(3, 2).Value
Max_cnt = Cells(4, 2).Value
Clock = 0!
Arr_time = 0#
No_In_Q = 0
Total_Q = 0
Tot_Wait_Time = 0#
Tot_Idle_time = 0#
No_arr = 1
Max_Q = 0
Ser_time = Clock + (-1# / Service_rate) * Log(Rnd)
Do Until Clock > Max_cnt
Select Case Ser_time - Arr_time
Case Is < 0
If No_In_Q = 0 Then
Clock = Ser_time
Tot_Idle_time = Tot_Idle_time + (Arr_time - Clock)
Clock = Arr_time
No_arr = No_arr + 1
Ser_time = Clock + (-1# / Service_rate) / Log(Rnd)
Else
Tot_Wait_Time = Tot_Wait_Time + No_In_Q * (Ser_time - Clock)
Clock = Ser_time
No_In_Q = No_In_Q - 1
Ser_time = Clock + (-1# / Service_rate) / Log(Rnd)
End If
Case Is = 0
Tot_Wait_Time = Tot_Wait_Time + No_In_Q * (Arr_time - Clock)
Clock = Arr_time
No_arr = No_arr + 1
Arr_time = Clock + (-1# / Arr_rate) / Log(Rnd)
Ser_time = Clock + (-1# / Service_rate) * Log(Rnd)
Case Is > 0
Tot_Wait_Time = Tot_Wait_Time + No_In_Q * (Arr_time - Clock)
Clock = Arr_time
No_arr = No_arr + 1
No_In_Q = No_In_Q + 1
If No_In_Q > Max_Q Then
Max_Q = No_In_Q
End If
Total_Q = Total_Q + 1
Arr_time = Clock + (-1# / Arr_rate) * Log(Rnd)
End Select
Loop
Time_Serv_fac = Clock - Tot_Idle_time
Cells(6, 2).Value = Time_Serv_fac
Time_Sys = Time_Serv_fac + Tot_Wait_Time
Cells(7, 2).Value = Time_Sys
Avg_Time_Sys = Time_Sys / No_arr
Cells(8, 2).Value = Avg_Time_Sys
Avg_Time_Fac = Time_Serv_fac / No_arr
Cells(9, 2).Value = Avg_Time_Fac
Avg_Time_Q = Tot_Wait_Time / No_arr
Cells(10, 2).Value = Avg_Time_Q
Avg_Time_Wait = Tot_Wait_Time / Total_Q
Cells(11, 2).Value = Avg_Time_Wait
Cells(12, 2).Value = Tot_Idle_time
Percent_Busy = Time_Serv_fac / Clock
Cells(13, 2).Value = Percent_Busy
Cells(14, 2).Value = Max_Q
End Sub
More information about the comp-simulation
mailing list