def NSPP(Stream): PossibleArrival = SimClasses.Clock + SimRNG.Expon(1.0 / 110, Stream) while SimRNG.Uniform(0, 1, Stream) >= ( 100 + 10 * math.sin(3.141593 * PossibleArrival / 12)) / 110.0: PossibleArrival = PossibleArrival + SimRNG.Expon(1.0 / 110, Stream) nspp = PossibleArrival - SimClasses.Clock return nspp
def NSPP(Stream): PossibleArrival = SimClasses.Clock + SimRNG.Expon(1.0 / MaxRate, Stream) i = int(min(NPeriods, math.ceil(PossibleArrival / Period))) while SimRNG.Uniform(0, 1, Stream) >= ARate[i - 1] / MaxRate: PossibleArrival = PossibleArrival + SimRNG.Expon(1.0 / MaxRate, Stream) i = int(min(NPeriods, math.ceil(PossibleArrival / Period))) nspp = PossibleArrival - SimClasses.Clock return nspp
def Arrival(): SimFunctions.Schedule(Calendar, "Arrival", SimRNG.Expon(MeanTBA, 1)) Customer = SimClasses.Entity() Queue.Add(Customer) if Server.Busy == 0: Server.Seize(1) SimFunctions.Schedule(Calendar, "EndOfService", SimRNG.Erlang(Phases, MeanST, 2))
def Arrival2(): SimFunctions.Schedule(Calendar, "Arrival2", SimRNG.Expon(MeanTBA2, 2)) Class2Customer = SimClasses.Entity() Class2Customer.ClassNum = 2 if Server2.Busy == 0: Server2.Seize(1) SimFunctions.SchedulePlus(Calendar, "EndOfService2", SimRNG.Expon(MeanPT2, 5), Class2Customer) else: Queue2.Add(Class2Customer)
def Arrival1(): SimFunctions.Schedule(Calendar, "Arrival1", SimRNG.Expon(MeanTBA1, 1)) Class1Customer = SimClasses.Entity() Class1Customer.ClassNum = 1 if Server1.Busy == 0: Server1.Seize(1) SimFunctions.SchedulePlus(Calendar, "EndOfService1", SimRNG.Expon(MeanPT1_1, 3), Class1Customer) elif Server2.Busy == 0: Server2.Seize(1) SimFunctions.SchedulePlus(Calendar, "EndOfService2", SimRNG.Expon(MeanPT1_2, 4), Class1Customer) else: Queue1.Add(Class1Customer)
def EndOfService1(DepartingCustomer): # class 1 job departing server 1 TotalTime1.Record(SimClasses.Clock - DepartingCustomer.CreateTime) if Queue1.NumQueue() > 0: NextCustomer = Queue1.Remove() SimFunctions.SchedulePlus(Calendar, "EndOfService1", SimRNG.Expon(MeanPT1_1, 3), NextCustomer) else: Server1.Free(1)
def EndOfService(): DepartingCustomer = Queue.Remove() Wait.Record(SimClasses.Clock - DepartingCustomer.CreateTime) if Queue.NumQueue() > 0: SimFunctions.Schedule(Calendar, "EndOfService", SimRNG.Erlang(Phases, MeanST, 2)) else: Server.Free(1)
def SpecialArrival(SpecialFax): if Specialists.Busy < Specialists.NumberOfUnits: Specialists.Seize(1) SimFunctions.SchedulePlus(Calendar, "EndOfEntrySpecial", SimRNG.Normal(MeanSpecial, VarSpecial, 4), SpecialFax) else: SpecialQ.Add(SpecialFax)
def EndOfService2( DepartingCustomer ): # class 1 or 2 job departing server 2; give priority to class 1 if DepartingCustomer.ClassNum == 1: # class 1 customer departing TotalTime1.Record(SimClasses.Clock - DepartingCustomer.CreateTime) else: # class 2 customer departing TotalTime2.Record(SimClasses.Clock - DepartingCustomer.CreateTime) if Queue1.NumQueue() > 0: # priority to class 1 NextCustomer = Queue1.Remove() SimFunctions.SchedulePlus(Calendar, "EndOfService2", SimRNG.Expon(MeanPT1_2, 4), NextCustomer) elif Queue2.NumQueue() > 0: NextCustomer = Queue2.Remove() SimFunctions.SchedulePlus(Calendar, "EndOfService2", SimRNG.Expon(MeanPT2, 5), NextCustomer) else: Server2.Free(1)
def EndOfEntry(DepartingFax): if SimRNG.Uniform(0, 1, 3) < 0.2: SpecialArrival(DepartingFax) else: Wait = SimClasses.Clock - DepartingFax.CreateTime RegularWait.Record(Wait) if Wait < 10: Regular10.Record(1) else: Regular10.Record(0) if RegularQ.NumQueue() > 0 and Agents.NumberOfUnits >= Agents.Busy: DepartingFax = RegularQ.Remove() SimFunctions.SchedulePlus(Calendar, "EndOfEntry", SimRNG.Normal(MeanRegular, VarRegular, 2), DepartingFax) else: Agents.Free(1)
def Arrival(): global MaxQueue global N interarrival = NSPP(1) SimFunctions.Schedule(Calendar,"Arrival", interarrival) N = N + 1 QueueLength.Record(N) if N > MaxQueue: MaxQueue = N SimFunctions.Schedule(Calendar,"Departure",SimRNG.Expon(MeanParkingTime, 2))
def Arrival(): if SimClasses.Clock < RunLength: SimFunctions.Schedule(Calendar, "Arrival", NSPP(1)) else: return Fax = SimClasses.Entity() if Agents.Busy < Agents.NumberOfUnits: Agents.Seize(1) SimFunctions.SchedulePlus(Calendar, "EndOfEntry", SimRNG.Normal(MeanRegular, VarRegular, 2), Fax) else: RegularQ.Add(Fax)
def EndOfEntrySpecial(DepartingFax): Wait = SimClasses.Clock - DepartingFax.CreateTime SpecialWait.Record(Wait) if Wait < 10: Special10.Record(1) else: Special10.Record(0) if SpecialQ.NumQueue( ) > 0 and Specialists.NumberOfUnits >= Specialists.Busy: DepartingFax = SpecialQ.Remove() SimFunctions.SchedulePlus(Calendar, "EndOfEntrySpecial", SimRNG.Normal(MeanSpecial, VarSpecial, 4), DepartingFax) else: Specialists.Free(1)
def Milestone(ActIn, Node): global ThisActivity global Inbound global Outbound global Nodes global Destination Inbound = Nodes[InTo, Node] Outbound = Nodes[OutOf, Node] m = len(Inbound) for Incoming in range(0, m, 1): if Inbound[Incoming] == ActIn: Inbound.remove(Inbound[Incoming]) break Nodes[InTo, Node] = Inbound if len(Inbound) == 0: m = len(Outbound) for ActOut in range(0, m, 1): ThisActivity = SimClasses.Activity() ThisActivity.WhichActivity = Outbound[0] ThisActivity.WhichNode = Destination[Outbound[0] - 1] SimFunctions.SchedulePlus(Calendar, "Milestone", SimRNG.Expon(1, 1), ThisActivity) Outbound.remove(Outbound[0])
""" import SimClasses import SimFunctions import SimRNG import math import pandas import numpy as np SimClasses.Clock = 0 MeanParkingTime = 2.0 QueueLength = SimClasses.CTStat() N = 0 MaxQueue = 0 ZSimRNG = SimRNG.InitializeRNSeed() Calendar = SimClasses.EventCalendar() TheCTStats = [] TheDTStats = [] TheQueues = [] TheResources = [] TheCTStats.append(QueueLength) AllQueueLength = [] AllMaxQueue = [] AllN = [] print("Average Number in Queue", "Maximum Number in Queue")
# -*- coding: utf-8 -*- """ Converted from VBASim by Yujing Lin, Linda Pei & Barry L Nelson Last update 8/15/2018 """ import SimRNG import pandas ZRNG = SimRNG.InitializeRNSeed() AllWait = [] print "Rep", "Average Wait" m = 55000 d = 5000 for Rep in range(0, 10, 1): Y = 0 SumY = 0 for i in range(0, d, 1): a = SimRNG.Expon(1, 1) X = SimRNG.Erlang(3, 0.8, 2) Y = max(0, Y + X - a) for i in range(d, m, 1): a = SimRNG.Expon(1, 1) X = SimRNG.Erlang(3, 0.8, 2) Y = max(0, Y + X - a) SumY = SumY + Y
# -*- coding: utf-8 -*- """ Converted from VBASim by Yujing Lin, Linda Pei & Barry L Nelson Last update 8/15/2018 """ import SimRNG import math import pandas ZRNG = SimRNG.InitializeRNSeed() Replications = 10000 Maturity = 1.0 Steps = 32 Sigma = 0.3 InterestRate = 0.05 InitialValue = 50.0 StrikePrice = 55.0 Interval = Maturity / Steps Sigma2 = Sigma * Sigma / 2 TotalValue = [] for i in range(0,Replications,1): Sum = 0.0 X = InitialValue for j in range(0,Steps,1): Z = SimRNG.Normal(0,1,12) X = X * math.exp((InterestRate - Sigma2) * Interval + Sigma * math.sqrt(Interval) * Z) Sum = Sum + X
# -*- coding: utf-8 -*- """ Converted from VBASim by Yujing Lin, Linda Pei & Barry L Nelson Last update 8/15/2018 """ import SimRNG import math ZRNG = SimRNG.InitializeRNSeed() N = 1000 c = 0 tp = 5 for rep in range(0, N, 1): X = [] for i in range(0, tp, 1): X.append(SimRNG.Expon(1.0, 7)) Y = max(X[0] + X[3], X[0] + X[2] + X[4], X[1] + X[4]) if Y > tp: c = c + 1 Theta = 1 - ( (tp**2 / 2.0 - 3 * tp - 3) * math.exp(-2 * tp) + (-tp**2 / 2.0 - 3 * tp + 3) * math.exp(-tp) + 1 - math.exp(-3 * tp)) print float(c) / N, Theta
# -*- coding: utf-8 -*- """ Converted from VBASim by Yujing Lin, Linda Pei & Barry L Nelson Last update 8/15/2018 """ import SimFunctions import SimRNG import SimClasses import pandas import numpy as np ZSimRNG = SimRNG.InitializeRNSeed() Queue = SimClasses.FIFOQueue() Wait = SimClasses.DTStat() Server = SimClasses.Resource() Calendar = SimClasses.EventCalendar() TheCTStats = [] TheDTStats = [] TheQueues = [] TheResources = [] TheDTStats.append(Wait) TheQueues.append(Queue) TheResources.append(Server) Server.SetUnits(1) MeanTBA = 1.0