Я новичок в SymPy (3.0.8) и хотел бы запустить демо-симуляцию «участник конференции» до тех пор, пока не даст значение (250), т.е. запустите до разговора 7 (3 беседы , 1 перерыв, 3 беседы, 1 перерыв, 1 разговор).Выполнение симуляции Simpy до заданного значения
3 * 30 + 15 + 3 * 30 + 15 + 1 * 30 = 240
Но моделирование заканчивается после того, как 3 переговоров, 1 перерыв, 3 переговоры и 1 перерыв (210).
Хотелось бы узнать, почему симуляции не работают до «talk 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
Но я ожидал, что это будет:
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 ('Talk {0} начинается с {1}'. Format (talk + 1, env.now)) '' – Rene