基于simpy的多级库存仿真

2024-10-02 10:23:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在多层次环境中使用Simpy构建库存模拟模型。然而,似乎有一些阻塞函数不允许我的程序在时间单位0之后继续运行

我的代码的简化版本是:

class repl():
    rosq_st=1
    toq_st=5
    poq_dc=30
    lt_st=2
    lt_dc=10
    ss_st=2
    ss_dc=10
    toq_day=toq_st/lt_st
    rop_st=ss_st+(lt_st*rosq_st)
    rop_dc=ss_dc+(lt_dc*toq_day)
    simulation_time=30

class Inventory():
    def __init__(self,env):
        self.env=env
        self.st_inv=simpy.Container(env,init=repl.rop_st)
        self.dc_inv=simpy.Container(env,init=repl.rop_dc)
        env.process(self.custord(env))
        env.process(self.ropcheck_st_inv(env)) #check ropcheck_st_inv_proc?
        env.process(self.ropcheck_dc_inv(env)) # check ropcheck_dc_inv_proc?
        print ("inv process started")

    def ropcheck_st_inv(self,env):
        while True:
            if self.st_inv.level<repl.rop_st:
                print ("Order placed to DC at time {}".format(self.env.now))
                yield self.env.timeout(repl.lt_st)
                print ("Order received at store at time {}".format(self.env.now))
                yield self.env.dc_inv.get(repl.toq_st)
                yield self.env.st_inv.put(repl.toq_st)
                print ("Order added to store at time {}".format(self.env.now))
                yield self.env.timeout(1)

    def ropcheck_dc_inv(self,env):
        while True:
            if self.dc_inv.level<repl.rop_dc:
                print ("Order placed to sup at time {}".format(self.env.now))
                yield self.env.timeout(repl.lt_dc)
                print ("Order received at dc at time {}".format(self.env.now))
                yield self.env.dc_inv.put(repl.poq_dc)
                print ("Order added to dc at time {}".format(self.env.now))
                yield self.env.timeout(1)

    def custord(self,env):
        while True:
            print (str(self.env.now))
            yield self.st_inv.get(repl.rosq_st)
            print (self.st_inv.level)
            yield self.env.timeout(1)

env = simpy.Environment()
inventory = Inventory(env)
env.run(until=10)

Tags: ltselfenvtimedcreplnowat

热门问题