priorityResource dose not act properly based on priority values
I have the following code, I expected p2 gets access to priority resource before p1 because p2 has lower priority value(which means high priority), but according to the printed result, it is in the opposite way. Wondering what is the reason for this?
import simpy
def resource_user(name, env, resource, wait, prio):
yield env.timeout(wait)
with resource.request(priority=prio) as req:
print(f'{name} requesting at {env.now} with priority={prio}')
yield req
print(f'{name} got resource at {env.now}')
yield env.timeout(3)
env = simpy.Environment()
res = simpy.PriorityResource(env, capacity=1)
p1 = env.process(resource_user(1, env, res, wait=0, prio=0))
p2 = env.process(resource_user(2, env, res, wait=0, prio=-2))
p3 = env.process(resource_user(3, env, res, wait=2, prio=-2))
env.run()
1 requesting at 0 with priority=0
2 requesting at 0 with priority=-2
1 got resource at 0
3 requesting at 2 with priority=-2
2 got resource at 3
3 got resource at 6
Edited by Peter Grayson