1
私はSymPy(3.0.8)を初めて使用しており、与えられた値(250)までデモシミュレーション 'conference attendee'を実行したい、つまりtalk 7(3 talks 、1ブレーク、3トーク、1ブレーク、1トーク)。特定の値までSimpyシミュレーションを実行する
3 * 30 + 15 + 3 * 30 + 15 + 1 * 30 = 240
しかし、シミュレーションは3つの会談、1つのブレーク、3回の講演や1つのブレーク(210)後に終了します。
「トーク7」までシミュレーションが実行されない理由と、これを修正する方法を知りたいと思います。
# import
import simpy
from random import randint
# config
TALKS_PER_SESSION = 3
TALK_LENGTH = 30
BREAK_LENGTH = 15
ATTENDEES = 3
# process function
def attendee(env, name, knowledge=0, hunger=0):
talks = 0
breaks = 0
while True:
# Visit talks
for i in range(TALKS_PER_SESSION):
knowledge += randint(0, 3)/(1 + hunger)
hunger += randint(1, 4)
talks += 1
yield env.timeout(TALK_LENGTH)
print('Attendee %s finished %d talks with knowledge %.2f and hunger %.2f.' % (name, talks, knowledge, hunger))
# Go to buffet
food = randint(3, 12)
hunger -= min(food, hunger)
breaks += 1
yield env.timeout(BREAK_LENGTH)
print('Attendee %s has finished break %d with hunger %.2f' % (name, breaks, hunger))
# setup environment and run simulation
env = simpy.Environment()
for i in range(ATTENDEES):
env.process(attendee(env, i))
env.run(until=250)
このシミュレーションの出力は次のようになります。
Attendee 0 finished 3 talks with knowledge 2.33 and hunger 7.00.
Attendee 1 finished 3 talks with knowledge 0.60 and hunger 8.00.
Attendee 2 finished 3 talks with knowledge 3.81 and hunger 7.00.
Attendee 0 has finished break 1 with hunger 0.00
Attendee 1 has finished break 1 with hunger 0.00
Attendee 2 has finished break 1 with hunger 0.00
Attendee 0 finished 6 talks with knowledge 5.53 and hunger 6.00.
Attendee 1 finished 6 talks with knowledge 1.89 and hunger 9.00.
Attendee 2 finished 6 talks with knowledge 4.31 and hunger 5.00.
Attendee 0 has finished break 2 with hunger 0.00
Attendee 1 has finished break 2 with hunger 0.00
Attendee 2 has finished break 2 with hunger 0.00
しかし、私はそれがあることが予想:ATTENDEES = 1
を設定し、インナfor
ループを変更してください
Attendee 0 finished 3 talks with knowledge 2.33 and hunger 7.00.
Attendee 1 finished 3 talks with knowledge 0.60 and hunger 8.00.
Attendee 2 finished 3 talks with knowledge 3.81 and hunger 7.00.
Attendee 0 has finished break 1 with hunger 0.00
Attendee 1 has finished break 1 with hunger 0.00
Attendee 2 has finished break 1 with hunger 0.00
Attendee 0 finished 6 talks with knowledge 5.53 and hunger 6.00.
Attendee 1 finished 6 talks with knowledge 1.89 and hunger 9.00.
Attendee 2 finished 6 talks with knowledge 4.31 and hunger 5.00.
Attendee 0 has finished break 2 with hunger 0.00
Attendee 1 has finished break 2 with hunger 0.00
Attendee 2 has finished break 2 with hunger 0.00
Attendee 0 finished 7 talks with knowledge <...> and hunger <...>.
Attendee 1 finished 7 talks with knowledge <...> and hunger <...>.
Attendee 2 finished 7 talks with knowledge <...> and hunger <...>.
ありがとう!あなたのコードがPythonの私のバージョン(3.5.3)で動くようにするには、printコマンドを '' print {'} {1}で始める' 'print {'{talk} + 1、env.now}' ' – Rene