jacquesfize / GMatch4py

A graph matching library for Python
MIT License
192 stars 41 forks source link

Quick question: Do not quite understand simple output #14

Closed davidlee321 closed 3 years ago

davidlee321 commented 5 years ago

This simple example shows a different edit distance compared to networkX's GED. Would be great if someone could help me understand the difference. From my understanding of GED, the edit distance should be 1, not 2.

import networkx
import gmatch4py as gm

g1=nx.complete_bipartite_graph(2,3) 
g2=nx.complete_bipartite_graph(2,3)
g2.add_edge(0, 1)
adj=[(v, neighbors) for v, neighbors in g1.adjacency()]
print(adj)
adj=[(v, neighbors) for v, neighbors in g2.adjacency()]
print(adj)
ged=gm.GraphEditDistance(1,1,1,1) # all edit costs are equal to 1
result=ged.compare([g1,g2],None) 
print(result)
[(0, {2: {}, 3: {}, 4: {}}), (1, {2: {}, 3: {}, 4: {}}), (2, {0: {}, 1: {}}), (3, {0: {}, 1: {}}), (4, {0: {}, 1: {}})]
[(0, {2: {}, 3: {}, 4: {}, 1: {}}), (1, {2: {}, 3: {}, 4: {}, 0: {}}), (2, {0: {}, 1: {}}), (3, {0: {}, 1: {}}), (4, {0: {}, 1: {}})]

[[0. 2.]
 [2. 0.]]
ged_nx = nx.graph_edit_distance(g1, g2)
print(ged_nx)
1.0
jacquesfize commented 3 years ago

Dear @davidlee321,

It depends on the algorithm heuristic used to compute the edit distance. Here, the algorithm heuristic is different from the one used by networkX.

Best, @Jacobe2169