今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: このコンストラクターは引数を取りません