SimPy是“Simulation in Python”的缩写,意为“在Python中模拟”,是一個基於標準Python的過程型離散事件模擬框架[1]。它使用戶可以將活動組件(如客戶、車輛或代理)建模為簡單的Python 生成器函數。SimPy作为開源軟體MIT許可證下,第一個版本於2002年12月發布[2]

SimPy,一款基於Python的離散事件模擬框架
原作者Klaus G. Müller, Tony Vignaux
開發者Ontje Lünsdorf, Stefan Scherfke
首次发布2002年9月17日 (2002-09-17)
当前版本
  • 3.0.11 (2018年11月16日)
編輯維基數據鏈接
源代码库 編輯維基數據鏈接
编程语言Python
操作系统Cross-platform
类型Discrete event simulation
许可协议MIT
网站simpy.readthedocs.org

概述

编辑

SimPy的事件調度器是基於Python的生成器,這使得它可以應用於異步網絡或實現多代理系統(包括模擬和真實的通信)。模擬可以以“盡可能快”的方式進行,也可以實時進行(即按照實際時間),或者可以手動一步步地進行。儘管理論上SimPy可以進行連續模擬,但它並未提供足夠的支援。然而,對於那些具有固定步長、過程之間沒有互動或與共享資源交互的模擬,一個簡單的while迴圈就足以應對[3]

此外,SimPy提供了不同類型的共享資源,以模擬具有有限容量的擁塞點,如服務器、結帳櫃檯和隧道。在3.1版本及以上,SimPy提供了監控功能,以協助收集有關過程和資源的統計資訊。

有關於版本需求,SimPy 3.0需要Python 3[4],而SimPy 4.0需要Python 3.6+。SimPy發行版提供教程[5]、文件和範例供使用者學習。

範例

编辑

實作一個時鐘[6],該時鐘在每個步驟打印目前模擬時間:

>>> import simpy
>>>
>>> def clock(env, name, tick):
...     while True:
...         print(name, env.now)
...         yield env.timeout(tick)
...
>>> env = simpy.Environment()
>>> env.process(clock(env, 'fast', 0.5))
<Process(clock) object at 0x...>
>>> env.process(clock(env, 'slow', 1))
<Process(clock) object at 0x...>
>>> env.run(until=2)
fast 0
slow 0 
fast 0.5 
slow 1 
fast 1.0 
fast 1.5

參考資料

编辑
  1. ^ Iwata, Curtis; Mavris, Dimitri. Object-Oriented Discrete Event Simulation Modeling Environment for Aerospace Vehicle Maintenance and Logistics Process. Procedia Computer Science. 2013 Conference on Systems Engineering Research. 2013-01-01, 16: 187–196 [2024-05-26]. ISSN 1877-0509. doi:10.1016/j.procs.2013.01.020 . (原始内容存档于2023-11-09). 
  2. ^ Xiong, Xinli; Ma, Linru; Cui, Chao. Simulation Environment of Evaluation and Optimization for Moving Target Defense: A SimPy Approach. Proceedings of the 2019 9th International Conference on Communication and Network Security. ICCNS '19 (Association for Computing Machinery). 2020-01-13: 114–117. ISBN 978-1-4503-7662-4. doi:10.1145/3371676.3371692.  已忽略未知参数|__cpLocation= (帮助)
  3. ^ Olaitan, Oladipupo; Geraghty, John; Young, Paul; Dagkakis, Georgios; Heavey, Cathal; Bayer, Martin; Perrin, Jerome; Robin, Sebastien. Implementing ManPy, a Semantic-free Open-source Discrete Event Simulation Package, in a Job Shop. Procedia CIRP. 8th International Conference on Digital Enterprise Technology - DET 2014 Disruptive Innovation in Manufacturing Engineering towards the 4th Industrial Revolution. 2014-01-01, 25: 253–260 [2024-05-26]. ISSN 2212-8271. doi:10.1016/j.procir.2014.10.036 . (原始内容存档于2023-11-09). 
  4. ^ SimPy History & Change Log — SimPy 4.0.2.dev1+g2973dbe documentation. [2024-05-26]. (原始内容存档于2023-04-06). 
  5. ^ Zinoviev, Dmitry. Discrete Event Simulation. It's Easy with SimPy!. PragPub. February 2018, (104): 1–16. 
  6. ^ Scherfke, Stefan. Discrete-event simulation with SimPy (PDF): 5. July 25, 2014 [August 10, 2016]. (原始内容存档 (PDF)于2024-03-02). 

注解

编辑