2

Let suppose we order the nodes first by degree (in + out), to get a list of node structures:

Node:
   labels: []   # lexicographic ordered
   out_arrows: []  # ordered by ordering of the nodes
   in_arrows: []   # ordered by ordering of the nodes

Then how should we order the nodes that have equal degree? Or am I approaching this the wrong way? My end goal is to have O(Q) to O(log N) graph lookup where N is the size of my library and Q is the size of a much smaller query graph. Not only that but once you convert the serialized data to a hashable type such as a string, then you can perform the search using a standard data structure (dictionary or map).

What is some work done in this area, i.e. have people already thought of this standard form serialization and search method?


Note that the key graphs my library will hold are relatively small (5-50) nodes, but their may be a million of them in the library. So it's not advised to perform a usual subgraph isomorphism search of the whole library say using Ullmann's algorithm, because for the most part, the graph is disconnected.

Daniel Donnelly
  • 628
  • 3
  • 12

1 Answers1

2

Graph canonization is well-studied, and there are sophisticated algorithms for it; see https://en.wikipedia.org/wiki/Graph_canonization. The standard answer is to use existing, well-tuned software, such as Nauty, rather than trying to invent your own.

How to implement in Python is out of scope of this site (but I would investigate API bindings or running it on the command line).

See also Graph isomorphism problem for labeled graphs.

D.W.
  • 167,959
  • 22
  • 232
  • 500