Skip to content

Relabel nodes in canonical order #144

@lmondada

Description

@lmondada

For testing and comparing portgraphs, It would useful to be able to reorder a graph's node indices into a canonical order. We could either change the behaviour of compact_nodes to do that, or alternatively introduce an additional e.g. compact_nodes_canonical (the reason for the latter variant is that we might want to pass arguments to the function).

We would need first to discuss what "canonical" should mean:

Canonical ordering of nodes

Given the ordering of port offsets, a Dfs or Bfs traversal gives us a canonical ordering of nodes, up to a choice of start vertex per connected component of the graph (this assumes that directed edges can also be traversed backwards). I can think of a couple of strategies to choose the start vertices

  • order connected components by their number of vertices
  • pick vertices with indegree 0 as start.

This is obviously still not unique, but definitely good enough for me. Choosing the smallest NodeIndex first would be a reasonable tie-breaker. Alternatively, we could let the caller specify a tie-breaking strategy...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions