本文整理匯總了Python中Event.eventType方法的典型用法代碼示例。如果您正苦於以下問題:Python Event.eventType方法的具體用法?Python Event.eventType怎麽用?Python Event.eventType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Event
的用法示例。
在下文中一共展示了Event.eventType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_sim
# 需要導入模塊: import Event [as 別名]
# 或者: from Event import eventType [as 別名]
def run_sim(payQueueSize, pickupQueueSize, iterations, interarrival):
order = OrderQueue.OrderQueue()
payment = PaymentWindow.PaymentWindow()
pickup = PickupWindow.PickupWindow()
totalCars = 0
arrivalCount = 0
orderCompleteCount = 0
paymentCompleteCount = 0
processCompleteCount = 0
totalWaitForPaymentQueue = 0
totalWaitForPickupQueue = 0
payment.set_max(payQueueSize)
pickup.set_max(pickupQueueSize)
STOP = iterations
EL = EventList.EventList() # create a new event list object
get_arrival.arrival_time = 0 # initialize arrival time to 0
t = time_structure()
return_stats = stats()
t.current = 0 # set the simulation clock to 0
arrival = Event.Event() # create a new event object
t.arrival = get_arrival(interarrival) # get our first arrival time, we might get rid of this
arrival.time = t.arrival # set the objects time to t.arrival
arrival.eventType = Event.eventType(1) # set the enum to make the event type be an arrival
EL.scheduleEvent(arrival) # add the arrival to the event list.
arrivalCount += 1
# We do not need to set the completions to infinity because it is the same as the objects not existing.
#currently without any intake from data
while(t.arrival < STOP): # or (order.get_queue_size() + payment.get_queue_size() + pickup.get_queue_size()) > 0): # keep running the simulation until we reach our stop time
event = EL.getNextEvent()
nextTime = event.time # BAM! get our event from the heap in the event list! and get its time element
#Heres where we'd update integrals if we use them
t.current = nextTime #updates clock
#------------------------------------------------------------------------------------------------
# majority of logic goes in here
#process arrival
if event.eventType.value == 1:
order.add_to_queue() #add one car to the order window structure
totalCars = totalCars + 1 #add one to total cars that have gone through drive through
#check if next queue has room, if it does , schedule a completions because we can fit a car in
if payment.get_queue_size() < payment.get_max():
orderComplete = Event.Event()
orderComplete.eventType = Event.eventType(2)#register event as an order completion
service = order.get_service()
orderComplete.time = t.current + service #calculate service time and add it to curr time to get completion time
EL.scheduleEvent(orderComplete) #add to event list
order.order_complete() #removes a car from the order queue
orderCompleteCount += 1
payment.add_to_queue() #adds the car to the payment window
return_stats.order_time += service # time leaving the order window
else:
moveOrder = Event.Event()
moveOrder.eventType = Event.eventType(5) # register event as move order car event
service = order.get_service()
moveOrder.time = t.current + service # we will still calculate the service time as if we were completing
EL.scheduleEvent(moveOrder)#add to event list
return_stats.order_time += service #scheduling a move order but we are still in the order queue
return_stats.avg_order_cant_mv_time += service #technically were stuck
#schedule next arrival
if t.current < STOP: # if we are still below our stop time, schedule another arrival
arrival = Event.Event()
t.arrival = get_arrival(interarrival)
arrival.time = t.arrival
arrival.eventType = Event.eventType(1) #set this event as an type arrival
EL.scheduleEvent(arrival) #add arrival to event list
#print("arrival", t.current)
arrivalCount += 1
#process order completion
elif event.eventType.value == 2:
# check if payment window has room
if pickup.get_queue_size() < pickup.get_max():
paymentComplete = Event.Event()
paymentComplete.eventType = Event.eventType(3) #register it as a payment complete
service = payment.get_service()
paymentComplete.time = t.current + service
EL.scheduleEvent(paymentComplete) #add to event list
payment.pay_complete() #remove from payment window
paymentCompleteCount += 1
pickup.add_to_queue() # add car to pickup queue
return_stats.payment_time += service # add service time to payment total time
#print("order complete", t.current)
else:
paymentMove = Event.Event()
paymentMove.eventType = Event.eventType(6) # register this event as a payment move event
service = payment.get_service()
#.........這裏部分代碼省略.........