Пример #1
0
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()
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
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)
Пример #8
0
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)
Пример #9
0
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)
Пример #10
0
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)
Пример #11
0
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)
Пример #12
0
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)
Пример #13
0
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
Пример #14
0
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)
Пример #15
0
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
Пример #16
0
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()          
Пример #17
0
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)
Пример #18
0
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)
Пример #19
0
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)
Пример #20
0
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)
Пример #21
0
    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":
Пример #22
0
    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":
Пример #23
0
    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":
Пример #24
0
    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":
Пример #25
0
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":