Python में Discrete Event Simulation
Dr Diogo Costa
Adjunct Professor, University of Saskatchewan, Canada & CEO of ImpactBLUE-Scientific
वास्तविक समस्याओं में इवेंट कई स्थितियों से प्रभावित होते हैं.
आम स्थितियाँ शामिल हैं:
इन स्थितियों को SimPy डिस्क्रीट-इवेंट मॉडल में बदला जा सकता है.
उदाहरण
ग्राहक कपड़ों की दुकान पर आते हैं
def customer_arrivals(env, shop)
खास आइटम ढूँढते हैं
env.timeout(search_time)
if shop.available[item]:
जेनरेटर: सारा कोड साथ लाना
def customer_arrivals(env, shop):while True: yield env.timeout(search_time)# Only buy item if available if shop.available[item]: env.process(shop_buyer(env, item, num_items, shop))
कुछ इवेंट रुक सकते हैं, कारण:
मेथड
simpy_process_1.interrupt()
उदाहरण
मशीन समय-समय पर टूटती है और प्रोडक्शन लाइन बाधित होती है.
def break_machine(env):# Break machine every now and then. while True: # Time between machine fails yield env.timeout(fail_time())# Machine fail: interrupt process simpy_process_1.interrupt()
capacity=5:simpy.Resource(env, capacity=5)
उदाहरण: गैस स्टेशन में पेट्रोल का भंडार नियमित रूप से रीप्लेनिश करना पड़ता है
with gas_station.request() as request:# Request one of the gas pumps yield request# Once pump is available: pump fuel liters_request = 10 yield fuel_reserve.get(liters_request) # The "actual" refueling takes time refuel_duration = liters_request / refuel_speedyield env.timeout(refuel_duration)
बिटवाइज़ ऑपरेटर्स
a & b, a >> b, a ^ bSimPy में
SimPy के लिए प्रासंगिक बिटवाइज़ ऑपरेटर्स
__and__() या &__or__() या |उदाहरण: मूवीगोअर टिकट लाइन में तब तक इंतज़ार करता है जब तक उसकी बारी न आ जाए या मूवी सेल आउट न हो जाए
with counter.request() as my_turn:# Wait until turn or movie is sold out result = yield my_turn | counter.sold_out[movie]# If tickets available if my_turn in result: theater.num_moviegoers[movie] += 1 return# If tickets sold out if my_turn not in result: theater.num_renegers[movie] += 1 return
Python में Discrete Event Simulation