标签: event-simulation

如何提高布朗运动蒙特卡洛模拟速度?

我想让我的代码更快地运行,以进行更多的迭代和运行。现在,我的代码太慢了,但是我不知道要更改什么来加速它。我首先编写了动力学的蒙特卡洛模拟,然后将其编辑为布朗运动模拟。我当前的代码无法处理10,000次运行,每次运行10,000次迭代。

import numpy as np
import matplotlib.pyplot as plt
import time
%matplotlib inline

runs = int(input("Enter number of runs: "))
N = int(input("Enter number of iterations per simulation: "))

y = 0
R = 10*1  # R is the rate value
t0 = time.time()
for y in range(runs):  # Run the simulation 'runs' times
    T = np.array([0])
    dt = 0
    x = 0.5  # sets values 
    X = np.array([x])
    t = 0
    i = 0

    while t < N:  # …
Run Code Online (Sandbox Code Playgroud)

python montecarlo stochastic event-simulation

5
推荐指数
1
解决办法
119
查看次数

ruby - 计算超市排队时间

所以假设超市里有一个自助结账柜台排队。我正在尝试编写一个函数来计算所有客户结账所需的总时间!

输入:

客户:代表队列的正整数数组。每个整数代表一个客户,其值是他们需要结账的时间。

n:正整数,结账台数。

输出:

该函数应返回一个整数,即所需的总时间。例子:

queue_time([5,3,4], 1)
# should return 12
# because when n=1, the total time is just the sum of the times

queue_time([10,2,3,3], 2)
# should return 10
# because here n=2 and the 2nd, 3rd, and 4th people in the 
# queue finish before the 1st person has finished.

queue_time([2,3,10], 2)
# should return 12
Run Code Online (Sandbox Code Playgroud)

只有一个队列服务多个收银台,队列的顺序永远不会改变。队列中的最前面的人(数组/列表中的第一个元素)一有空就进入直到。我试过这个,但它不能正常工作,我不知道如何让下一个人进入,直到它打开。

def queue_time(customers, n)
  if customers == []
    n=0
  else
    x= customers.reduce(:+) / n 
    if x < customers.max
      customers.max
    else …
Run Code Online (Sandbox Code Playgroud)

ruby arrays methods event-simulation

3
推荐指数
1
解决办法
140
查看次数

今天使用哪些书籍来学习离散事件模拟?

我刚刚参加了一个程序,该程序使我开始研究新的网络协议,而我的第一个任务是学习离散事件仿真

推荐了2本书:

仿真计算机系统:技术与工具迈伦H.麦克杜格尔

仿真模型设计和执行:保罗·菲什威克Paul Fishwick)构建数字世界

这两本书都使用了我不会特别使用的工具,但是我被告知这是学习离散事件模拟基础的好书。

但是,碰巧,MacDougall的书除了amazon dot com以外,在其他任何商店中都没有,而且要花两个月的时间才能寄到我的地址。Fishwick的书将花掉我现在不愿意花的一笔钱。

现在,我来问一个问题:今天使用哪些书籍来学习与那些相似的离散事件模拟?

PS:我将使用基于Python的SimPy仿真工具。

python simpy event-simulation

2
推荐指数
1
解决办法
1120
查看次数