forked from salabim/salabim
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMMc with state.py
43 lines (29 loc) · 899 Bytes
/
MMc with state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import salabim as sim
class Server(sim.Component):
def process(self):
while True:
if not waiting_clients:
yield self.wait(work_to_do)
this_client = waiting_clients.pop()
yield self.hold(sim.Exponential(server_time).sample())
this_client.activate()
class Client(sim.Component):
def process(self):
self.enter(waiting_clients)
work_to_do.trigger(max=1)
yield self.passivate()
class ClientGenerator(sim.Component):
def process(self):
while True:
yield self.hold(sim.Exponential(iat).sample())
Client()
env = sim.Environment(trace=True)
waiting_clients = sim.Queue('waiting_clients')
work_to_do = sim.State('work_to_do')
nservers = 5
iat = 1
server_time = 4
for i in range(nservers):
Server()
ClientGenerator(name='clientgenerator')
env.run(100)