Closed Raghad1997 closed 5 years ago
Hi, You don't need to implement the MST. It is already implemented in the networkx library. The G variable of the topology class is a networkx graph.
https://networkx.github.io/documentation/networkx-1.10/reference/algorithms.mst.html
My other Question I have a physical topology so I want to build a logical topology ( based on the weight of links and node costs) from the physical can we apply this requirement in the simulation? if yes? how we can do that
I want the logical topology to implement the MST to remove the cycle
@wisaaco
Hello,
In the topology, you can define as many attributes as you want. Networkx is a powerful library with multiples implemented graph algorithms. An example:
t = Topology()
#A grid
t.G = nx.grid_2d_graph(10, 10, periodic=False)
# for visualization purporses
lat = {}
lng = {}
for k in t.G.nodes():
lat[k[1] + k[0] * 10] = k[0]
lng[k[1] + k[0] * 10] = k[1]
li = {x: int(x[1] + x[0] * 10) for x in t.G.nodes}
nx.relabel_nodes(t.G, li, False) # Transform str-labels to int-labels
# Adding diaganols
for i in range(100):
if i < 89 and not i in range(9, 100, 10):
t.G.add_edge(i, i + 11)
if i > 0 and i < 90:
t.G.add_edge(i, i + 9)
# Lat and lng attributes are used for visualization
nx.set_node_attributes(t.G, values=lat, name="lat")
nx.set_node_attributes(t.G, values=lng, name="lng")
# Node mandatory attributes
valuesOne = dict(itertools.izip(t.G.nodes(), np.ones(len(t.G.nodes()))))
nx.set_node_attributes(t.G, name='IPT', values=valuesOne)
# Edge mandatory attributes
valuesOne = dict(itertools.izip(t.G.edges(), np.ones(len(t.G.edges()))))
nx.set_edge_attributes(t.G, name='BW', values=valuesOne)
nx.set_edge_attributes(t.G, name='PR', values=valuesOne)
nx.write_graphml(t.G, "network_grid.graphml")
Other possible solution is to have another Graph. In your custom classes, you can have all variables than you need, so, you can create your `logical topology'.
@wisaaco Good morning, I have a question, is it possible to imply the minimum spanning tree algorithm? in the simulation?
for example, I have an orchestrator and nodes with their edges and I want the MST ?
Can we implement that ? in YAFS simulation