def Schedule(calendar, EventType, EventTime, clock): #Schedule future events of EventType to occur at time Clock + EventTime addedEvent = Basic_Classes.EventNotice() addedEvent.EventType = EventType addedEvent.EventTime = clock + EventTime calendar.Schedule(addedEvent)
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) 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 SchedulePlus(calendar, EventType, EventTime, TheObject, clock): #Schedule future events of EventType to occur at time Clock + EventTime #and pass with the event notice TheObject addedEvent = Basic_Classes.EventNotice() addedEvent.EventType = EventType addedEvent.EventTime = clock + EventTime addedEvent.WhichObject = TheObject calendar.Schedule(addedEvent)
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 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 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 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 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)
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)
@author: zuq31 """ #import libraries import VBASim import Basic_Classes as bc import RNG import numpy as np #initialize variables TheQueues = [] TheResources = [] TheDTStats = [] TheCTStats = [] #create instances of objects ParkingLot = bc.FIFOQueue() MaxCars = 0 TimeSpent = bc.DTStat() Calendar = bc.EventCalendar() TheQueues.append(ParkingLot) TheDTStats.append(TimeSpent) AllAverageQueues = [] AllMaxCars = [] AllTimeSpent = [] print("Rep", "Average Number", "Max Number", "Average Time Spent") MeanTBA = 0.021 #for stationary Poisson arrival #MeanTBA = 0.03312 #for nonstationary Poisson arrival
# -*- coding: utf-8 -*- import VBASim import RNG import Basic_Classes import math import numpy as np import pandas as pd from scipy import stats Clock = 0.0 ZRNG = RNG.InitializeRNSeed() Queue = Basic_Classes.FIFOQueue() # Inventory Calendar = Basic_Classes.EventCalendar() Server = Basic_Classes.Resource() # dummy, not used TheCTStats = [] TheDTStats = [] TheQueues = [] TheResources = [] TheQueues.append(Queue) TheResources.append(Server) AllStats = [] p = 0.2 MeanTBA = 1.0 # Demand Arrival MeanLead = 1.0 # Item Arrival T = 240 # Runlength s = 4 S = 10 NumSold = 0 # total number of sold items M = 0 # total number of ordered items o = 0.5 r = 1
import VBASim import Basic_Classes as bc import RNG import numpy as np import csv Clock = 0.0 ZRNG = RNG.InitializeRNSeed() #initialize variables TheQueues = [] TheResources = [] TheDTStats = [] TheCTStats = [] WaitingList = bc.FIFOQueue() WaitingTime = bc.DTStat() Difference = bc.DTStat() Calendar = bc.EventCalendar() Server = bc.Resource() TimeSpent = bc.DTStat() TheQueues.append(WaitingList) TheDTStats.append(WaitingTime) TheDTStats.append(Difference) TheResources.append(Server) Server.SetUnits(3) MeanTBA = 1.0 MeanST = 2.7 Phases = 2
#!/usr/bin/env python2 import VBASim import RNG import Basic_Classes import pandas as pd Clock = 0.0 ZRNG = RNG.InitializeRNSeed() Queue = Basic_Classes.FIFOQueue() Wait = Basic_Classes.DTStat() Server = Basic_Classes.Resource() Calendar = Basic_Classes.EventCalendar() TheCTStats = [] TheDTStats = [] TheQueues = [] TheResources = [] TheDTStats.append(Wait) TheQueues.append(Queue) TheResources.append(Server) c = 10 # retrial if # customers in the system >= c Server.SetUnits(1) MeanTBA = 1.0 MeanST = 0.8 MeanTR = 2.0 # retrial customer return time ~ exp(MeanTR) Phases = 3 RunLength = 55000.0 WarmUp = 5000.0 AllStats = []
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import VBASim import RNG import Basic_Classes import pandas as pd Clock = 0.0 ZRNG = RNG.InitializeRNSeed() Queue1 = Basic_Classes.FIFOQueue() # Financial Queue2 = Basic_Classes.FIFOQueue() # Contact Management Wait = Basic_Classes.DTStat() Server1 = Basic_Classes.Resource() # Financial Server2 = Basic_Classes.Resource() # Contact Management Calendar = Basic_Classes.EventCalendar() TheCTStats = [] TheDTStats = [] TheQueues = [] TheResources = [] TheDTStats.append(Wait) TheQueues.append(Queue1) TheQueues.append(Queue2) TheResources.append(Server1) TheResources.append(Server2) s1 = 4 s2 = 3 Server1.SetUnits(s1) Server2.SetUnits(s2) MeanTBA = 1.0 MeanST1 = 5.0 MeanST2 = 5.0
import Basic_Classes import pandas as pd import csv Clock = 0.0 ZRNG = RNG.InitializeRNSeed() ''' Class1 Class2 Queue1 Queue2 | \ | | \ | A B1 B2 | \ | | \ | ServerA ServerB ''' Queue1 = Basic_Classes.FIFOQueue() Queue2 = Basic_Classes.FIFOQueue() ServerA = Basic_Classes.Resource() ServerB = Basic_Classes.Resource() TotalTime1 = Basic_Classes.DTStat() TotalTime2 = Basic_Classes.DTStat() Calendar = Basic_Classes.EventCalendar() TheCTStats = [] TheDTStats = [] TheQueues = [] TheResources = [] TheDTStats.append(TotalTime1) TheDTStats.append(TotalTime2) TheQueues.append(Queue1)