Skip to content

Consistent representation of trees through "parent vectors" #1880

@szhorvat

Description

@szhorvat

There are several functions in igraph which effectively return a tree through a "parent vector", sometimes called "predecessors" or "father". We should make sure that functions that use this format are consistent with each other. We should also use a consistent and neutral naming (such as "parent").

Here is an incomplete list of relevant functions:

  • igraph_bfs, igraph_bfs_simple, igraph_dfs. @ntamas proposed to overhaul the interface of these functions.
  • igraph_get_shortest_paths, igraph_get_shortest_paths_dijkstra, igraph_get_shortest_paths_bellman_ford return the shortest path tree in a similar format. (fixed in Use parent vector of #1880 for get_shortest_paths #2070 and 9fddebf)
  • igraph_dominator_tree returns a tree like this as well
  • igraph_cohesive_blocks can return the block tree this way
  • There is a proposal in Create tree or forest from list of parents #1840 for a function to create a tree from this format.
  • Any other functions that are not yet mentioned? Please edit the issue and complete this list.

There are small differences in the representation:

  • DFS/BFS functions used NaN to represent the lack of a parent, but this was switched to -1 after the integer transition
  • Shortest path functions use -1 for unvisited vertices, but they use the same index as the vertex itself for the root vertex. According to the current proposal in Create tree or forest from list of parents #1840 such a vector would be rejected by the tree creation function. edit: shortest path functions now confirm to this proposal.

We need to make everything consistent, and since this is API-breaking, ideally do this before 0.10.

Other related issues to consider:

  • Do we want other functions to optionally return data in the same format? How about spanning tree functions—is it useful at all for them?
  • Do we want to introduce a format which can encode not just a spanning tree, but a complete edge traversal? This relates to modifying DFS/BFS which currently just record nodes, but not the edges. For some applications, the edges are necessary (e.g. cycle basis). It also relates to weighted shortest path functions, which also return the predecessor edge ID of each vertex—this is necessary to identify the weight of the incoming edge. But it is not sufficient for a complete representation of an edge traversal: for that we additionally need the predecessor vertex of each edge (thus two vectors: predecessor edge of each vertex and predecessor vertex of each edge). Finally, it also related to igraph_unfold_tree().

Metadata

Metadata

Assignees

No one assigned

    Labels

    todoTriaged for implementation in some unspecified future version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions