def Arrival(): NewCar = bc.Entity(Clock) ParkingLot.Add(NewCar, Clock) VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) VBASim.Schedule(Calendar, "Departure", RNG.Expon(MeanPT, 2), Clock) global MaxCars if ParkingLot.NumQueue() > MaxCars: MaxCars = ParkingLot.NumQueue()
def Arrival(): VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) Customer = Basic_Classes.Entity(Clock) Queue.Add(Customer, Clock) if Server.Busy == 0: Server.Seize(1, Clock) VBASim.Schedule(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), Clock)
def Arrival(): VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) Customer = Basic_Classes.Entity(Clock) Queue.Add(Customer, Clock) # queue here includes the customers in service if Server.Busy < Server.NumberOfUnits: # if there is an idle server available Server.Seize(1, Clock) VBASim.Schedule(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), Clock)
def Arrival(): VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) Customer = Basic_Classes.Entity(Clock) Queue.Add(Customer, Clock) if Server.Busy < Server.NumberOfUnits: # if not all servers are busy, we can schedule a service Server.Seize(1, Clock) VBASim.Schedule(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), Clock)
def Arrival(): VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) if Queue.NumQueue( ) >= c: # if there are c or more customers in the system, # the new customer will return after an exponentiallly distributed time VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTR, 1), Clock) else: # fewer than c customers in the system Customer = Basic_Classes.Entity(Clock) Queue.Add(Customer, Clock) if Server.Busy == 0: Server.Seize(1, Clock) VBASim.Schedule(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), Clock)
def Arrival(): VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) Customer = Basic_Classes.Entity(Clock) Queue.Add(Customer, Clock) if Server.Busy < Server.NumberOfUnits: # if not all servers are busy, we can schedule a service Server.Seize(1, Clock) if Uniform(0, 1, 1) < 0.59: # 59% Financial Customer VBASim.Schedule(Calendar, "EndOfService1", RNG.Erlang(Phase1, MeanST1, 2), Clock) else: VBASim.Schedule(Calendar, "EndOfService2", RNG.Erlang(Phase2, MeanST2, 3), Clock)
def EndOfService1(): global Total_Customer1 Total_Customer1 += 1 DepartingCustomer1 = Queue.Remove(Clock) Wait.Record(Clock - DepartingCustomer1.CreateTime) if Queue.NumQueue() >= Server.NumberOfUnits: if Uniform(0, 1, 1) < 0.59: VBASim.Schedule(Calendar, "EndOfService1", RNG.Erlang(Phase1, MeanST1, 2), Clock) else: VBASim.Schedule(Calendar, "EndOfService2", RNG.Erlang(Phase2, MeanST2, 3), Clock) else: Server.Free(1, Clock)
def EndOfService2(): global Total_Customer2 Total_Customer2 += 1 DepartingCustomer2 = Queue.Remove(Clock) Wait.Record(Clock - DepartingCustomer2.CreateTime) if Queue.NumQueue() >= Server.NumberOfUnits: if Uniform(0, 1, 1) < 0.59: # if there are enough customers waiting, we can schedule a service VBASim.Schedule(Calendar, "EndOfService1", RNG.Erlang(Phase1, MeanST1, 2), Clock) else: VBASim.Schedule(Calendar, "EndOfService2", RNG.Erlang(Phase2, MeanST2, 3), Clock) else: Server.Free(1, Clock)
def EndOfService(): DepartingCustomer = Queue.Remove(Clock) Wait.Record(Clock - DepartingCustomer.CreateTime) if Queue.NumQueue() > 0: VBASim.Schedule(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), Clock) else: Server.Free(1, Clock)
def EndOfService(): DepartingCustomer = Queue.Remove(Clock) Wait.Record(Clock - DepartingCustomer.CreateTime) if (Queue.NumQueue() >= Server.NumberOfUnits): # if there are enough customers waiting, we can schedule a service VBASim.Schedule(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), Clock) else: Server.Free(1, Clock)
def EndOfService2(): global Total_Customer2 Total_Customer2 += 1 DepartingCustomer2 = Queue2.Remove(Clock) Wait.Record(Clock - DepartingCustomer2.CreateTime) if Queue2.NumQueue() >= Server2.NumberOfUnits: VBASim.Schedule(Calendar, "EndOfService2", RNG.Erlang(Phase2, MeanST2, 3), Clock) else: Server2.Free(1, Clock)
def Arrival2(): VBASim.Schedule(Calendar, "Arrival2", RNG.Expon(MeanTBA2, 2), Clock) Customer2 = Basic_Classes.Entity(Clock) # Go to B, or add in Queue2 if ServerB.Busy < ServerB.NumberOfUnits: # Go to ServerB ServerB.Seize(1, Clock) VBASim.SchedulePlus(Calendar, "EndOfServiceB2", RNG.Expon(MeanPT2, 5), Customer2, Clock) else: # Add in Queue2 Queue2.Add(Customer2, Clock)
def ItemArrival(): global NumSold, M, OrderPlaced, NumtoOrder for i in range (NumtoOrder): Queue.Add(0,Clock) OrderPlaced = 0 if Queue.NumQueue() < s: NumtoOrder = S - Queue.NumQueue() VBASim.Schedule(Calendar,"ItemArrival",RNG.Expon(MeanLead, 2),Clock) OrderPlaced = 1 M += NumtoOrder
def Arrival(): global Clock, rates VBASim.Schedule(Calendar, "Arrival", RNG.Expon(60.0 / rates[int(Clock / 60.0)], 1), Clock) Customer = Basic_Classes.Entity(Clock) if Uniform(0, 1, 1) < 0.59: # 59% Financial Customer Queue1.Add(Customer, Clock) if Server1.Busy < Server1.NumberOfUnits: # if not all servers are busy, we can schedule Service1 Server1.Seize(1, Clock) VBASim.Schedule(Calendar, "EndOfService1", RNG.Erlang(Phase1, MeanST1, 2), Clock) else: Queue2.Add(Customer, Clock) if Server2.Busy < Server2.NumberOfUnits: # if not all servers are busy, we can schedule a service Server2.Seize(1, Clock) VBASim.Schedule(Calendar, "EndOfService2", RNG.Erlang(Phase2, MeanST2, 3), Clock)
def DemandArrival(): global NumSold, M, OrderPlaced, NumtoOrder VBASim.Schedule(Calendar,"DemandArrival",RNG.Expon(MeanTBA, 1),Clock) B = 1 # generating Geometric r.v.: while True: if RNG.Uniform(0,1,3) < p: break else: B += 1 if Queue.NumQueue() > 0: # if Inventory > 0: num = min(B,Queue.NumQueue()) # number of items sold NumSold += num for i in range (num): Queue.Remove(Clock) # reduce inventory if Queue.NumQueue() < s and OrderPlaced == 0: NumtoOrder = S - Queue.NumQueue() VBASim.Schedule(Calendar,"ItemArrival",RNG.Expon(MeanLead, 2),Clock) OrderPlaced = 1 # change the state whether an order is placed M += NumtoOrder
def Simulation(): global NumSold, M, OrderPlaced, NumtoOrder, Clock VBASim.VBASimInit(Calendar,TheQueues,TheCTStats,TheDTStats,TheResources,Clock) for i in range (S): # Initial inventory is S Queue.Add(0,Clock) VBASim.Schedule(Calendar,"DemandArrival",RNG.Expon(MeanTBA, 1),Clock) VBASim.Schedule(Calendar,"EndSimulation",T,Clock) NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "DemandArrival": DemandArrival() elif NextEvent.EventType == "ItemArrival": ItemArrival() while NextEvent.EventType != "EndSimulation": NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "DemandArrival": DemandArrival() elif NextEvent.EventType == "ItemArrival": ItemArrival()
def EndOfService1(): global Total_Customer1 Total_Customer1 += 1 DepartingCustomer1 = Queue1.Remove(Clock) Wait.Record(Clock - DepartingCustomer1.CreateTime) if Queue1.NumQueue() >= Server1.NumberOfUnits: # if there are enough customers waiting, we can schedule a service VBASim.Schedule(Calendar, "EndOfService1", RNG.Erlang(Phase1, MeanST1, 2), Clock) else: Server1.Free(1, Clock)
def Arrival(): VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) Customer = bc.Entity(Clock) if Server.Busy < Server.NumberOfUnits: Server.Seize(1, Clock) VBASim.SchedulePlus(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), Customer, Clock) WaitingTime.Record(0) WTrecords.append(0) else: WaitingList.Add(Customer, Clock)
def EndOfService(): DepartingCustomer = Queue.Remove(Clock) waitingtime = Clock - DepartingCustomer.CreateTime Wait.Record(waitingtime) waitings.append(waitingtime) if waitingtime > 3: Longwait.Record(waitingtime) if Queue.NumQueue() >= Server.NumberOfUnits: # a new service starts VBASim.Schedule(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), Clock) else: Server.Free(1, Clock)
def Arrival1(): VBASim.Schedule(Calendar, "Arrival1", RNG.Expon(MeanTBA1, 1), Clock) Customer1 = Basic_Classes.Entity(Clock) # Go to A, or go to B, or add in Queue1 if ServerA.Busy < ServerA.NumberOfUnits: # Go to ServerA ServerA.Seize(1, Clock) VBASim.SchedulePlus(Calendar, "EndOfServiceA", RNG.Expon(MeanPT1_1, 3), Customer1, Clock) elif (ServerB.Busy < ServerB.NumberOfUnits) and (Queue1.NumQueue == 0): # Go to ServerB ServerB.Seize(1, Clock) VBASim.SchedulePlus(Calendar, "EndOfServiceB1", RNG.Expon(MeanPT1_2, 4), Customer1, Clock) else: # Add in Queue1 Queue1.Add(Customer1, Clock)
Total_Customer2 += 1 DepartingCustomer2 = Queue2.Remove(Clock) Wait.Record(Clock - DepartingCustomer2.CreateTime) if Queue2.NumQueue() >= Server2.NumberOfUnits: VBASim.Schedule(Calendar, "EndOfService2", RNG.Erlang(Phase2, MeanST2, 3), Clock) else: Server2.Free(1, Clock) for reps in range(0, 100, 1): Total_Customer1, Total_Customer2 = 0, 0 Clock = 0.0 VBASim.VBASimInit(Calendar, TheQueues, TheCTStats, TheDTStats, TheResources, Clock) VBASim.Schedule(Calendar, "Arrival", RNG.Expon(60.0 / rates[int(Clock / 60.0)], 1), Clock) VBASim.Schedule(Calendar, "EndSimulation", T, Clock) NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival": Arrival() elif NextEvent.EventType == "EndOfService1": EndOfService1() elif NextEvent.EventType == "EndOfService2": EndOfService2() while NextEvent.EventType != "EndSimulation": NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival": Arrival() elif NextEvent.EventType == "EndOfService1":
global MaxCars if ParkingLot.NumQueue() > MaxCars: MaxCars = ParkingLot.NumQueue() def Departure(): DepartingCar = ParkingLot.Remove(Clock) TimeSpent.Record(Clock - DepartingCar.CreateTime) for reps in range(0, 2000, 1): Clock = 0.0 MaxCars = 0 VBASim.VBASimInit(Calendar, TheQueues, TheCTStats, TheDTStats, TheResources, Clock) VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) VBASim.Schedule(Calendar, "EndSimulation", 8, Clock) NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival": Arrival() elif NextEvent.EventType == "Departure": Departure() while NextEvent.EventType != "EndSimulation": NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival":
if WaitingList.NumQueue() > 0: NextCustomer = WaitingList.Remove(Clock) VBASim.SchedulePlus(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), NextCustomer, Clock) WaitingTime.Record(Clock - NextCustomer.CreateTime) WTrecords.append(Clock - NextCustomer.CreateTime) else: Server.Free(1, Clock) for reps in range(0, 1, 1): WTrecords = [] Clock = 0.0 VBASim.VBASimInit(Calendar, TheQueues, TheCTStats, TheDTStats, TheResources, Clock) VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival": Arrival() elif NextEvent.EventType == "EndOfService": EndOfService(NextEvent.WhichObject) if WaitingTime.N() == WarmUp: VBASim.ClearStats(TheCTStats, TheDTStats, Clock) while WaitingTime.N() != RunLength - WarmUp: NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival":
global MaxCars if ParkingLot.NumQueue() > MaxCars: MaxCars = ParkingLot.NumQueue() def Departure(): DepartingCar = ParkingLot.Remove(Clock) TimeSpent.Record(Clock - DepartingCar.CreateTime) for reps in range(0, 2000, 1): Clock = 0.0 MaxCars = 0 VBASim.VBASimInit(Calendar, TheQueues, TheCTStats, TheDTStats, TheResources, Clock) VBASim.Schedule(Calendar, "Arrival", NextInterarrival(), Clock) VBASim.Schedule(Calendar, "EndSimulation", 8, Clock) NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival": Arrival() elif NextEvent.EventType == "Departure": Departure() while NextEvent.EventType != "EndSimulation": NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival": Arrival() elif NextEvent.EventType == "Departure":
def EndOfService(): DepartingCustomer = Queue.Remove(Clock) Wait.Record(Clock - DepartingCustomer.CreateTime) if Queue.NumQueue() > 0: VBASim.Schedule(Calendar, "EndOfService", RNG.Erlang(Phases, MeanST, 2), Clock) else: Server.Free(1, Clock) for reps in range(0, 10, 1): Clock = 0.0 VBASim.VBASimInit(Calendar, TheQueues, TheCTStats, TheDTStats, TheResources, Clock) VBASim.Schedule(Calendar, "Arrival", RNG.Expon(MeanTBA, 1), Clock) VBASim.Schedule(Calendar, "EndSimulation", RunLength, Clock) VBASim.Schedule(Calendar, "ClearIt", WarmUp, Clock) NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival": Arrival() elif NextEvent.EventType == "EndOfService": EndOfService() elif NextEvent.EventType == "ClearIt": VBASim.ClearStats(TheCTStats, TheDTStats, Clock) while NextEvent.EventType != "EndSimulation": NextEvent = Calendar.Remove() Clock = NextEvent.EventTime if NextEvent.EventType == "Arrival":