From 763ebfe1369891d6ba7bc03197bffd8d1fe97561 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Wed, 15 Feb 2023 02:50:03 +0100 Subject: [PATCH] set up complete graph if n<=d If the number of nodes in a channel is smaller or equal than the requested degree, a fully connected graph is used. For n>d, a random d-regular graph is set up. (For n=d+1, the two are the same.) Signed-off-by: Csaba Kiraly --- DAS/simulator.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/DAS/simulator.py b/DAS/simulator.py index 3e6e496..5553087 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -53,9 +53,14 @@ class Simulator: for id in range(self.shape.blockSize): - if (len(rowChannels[id]) < self.shape.netDegree): - self.logger.error("Graph degree higher than %d" % len(rowChannels[id]), extra=self.format) - G = nx.random_regular_graph(self.shape.netDegree, len(rowChannels[id])) + # If the number of nodes in a channel is smaller or equal to the + # requested degree, a fully connected graph is used. For n>d, a random + # d-regular graph is set up. (For n=d+1, the two are the same.) + if (len(rowChannels[id]) <= self.shape.netDegree): + self.logger.debug("Graph fully connected with degree %d !" % (len(rowChannels[id]) - 1), extra=self.format) + G = nx.complete_graph(len(rowChannels[id])) + else: + G = nx.random_regular_graph(self.shape.netDegree, len(rowChannels[id])) if not nx.is_connected(G): self.logger.error("Graph not connected for row %d !" % id, extra=self.format) for u, v in G.edges: @@ -64,9 +69,11 @@ class Simulator: val1.rowNeighbors[id].update({val2.ID : Neighbor(val2, self.shape.blockSize)}) val2.rowNeighbors[id].update({val1.ID : Neighbor(val1, self.shape.blockSize)}) - if (len(columnChannels[id]) < self.shape.netDegree): - self.logger.error("Graph degree higher than %d" % len(columnChannels[id]), extra=self.format) - G = nx.random_regular_graph(self.shape.netDegree, len(columnChannels[id])) + if (len(columnChannels[id]) <= self.shape.netDegree): + self.logger.debug("Graph fully connected with degree %d !" % (len(columnChannels[id]) - 1), extra=self.format) + G = nx.complete_graph(len(columnChannels[id])) + else: + G = nx.random_regular_graph(self.shape.netDegree, len(columnChannels[id])) if not nx.is_connected(G): self.logger.error("Graph not connected for column %d !" % id, extra=self.format) for u, v in G.edges: