0

立即学习 SimPy。我正在使用第一个示例代码,链接https://simpy.readthedocs.org/en/latest/topical_guides/process_interaction.html

这部分代码是以交互方式编写的。我想将类 EV 放入一个名为 Ev.py 的单独 python 文件中(如下所示)。

ev.py

class EV:    
    def __init__(self, env):    
        self.env = env    
        self.drive_proc = env.process(self.drive(env))    
        self.bat_ctrl_proc = env.process(self.bat_ctrl(env))    
        self.bat_ctrl_reactivate = env.event()    
    
    def drive(self, env):    
        while True:    
            # Drive for 20-40 min    
            yield env.timeout(randint(20, 40))    
    
            # Park for 1–6 hours    
            print('Start parking at', env.now)    
            self.bat_ctrl_reactivate.succeed()  # "reactivate"    
            self.bat_ctrl_reactivate = env.event()    
            yield env.timeout(randint(60, 360))    
            print('Stop parking at', env.now)    
    
    def bat_ctrl(self, env):    
        while True:    
            print('Bat. ctrl. passivating at', env.now)    
            yield self.bat_ctrl_reactivate  # "passivate"    
            print('Bat. ctrl. reactivated at', env.now)    
    
            # Intelligent charging behavior here …    
            yield env.timeout(randint(30, 90)) 

然后我导入文件。我这样运行它:

from random import seed, randint
seed(23)
import simpy
import Ev
env=simpy.Environment()
ev = Ev.EV(env)
env.run(until=150)

说到步骤:ev=Ev.EV(env),就说明有错误:

回溯(最近一次通话最后):

文件“stdin”,第 1 行,在模块中

TypeError:此构造函数不带参数

4

0 回答 0