Skip to content

Commit

Permalink
Merge pull request #24 from gitaroktato/utility-functions
Browse files Browse the repository at this point in the history
feat: Using utility functions
  • Loading branch information
gitaroktato authored Apr 10, 2024
2 parents d323de5 + 55464b1 commit 0051690
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 26 deletions.
26 changes: 22 additions & 4 deletions bursty-traffic.ipynb

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions interesting-experiments.ipynb

Large diffs are not rendered by default.

42 changes: 30 additions & 12 deletions simulating-md1-queues.ipynb

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions src/queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import numpy as np
import numpy.typing as npt


def intervals_to_timestamps(intervals: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
timestamps = np.copy(intervals)
for index, value in enumerate(timestamps):
if index != 0:
timestamps[index] += timestamps[index - 1]
return timestamps


def timestamps_to_intervals(timestamps: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
intervals = np.copy(timestamps)
for index, value in reversed(list(enumerate(intervals))):
if index != 0:
intervals[index] -= intervals[index - 1]
return intervals


class Queue:

def __init__(
Expand All @@ -26,10 +43,7 @@ def process(self) -> None:
self.__process_length()

def __process_arrival_times(self) -> None:
self.__arrival_times = np.copy(self.__inter_arrival_times)
for index, value in enumerate(self.__arrival_times):
if index != 0:
self.__arrival_times[index] += self.__arrival_times[index-1]
self.__arrival_times = intervals_to_timestamps(self.__inter_arrival_times)

def __process_departure_times(self) -> None:
for index, arrive_at in enumerate(self.__arrival_times):
Expand Down
12 changes: 11 additions & 1 deletion test/queue_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from src.queue import Queue
from src.queue import Queue, intervals_to_timestamps, timestamps_to_intervals


class TestQueue:
Expand Down Expand Up @@ -69,3 +69,13 @@ def test_with_two_executors(self):
np.testing.assert_allclose(queue.utilization(1), [1, 1, 1, 1], rtol=1e-02)


class TestIntervalsAndTimestamps:

def test_intervals_to_timestamps(self):
result = intervals_to_timestamps(np.array([1, 1, 1, 1]))
np.testing.assert_equal(result, [1, 2, 3, 4])

def test_timestamps_to_intervals(self):
result = timestamps_to_intervals(np.array([1, 2, 3, 4]))
np.testing.assert_equal(result, [1, 1, 1, 1])

0 comments on commit 0051690

Please sign in to comment.