Commit 7e70cee1 authored by Fize Jacques's avatar Fize Jacques

Debug GED (again !)

parent df18e0b3
......@@ -17,25 +17,35 @@ cdef class GraphEditDistance(AbstractGraphEditDistance):
cpdef double substitute_cost(self, node1, node2, G, H):
return self.relabel_cost(node1, node2, G, H)
def relabel_cost(self, node1, node2, G, H):
if len(G.edges(node1)) == 0 and len(H.edges(node2)) ==0:
if node1 == node2:
return 0.0
return self.node_del+self.node_ins
R = nx.create_empty_copy(G)
R.add_edges_from(G.edges(node1,data=True))
nx.relabel_nodes(R,{node1:node2},copy=False)
R2 = nx.create_empty_copy(H)
R2.add_edges_from(H.edges(node2,data=True))
inter_=intersection(R,R2).number_of_edges()
add_diff=abs(R2.number_of_edges()-inter_)
del_diff=abs(R.number_of_edges()-inter_)
return (add_diff*self.edge_ins)+(del_diff*self.edge_del)+(0 if node1 == node2 else self.node_del+self.node_ins)
def add_edges(self,node1,node2,G):
R=nx.create_empty_copy(G)
try:
R.add_edges_from(G.edges(node1,node2))
except:
pass
return R
def relabel_cost(self, node1, node2, G, H):
## Si deux noeuds égaux
if node1 == node2 and G.degree(node1) == H.degree(node2):
return 0.0
elif node1 == node2 and G.degree(node1) != H.degree(node2):
R = self.add_edges(node1,node2,G)
R2 = self.add_edges(node1,node2,H)
inter_=intersection(R,R2).number_of_edges()
add_diff=abs(R2.number_of_edges()-inter_)
del_diff=abs(R.number_of_edges()-inter_)
return (add_diff*self.edge_ins)+(del_diff*self.edge_del)
#si deux noeuds connectés
if (node1,node2) in G.edges() or (node2,node1) in G.edges():
return self.node_ins+self.node_del
if not node2 in G:
nodesH=list(H.nodes())
index=nodesH.index(node2)
return self.node_del+self.node_ins+self.insert_cost(index,index,nodesH,H)
return sys.maxsize
cdef double delete_cost(self, int i, int j, nodesG, G):
if i == j:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment