确定性事件与过程

Python 中的离散事件模拟

Diogo Costa (PhD, MSc)

Adjunct Professor, University of Saskatchewan, Canada & CEO of ImpactBLUE-Scientific

事件(或过程)确定性

注意:术语"事件"和"过程"可互换使用。

什么是事件(或过程)的确定性?

  • 过程可被准确预测
  • 该过程称为"确定性"

为何确定性过程重要?

  • 自然与人为活动很复杂
  • 许多相互依赖的过程与资源
  • 有些过程每次都以相同方式重复
  • 对系统输出的影响可被准确预测
Python 中的离散事件模拟

确定性过程或事件示例

自然界

  • 海潮高度
  • 物体因重力的加速度(9.81 m$^2$/s)
  • 行星在太阳系中的运动
  • 空气中声速(331.29 m/s)
  • 光速(300,000 km/s)
  • 水的凝固(0 摄氏度)

人为或人启动

  • 水龙头出水流量
  • 瓶装水灌装机速度
  • 咖啡机制作一杯咖啡所需时间
  • 烤箱在 230 摄氏度释放的热量
  • 洗衣机的程序循环
  • 微波炉的工作方式
Python 中的离散事件模拟

在离散事件模型中表示确定性事件

确定性过程

  • 对动态系统的影响可预测
  • 持续时间已知
  • 以相同方式重复

需在仿真时间中计入过程持续时间

# Deterministic processes (time in hours)
duration_process_1 = 10
duration_process_2 = 5

while sim_time < total_sim_time:
# Update simulation time: Process 1 sim_time += duration_process_1
# Update simulation time: Process 2 sim_time += duration_process_2
Python 中的离散事件模拟

用 SimPy 表示确定性事件

使用 SimPy 实现确定性事件:

  • .timeout() 方法记录过程持续时间
    • 不关心时间单位
    • 将时间视为数值
    • 模型内时间单位需一致
# Deterministic processes
duration_process_1 = 10
duration_process_2 = 5

while True:

   # Update simulation time: Process 1
   yield env.timeout(duration_process_1)

   # Update simulation time: Process 2
   yield env.timeout(duration_process_2)

Python 中的离散事件模拟

让我们来练习!

Python 中的离散事件模拟

Preparing Video For Download...