1
votes

I am working on a project about scheduling and routing in networks. I have the objective to implement some routing and scheduling algorithms for different frames in some protocol.

My question is regarding the kind of inputs that the NetworkX library in Python can handle and how scalable it is. I looked at more examples but did not really encounter some similar input data as mine.

I have a small example of input from another project, which represents a topology example with nodes and links, here is the example data:

    {
    "graph": {},
    "directed": true,
    "multigraph": true,
    "nodes": [
              {"id": 0, "host": false, "MSD": 4},
              {"id": 1, "host": false, "MSD": 4},
              {"id": 2, "host": false, "MSD": 4},
              {"id": 3, "host": false, "MSD": 4},
              {"id": 4, "host": false, "MSD": 4},
              {"id": 5, "host": false, "MSD": 4},
              {"id": 6, "host": false, "MSD": 4},
              {"id": 7, "host": false, "MSD": 4},
              {"id": 8, "host": false, "MSD": 4},
              {"id": 9, "host": false, "MSD": 4},
              {"id": 10, "host": false, "MSD": 4},
              {"id": 11, "host": false, "MSD": 4},
              {"id": 12, "host": true, "MSD": 4},
              {"id": 13, "host": true, "MSD": 4},
              {"id": 14, "host": true, "MSD": 4},
              {"id": 15, "host": true, "MSD": 4},
              {"id": 16, "host": true, "MSD": 4},
              {"id": 17, "host": true, "MSD": 4},
              {"id": 18, "host": true, "MSD": 4},
              {"id": 19, "host": true, "MSD": 4},
              {"id": 20, "host": true, "MSD": 4},
              {"id": 21, "host": true, "MSD": 4},
              {"id": 22, "host": true, "MSD": 4},
              {"id": 23, "host": true, "MSD": 4}
             ],
    "links": [
           {"source": 0, "target": 1, "key": 0, "id": "l0"},
           {"source": 0, "target": 12, "key": 0, "id": "l1"},
           {"source": 0, "target": 4, "key": 0, "id": "l2"},
           {"source": 1, "target": 0, "key": 0, "id": "l3"},
           {"source": 1, "target": 2, "key": 0, "id": "l4"},
           {"source": 1, "target": 13, "key": 0, "id": "l5"},
           {"source": 2, "target": 1, "key": 0, "id": "l6"},
           {"source": 2, "target": 3, "key": 0, "id": "l7"},
           {"source": 2, "target": 14, "key": 0, "id": "l8"},
           {"source": 3, "target": 2, "key": 0, "id": "l9"},
           {"source": 3, "target": 7, "key": 0, "id": "l10"},
           {"source": 3, "target": 15, "key": 0, "id": "l11"},
           {"source": 4, "target": 16, "key": 0, "id": "l12"},
           {"source": 4, "target": 8, "key": 0, "id": "l13"},
           {"source": 4, "target": 5, "key": 0, "id": "l14"},
           {"source": 4, "target": 0, "key": 0, "id": "l15"},
           {"source": 5, "target": 17, "key": 0, "id": "l16"},
        ]
        }

The number of "ids" represents the number of nodes, the "host" variable shows if it is an end node or a switch in the network and finally the "links" show the connections between nodes.

  1. Q1: How easy is it to use this kind of data as an input to make graphs in NetworkX library?
  2. Q2: Performing algorithms with the following data is scalable?
  3. Q3: How easy is the integration of NetworkX with my own algorithm implementation?

If you have any other useful Python libraries feel free to share them.

1

1 Answers

0
votes

I am not sure if you still need the answer because you might have figured it out in the meantime but here is my go: Q1: This kind of data is very easy to use. See my sample code below:

import networkx as nx
import matplotlib.pyplot as plt

nodes= [{"id": 0, "host": False, "MSD": 4},
    {"id": 1, "host": False, "MSD": 4},
    {"id": 2, "host": False, "MSD": 4},
    {"id": 3, "host": False, "MSD": 4},
    {"id": 4, "host": False, "MSD": 4},
    {"id": 5, "host": False, "MSD": 4},
    {"id": 6, "host": False, "MSD": 4},
    {"id": 7, "host": False, "MSD": 4},
    {"id": 8, "host": False, "MSD": 4},
    {"id": 9, "host": False, "MSD": 4},
    {"id": 10, "host": False, "MSD": 4},
    {"id": 11, "host": False, "MSD": 4},
    {"id": 12, "host": True, "MSD": 4},
    {"id": 13, "host": True, "MSD": 4},
    {"id": 14, "host": True, "MSD": 4},
    {"id": 15, "host": True, "MSD": 4},
    {"id": 16, "host": True, "MSD": 4},
    {"id": 17, "host": True, "MSD": 4},
    {"id": 18, "host": True, "MSD": 4},
    {"id": 19, "host": True, "MSD": 4},
    {"id": 20, "host": True, "MSD": 4},
    {"id": 21, "host": True, "MSD": 4},
    {"id": 22, "host": True, "MSD": 4},
    {"id": 23, "host": True, "MSD": 4}]

links= [{"source": 0, "target": 1, "key": 0, "id": "l0"},
    {"source": 0, "target": 12, "key": 0, "id": "l1"},
    {"source": 0, "target": 4, "key": 0, "id": "l2"},
    {"source": 1, "target": 0, "key": 0, "id": "l3"},
    {"source": 1, "target": 2, "key": 0, "id": "l4"},
    {"source": 1, "target": 13, "key": 0, "id": "l5"},
    {"source": 2, "target": 1, "key": 0, "id": "l6"},
    {"source": 2, "target": 3, "key": 0, "id": "l7"},
    {"source": 2, "target": 14, "key": 0, "id": "l8"},
    {"source": 3, "target": 2, "key": 0, "id": "l9"},
    {"source": 3, "target": 7, "key": 0, "id": "l10"},
    {"source": 3, "target": 15, "key": 0, "id": "l11"},
    {"source": 4, "target": 16, "key": 0, "id": "l12"},
    {"source": 4, "target": 8, "key": 0, "id": "l13"},
    {"source": 4, "target": 5, "key": 0, "id": "l14"},
    {"source": 4, "target": 0, "key": 0, "id": "l15"},
    {"source": 5, "target": 17, "key": 0, "id": "l16"}]

G = nx.DiGraph(name="Test")
for n in nodes:
    G.add_node(n["id"], host=n["host"], MSD=n["MSD"])
for l in links:
    G.add_edge(l["source"], l["target"], key=l["key"], id_=l["id"])

nx.draw_planar(G)
plt.show()

Q2: To my knowledge this type of data is quite well scalable especially since the NetworkX works with database as its core data type.

Q3: I have no idea but it seams that it could work well.