2

For example, I would like to add some attributes to nodes and edges (say, some labels or any other additional info).

Is it possible to do that in NetworKit?

Thank you in advance!

elfinorr
  • 189
  • 3
  • 12

2 Answers2

1

NetworKit does not store internally additional node/edge attributes. However, assuming that you have a graph G, you can store properties externally (e.g., in a list or in a map), and use node/edge ids to access them. In NetworKit, node ids are always indexed from 0 to G.upperNodeIdBound() - 1, while edge ids are always indexed from 0 to G.upperEdgeIdBound() - 1.

To use edge ids, you first need to call G.indexEdges(), as edge ids are not generated by default. Then, G.edgeId(u, v) returns the id of the edge from node u to node v.

You can find more about this in the documentation of the NetworKit Graph class.

angriman
  • 430
  • 2
  • 12
1

Now, the latest version provide an API called "attachNodeAttribute" to create attribute for each node in a graph. You can attaches a node attribute to the graph G, then get and set attributes for each node.

For example:

A = G.attachNodeAttribute("attributeIdentifier", ofType) # attach a node attribute to Graph G

A[node] = value # set

value = A[node] # get

Check the following link to get more information in the documentation: https://networkit.github.io/dev-docs/python_api/networkit.html?highlight=attachnodeattribute#networkit.Graph.attachNodeAttribute

Alex
  • 11
  • 2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/33577420) – Joshua Voskamp Jan 09 '23 at 20:48