From 25ec0d93a965cd95bdedb9f03c04f102f03bf65d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 2 Jun 2023 13:15:38 +0100 Subject: [PATCH] Fix Link Traffic Levels observation encoding --- src/primaite/environment/observations.py | 2 +- .../obs_tests/laydown_with_LINK_TRAFFIC_LEVELS.yaml | 2 +- tests/test_observation_space.py | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/primaite/environment/observations.py b/src/primaite/environment/observations.py index a467a5db..a598d6db 100644 --- a/src/primaite/environment/observations.py +++ b/src/primaite/environment/observations.py @@ -281,7 +281,7 @@ class LinkTrafficLevels(AbstractObservationComponent): traffic_level = self._quantisation_levels - 1 else: traffic_level = (load / bandwidth) // ( - 1 / (self._quantisation_levels - 1) + 1 / (self._quantisation_levels - 2) ) + 1 obs.append(int(traffic_level)) diff --git a/tests/config/obs_tests/laydown_with_LINK_TRAFFIC_LEVELS.yaml b/tests/config/obs_tests/laydown_with_LINK_TRAFFIC_LEVELS.yaml index 516bf5cc..e65ea306 100644 --- a/tests/config/obs_tests/laydown_with_LINK_TRAFFIC_LEVELS.yaml +++ b/tests/config/obs_tests/laydown_with_LINK_TRAFFIC_LEVELS.yaml @@ -85,7 +85,7 @@ id: '5' startStep: 0 endStep: 5 - load: 20 + load: 999 protocol: TCP port: '80' source: '1' diff --git a/tests/test_observation_space.py b/tests/test_observation_space.py index 3fe71003..ae862c96 100644 --- a/tests/test_observation_space.py +++ b/tests/test_observation_space.py @@ -210,8 +210,8 @@ class TestLinkTrafficLevels: * two services * three nodes * two links - * an IER trying to send 20 bits of data over both links the whole time (via the first service) - * link bandwidth of 1000, therefore the utilisation is 2% + * an IER trying to send 999 bits of data over both links the whole time (via the first service) + * link bandwidth of 1000, therefore the utilisation is 99.9% """ act = np.asarray([0, 0, 0, 0]) obs, reward, done, info = env.step(act) @@ -219,6 +219,7 @@ class TestLinkTrafficLevels: # the observation space has combine_service_traffic set to False, so the space has this format: # [link1_service1, link1_service2, link2_service1, link2_service2] - # we send 20 bits of data via link1 and link2 on service 1. - # therefore the first and third elements should be 1 and all others 0 - assert np.array_equal(obs, [1, 0, 1, 0]) + # we send 999 bits of data via link1 and link2 on service 1. + # therefore the first and third elements should be 6 and all others 0 + # (`7` corresponds to 100% utiilsation and `6` corresponds to 87.5%-100%) + assert np.array_equal(obs, [6, 0, 6, 0])