Skip to content

Commit acd503e

Browse files
committed
wait and work
1 parent 197b405 commit acd503e

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ greenlet
33
kaleido
44
pandas
55
plotly
6+
py-des-lib
67
pydot
78
pyfakefs
89
pytest

src/eventsim/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TARGETS=\
2+
wait_and_work.out
3+
4+
include ../../examples.mk

src/eventsim/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
---
2-
title: "Discrete Event Simulator"
2+
title: "Discrete Event Simulation"
33
abstract: >
44
FIXME
55
syllabus:
66
- FIXME
77
---
88

99
[%fixme "create discrete event simulator" %] [%issue 56 %]
10+
11+
- Basic ideas of discrete event simulation
12+
- `wait_and_work.py`: work a fixed time, wait a fixed time

src/eventsim/wait_and_work.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
start to work at 0
2+
start to work at 5
3+
start to work at 10
4+
finished working at 15

src/eventsim/wait_and_work.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from pydes import Component, Simulator
2+
3+
4+
class Worker(Component):
5+
NUM_STEPS = 3
6+
WORK_TIME = 5
7+
8+
def __init__(self, sim):
9+
self._sim = sim
10+
11+
def main(self):
12+
for i in range(self.NUM_STEPS):
13+
print(f"start to work at {self._sim.now()}")
14+
self._sim.sleep(self.WORK_TIME)
15+
print(f"finished working at {self._sim.now()}")
16+
17+
18+
def simulate():
19+
sim = Simulator()
20+
worker = Worker(sim)
21+
sim.schedule(worker)
22+
sim.run()
23+
24+
25+
if __name__ == "__main__":
26+
simulate()

0 commit comments

Comments
 (0)