| 1 |
from SimPy.Simulation import Process, activate, hold, initialize, simulate |
| 2 |
|
| 3 |
|
| 4 |
class Customer(Process): |
| 5 |
def buy(self, budget=0): |
| 6 |
print('Here I am at the shops %s' % self.name) |
| 7 |
t = 5.0 |
| 8 |
for i in range(4): |
| 9 |
yield hold, self, t |
| 10 |
|
| 11 |
print('I just bought something %s' % self.name) |
| 12 |
budget -= 10.00 |
| 13 |
print('All I have left is %s I am going home %s' % (budget, self.name)) |
| 14 |
|
| 15 |
|
| 16 |
initialize() |
| 17 |
|
| 18 |
|
| 19 |
C = Customer(name='Evelyn') |
| 20 |
|
| 21 |
|
| 22 |
activate(C, C.buy(budget=100), at=10.0) |
| 23 |
|
| 24 |
simulate(until=100.0) |