Python 中的离散事件模拟
Diogo Costa (PhD, MSc)
Adjunct Professor, University of Saskatchewan, Canada & CEO of ImpactBLUE-Scientific
连续模型
以固定时间步运行
时间是哑变量
使用时间 for 循环
for t in range(time_range):
离散事件模型
以可变时间步运行
时间是状态变量
常用 while 循环
while (time < 365):
time += process_duration
示例:出租车公司模型
while (time < 10):
# Process 1
time_duration_1 = manage_requests()
time += time_duration_1
# Process 2
time_duration_2 = dispatch_taxi()
time += time_duration_2
结束条件
while (time < 10)
示例:出租车公司模型
while (time < 10):
# Process 1
time_duration_1 = manage_requests()
time += time_duration_1
# Process 2
time_duration_2 = dispatch_taxi()
time += time_duration_2
时钟
time += time_duration_1
time += time_duration_2
time 跟踪当前模拟时间示例:出租车公司模型
while (time < 10):
# Process 1
time_duration_1 = manage_requests()
time += time_duration_1
# Process 2
time_duration_2 = dispatch_taxi()
time += time_duration_2
状态变量
time
缩短从呼叫到送达的时间
描述系统输出与效率的变量
Python 中的离散事件模拟