Commit ec02e891 authored by Benoit GAUZERE's avatar Benoit GAUZERE

Implementation of attributes genericity for GED.py.

parent a87de536
......@@ -7,12 +7,17 @@ def ged(G1, G2, method='Riesen', rho=None, varrho=None,
cf=ConstantCostFunction(1, 3, 1, 3),
solver=linear_sum_assignment):
"""Compute Graph Edit Distance between G1 and G2 according to mapping
encoded within rho and varrho. Graph's node must be indexed by a
index which is used is rho and varrho
NB: Utilisation de
dictionnaire pour etre plus versatile ?
encoded within rho and varrho.
Graph's node must be indexed by a index starting at 0 which is
used in rho and varrho
TODO : rho and varrho should be encoded as a dict, but how to
manage the comparaison of phi_i and m
"""
if ((rho is None) or (varrho is None)):
if(method == 'Riesen'):
cf_bp = RiesenCostFunction(cf,lsap_solver=solver)
......@@ -40,7 +45,7 @@ def ged(G1, G2, method='Riesen', rho=None, varrho=None,
if(phi_j >= n):
ged += cf.cni(j, G2)
for e in G1.edges(data=True):
for e in G1.edges():
i = e[0]
j = e[1]
phi_i = rho[i]
......@@ -49,7 +54,7 @@ def ged(G1, G2, method='Riesen', rho=None, varrho=None,
mappedEdge = len(list(filter(lambda x: True if
x == phi_j else False, G2[phi_i])))
if(mappedEdge):
e2 = [phi_i, phi_j, G2[phi_i][phi_j]]
e2 = [phi_i, phi_j]
min_cost = min(cf.ces(e, e2, G1, G2),
cf.ced(e, G1) + cf.cei(e2, G2))
ged += min_cost
......@@ -57,7 +62,7 @@ def ged(G1, G2, method='Riesen', rho=None, varrho=None,
ged += cf.ced(e, G1)
else:
ged += cf.ced(e, G1)
for e in G2.edges(data=True):
for e in G2.edges():
i = e[0]
j = e[1]
phi_i = varrho[i]
......
......@@ -43,12 +43,47 @@ class TestGEDMethods(unittest.TestCase):
def test_GED(self):
from pygraph.utils.graphfiles import loadGXL
import networkx as nx
from pygraph.ged.GED import ged
g = loadGXL('./test.gxl')
self.assertEqual(ged(g,g)[0],0)
from pygraph.ged.costfunctions import ConstantCostFunction
cns = 1
cni = 2
ces = 3
cei = 4
cf = ConstantCostFunction(cns=cns, cni=cni, ces=ces, cei=cei)
g1 = nx.Graph()
g1.add_nodes_from([(0, {'label': 1}),
(1, {'label': 1}),
(2, {'label': 2})])
g1.add_edges_from([(0,1,{'label': '1', 'label2': 2}),
(1,2,{'label': '3', 'label2': 1})])
g2 = nx.Graph()
g2.add_nodes_from([(0, {'label': 1}),
(1, {'label': 2}),
(2, {'label': 2})])
g2.add_edges_from([(0,1,{'label': '3', 'label2': 1}),
(0,2,{'label': '1', 'label2': 2})])
self.assertEqual(ged(g1, g1)[0], 0)
self.assertEqual(ged(g1, g1,
rho=[0, 1, 2, 3, 4, 5],
varrho=[0, 1, 2, 3, 4, 5])[0], 0)
self.assertNotEqual(ged(g1, g1,
rho=[0, 2, 1, 3, 4, 5],
varrho=[0, 2, 1, 3, 4, 5])[0], 0)
self.assertEqual(ged(g1, g2)[0], 1)
self.assertEqual(ged(g1, g2,
rho=[0, 1, 2, 3, 4, 5],
varrho=[0, 1, 2, 3, 4, 5])[0],
ged(g2, g1,
rho=[0, 1, 2, 3, 4, 5],
varrho=[0, 1, 2, 3, 4, 5])[0])
class TestGraphFilesMethods(unittest.TestCase):
......
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