| 1 |
from SimPy.SimulationTrace import (Process, Resource, activate, initialize, |
| 2 |
hold, now, release, request, simulate) |
| 3 |
|
| 4 |
|
| 5 |
class Car(Process): |
| 6 |
def __init__(self, name, cc): |
| 7 |
Process.__init__(self, name=name) |
| 8 |
self.cc = cc |
| 9 |
|
| 10 |
def go(self): |
| 11 |
print('%s %s %s' % (now(), self.name, 'Starting')) |
| 12 |
yield request, self, gasstation |
| 13 |
print('%s %s %s' % (now(), self.name, 'Got a pump')) |
| 14 |
yield hold, self, 100.0 |
| 15 |
yield release, self, gasstation |
| 16 |
print('%s %s %s' % (now(), self.name, 'Leaving')) |
| 17 |
|
| 18 |
|
| 19 |
gasstation = Resource(capacity=2, name='gasStation', unitName='pump') |
| 20 |
initialize() |
| 21 |
c1 = Car('Car1', 2000) |
| 22 |
c2 = Car('Car2', 1600) |
| 23 |
c3 = Car('Car3', 3000) |
| 24 |
c4 = Car('Car4', 1600) |
| 25 |
activate(c1, c1.go(), at=4.0) |
| 26 |
activate(c2, c2.go()) |
| 27 |
activate(c3, c3.go(), at=3.0) |
| 28 |
activate(c4, c4.go(), at=3.0) |
| 29 |
simulate(until=300) |
| 30 |
print('Current time is %s' % now()) |