立即学习SimPy。我正在使用第一个示例代码,链接https://simpy.readthedocs.org/en/latest/topical_guides/process_interaction.html
这部分代码是以交互模式编写的。我想把类EV放到一个单独的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:此构造函数不带参数