Created
April 10, 2017 11:14
-
-
Save anonymous/5b2c1333548b6d7edebe7dd4af99335c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import simpy | |
import random | |
a, b, c = 10, 30, 5 | |
strict = +1 # +1 for version A, -1 for version B | |
def lap(sim, event): | |
laps[event.data] = strict * event.priority | |
if abs(laps[0] - laps[1]) > 1: | |
sim.stop_at(event.time) | |
sim.publish(simpy.Event(event.time + c + random.randint(a, b), | |
event.priority + strict, '', event.data)) | |
laps = [0, 0] | |
sim = simpy.Simulation() | |
sim.subscribe('', lap) | |
for player in range(2): | |
sim.publish(simpy.Event(random.randint(a, b), 0, '', player)) | |
sim.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment