You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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...
The text was updated successfully, but these errors were encountered:
You could also choose the start vertices that minimise some global property (e.g. the hash of each connected component). This would be very close to unique, but more expensive to compute. In this case you could assume no hash collision and thus no tie-breaker would be required.
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
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...The text was updated successfully, but these errors were encountered: