使用生成器模拟库存代码

时间:2018-12-13 10:58:16

标签: python generator normal-distribution

我在这段代码上遇到了一些问题,该代码本应在数周内模拟库存,并且在这段时间内,需求产生了(正态分布),库存的更新较晚,具体取决于 前一周剩余的库存

在下一个级别中,我将处理变质的产品(将产品放入垃圾箱3周后)

我正在尝试使用Generator使其更快,但我无法从此代码中得到结果

`import numpy as np
import random as rand
from scipy.stats import norm
week = 100000
service = 0.95
goal = 280
standart_dev = 60
def security(standart_dev,service):
     fractil = norm.ppf(service)
     return standart_dev*fractil
securityStock = security(standart_dev,service)
def stock(week):
     for i in range (week) :
          for j in range (int(goal+securityStock)) :
          yield 0
def demand_week(week):
     for i in range (week) :
         yield norm.rvs (155 , 60)
for X in stock(week):
     for Y in demand_week (week):
         x=int(goal+securityStock)
         if  x > 0 :
             x-=1
     if x==0:
         print(X)
         print("out of stock")`

0 个答案:

没有答案