networkxgraph-theoryrepast-simphonyrepast-hpcrepast4py

Is there a way to access the weight of an edge using Repast4Py's network module?


The Repast4py API documentation states there are ways to add edges with weights in a network. Similarly, it states ways to access the number of edges a given vertex has. However, it doesn't seem there is a way to access the weight of a given vertex. Is there any way to access the weight of an edge between two vertices using the Repast4py network module?


Solution

  • Each Repast4Py network object contains a graph field that is a networkx Graph object. This provides most of the non-distributed network functionality. Here's an example from the repast4py unit tests that use it to get an edge, and then get the 'weight' attribute of that edge.

    g = DirectedSharedNetwork('network', comm)
    g.add_edge(agents[5], agents[6], weight=12)
    edge = g.graph.edges[agents[5], agents[6]]
    self.assertEqual(12, edge['weight'])
    

    The shared networks tests at

    https://github.com/Repast/repast4py/blob/develop/tests/shared_network_tests.py

    have additional examples of working with edges. Also see the networkx documentation.

    https://networkx.org/documentation/stable/reference/index.html