| 1 |
from SimPy.Simulation import Process, activate, hold, initialize, now, simulate |
| 2 |
|
| 3 |
|
| 4 |
class Car(Process): |
| 5 |
def __init__(self, name, cc): |
| 6 |
Process.__init__(self, name=name) |
| 7 |
self.cc = cc |
| 8 |
|
| 9 |
def go(self): |
| 10 |
print('%s %s %s' % (now(), self.name, 'Starting')) |
| 11 |
yield hold, self, 100.0 |
| 12 |
print('%s %s %s' % (now(), self.name, 'Arrived')) |
| 13 |
|
| 14 |
|
| 15 |
initialize() |
| 16 |
c1 = Car('Car1', 2000) |
| 17 |
activate(c1, c1.go(), at=6.0) |
| 18 |
c2 = Car('Car2', 1600) |
| 19 |
activate(c2, c2.go()) |
| 20 |
simulate(until=200) |
| 21 |
print('Current time is %s' % now()) |