For example, these two graphs is considered to be a perfect partial match:
0 – 1
1 – 2
2 – 3
3 – 0
AND
0 – 1
1 – 2
These two are considered a bad match
0 – 1
1 – 2
2 – 3
3 – 0
AND
0 – 1
1 – 2
2 – 0
The numbers don’t have to match, as long as the relation between those nodes can perfectly match.
This is the subgraph isomorphism problem: http://en.wikipedia.org/wiki/Subgraph_isomorphism_problem
There is one algorithm mentioned in the article due to Ullmann.
Ullmann’s algorithm is an extension of a depth-first search. A depth-first search would work like this:
For the basic algorithm,
possible_assignments[i] = range(0,graph.n_vertices). That is, all the vertices are a possibility.Ullmann extends this basic algorithm by narrowing the possibilities:
The idea is that if node i of the subgraph could possibly match node j of the graph, then for every node x that is adjacent to node i in the subgraph, it has to be possible to find a node y that is adjacent to node j in the graph. This process helps more than might first be obvious, because each time we eliminate a possible assignment, this may cause other possible assignments to be eliminated, since they are interdependent.
The final algorithm is then: