From 815f7d8141eb8a40bc218450db6413f415c74a16 Mon Sep 17 00:00:00 2001 From: Jacob Palecek Date: Thu, 17 Jun 2021 19:18:23 +0200 Subject: [PATCH 1/2] Change the signature of GeoCell and add documentation This should help prevent bugs in the future, since some bugs already occurred that would have been mitigated by the changes signature and documentation. Signed-off-by: Jacob Palecek --- ether/cell.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ether/cell.py b/ether/cell.py index 5aa6385..8404f21 100644 --- a/ether/cell.py +++ b/ether/cell.py @@ -166,7 +166,14 @@ def materialize(self, topology: Topology, parent=None): class GeoCell(Cell): - def __init__(self, size, density, nodes) -> None: + def __init__(self, density, nodes, size: int = 1) -> None: + """ + Initializes the GeoCell :param density: int or Randomsampler. Used to divide the nodes in the cells :param + nodes: nodes the GeoCell will contain :param size: Number of times GeoCell will iterate over the nodes when + materializing. ATTENTION: If you want to supply your own nodes that aren't themselves generators, + this must be 1, since otherwise materialize will be called n times on your nodes, depending on what size you + choose + """ super().__init__(nodes, size) if isinstance(density, int): self.density = ConstantSampler(density) @@ -176,7 +183,7 @@ def __init__(self, size, density, nodes) -> None: raise ValueError('unknown density type %s' % type(density)) def materialize(self, topology: Topology, parent=None): - for i in range(self.size): + for _ in range(self.size): n = self.density.sample() for c in self.nodes: From 6a396a1c30a5741a3e782f12258004f1607b897e Mon Sep 17 00:00:00 2001 From: Jacob Palecek Date: Thu, 17 Jun 2021 19:18:23 +0200 Subject: [PATCH 2/2] Change the signature of GeoCell and add documentation This should help prevent bugs in the future, since some bugs already occurred that would have been mitigated by the changes signature and documentation. Signed-off-by: Jacob Palecek --- ether/cell.py | 11 +++++++++-- ether/scenarios/urbansensing.py | 2 +- examples/urbansensing.py | 2 +- examples/vivaldi/urban_sensing.py | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ether/cell.py b/ether/cell.py index 5aa6385..8404f21 100644 --- a/ether/cell.py +++ b/ether/cell.py @@ -166,7 +166,14 @@ def materialize(self, topology: Topology, parent=None): class GeoCell(Cell): - def __init__(self, size, density, nodes) -> None: + def __init__(self, density, nodes, size: int = 1) -> None: + """ + Initializes the GeoCell :param density: int or Randomsampler. Used to divide the nodes in the cells :param + nodes: nodes the GeoCell will contain :param size: Number of times GeoCell will iterate over the nodes when + materializing. ATTENTION: If you want to supply your own nodes that aren't themselves generators, + this must be 1, since otherwise materialize will be called n times on your nodes, depending on what size you + choose + """ super().__init__(nodes, size) if isinstance(density, int): self.density = ConstantSampler(density) @@ -176,7 +183,7 @@ def __init__(self, size, density, nodes) -> None: raise ValueError('unknown density type %s' % type(density)) def materialize(self, topology: Topology, parent=None): - for i in range(self.size): + for _ in range(self.size): n = self.density.sample() for c in self.nodes: diff --git a/ether/scenarios/urbansensing.py b/ether/scenarios/urbansensing.py index 12ca524..480709f 100644 --- a/ether/scenarios/urbansensing.py +++ b/ether/scenarios/urbansensing.py @@ -51,7 +51,7 @@ def create_city(self) -> GeoCell: backhaul=MobileConnection(self.internet) ) - city = GeoCell(self.num_cells, nodes=[neighborhood], density=self.cell_density) + city = GeoCell(size=self.num_cells, nodes=[neighborhood], density=self.cell_density) return city diff --git a/examples/urbansensing.py b/examples/urbansensing.py index c3cbc46..e644c86 100644 --- a/examples/urbansensing.py +++ b/examples/urbansensing.py @@ -32,7 +32,7 @@ def main(): shared_bandwidth=500, backhaul=MobileConnection('internet_chix')) city = GeoCell( - 5, nodes=[neighborhood], density=lognorm((0.82, 2.02))) + size=5, nodes=[neighborhood], density=lognorm((0.82, 2.02))) cloudlet = Cloudlet( 5, 2, backhaul=FiberToExchange('internet_chix')) diff --git a/examples/vivaldi/urban_sensing.py b/examples/vivaldi/urban_sensing.py index d6ee69a..4526850 100644 --- a/examples/vivaldi/urban_sensing.py +++ b/examples/vivaldi/urban_sensing.py @@ -47,7 +47,7 @@ def create_edge_broker() -> Broker: nodes=[[aot_node] * size, [edge_broker_factory_with_region(region)]], backhaul=MobileConnection(region) ) - city = GeoCell(5, nodes=[neighborhood], density=lognorm((0.82, 2.02))) + city = GeoCell(size=5, nodes=[neighborhood], density=lognorm((0.82, 2.02))) topology.add(city) broker = Broker(f'cloud-broker_{region}', backhaul=region)