| @@ -1,10 +1,11 @@ | |||||
| from ged.costfunctions import BasicCostFunction, RiesenCostFunction | from ged.costfunctions import BasicCostFunction, RiesenCostFunction | ||||
| from ged.costfunctions import NeighboorhoodCostFunction | from ged.costfunctions import NeighboorhoodCostFunction | ||||
| from ged.bipartiteGED import computeBipartiteCostMatrix, getOptimalMapping | from ged.bipartiteGED import computeBipartiteCostMatrix, getOptimalMapping | ||||
| from scipy.optimize import linear_sum_assignment | |||||
| def ged(G1, G2, method='Riesen', rho=None, varrho=None, | def ged(G1, G2, method='Riesen', rho=None, varrho=None, | ||||
| cf=BasicCostFunction(1, 3, 1, 3)): | |||||
| cf=BasicCostFunction(1, 3, 1, 3), | |||||
| solver=linear_sum_assignment): | |||||
| """Compute Graph Edit Distance between G1 and G2 according to mapping | """Compute Graph Edit Distance between G1 and G2 according to mapping | ||||
| encoded within rho and varrho. Graph's node must be indexed by a | encoded within rho and varrho. Graph's node must be indexed by a | ||||
| index which is used is rho and varrho | index which is used is rho and varrho | ||||
| @@ -14,15 +15,16 @@ def ged(G1, G2, method='Riesen', rho=None, varrho=None, | |||||
| """ | """ | ||||
| if ((rho is None) or (varrho is None)): | if ((rho is None) or (varrho is None)): | ||||
| if(method == 'Riesen'): | if(method == 'Riesen'): | ||||
| cf_bp = RiesenCostFunction(cf) | |||||
| cf_bp = RiesenCostFunction(cf,lsap_solver=solver) | |||||
| elif(method == 'Neighboorhood'): | elif(method == 'Neighboorhood'): | ||||
| cf_bp = NeighboorhoodCostFunction(cf) | |||||
| cf_bp = NeighboorhoodCostFunction(cf,lsap_solver=solver) | |||||
| elif(method == 'Basic'): | elif(method == 'Basic'): | ||||
| cf_bp = cf | cf_bp = cf | ||||
| else: | else: | ||||
| raise NameError('Non existent method ') | raise NameError('Non existent method ') | ||||
| rho, varrho = getOptimalMapping(computeBipartiteCostMatrix(G1, G2, cf_bp)) | |||||
| rho, varrho = getOptimalMapping( | |||||
| computeBipartiteCostMatrix(G1, G2, cf_bp), lsap_solver=solver) | |||||
| n = G1.number_of_nodes() | n = G1.number_of_nodes() | ||||
| m = G2.number_of_nodes() | m = G2.number_of_nodes() | ||||
| @@ -49,7 +51,7 @@ def ged(G1, G2, method='Riesen', rho=None, varrho=None, | |||||
| if(mappedEdge): | if(mappedEdge): | ||||
| e2 = [phi_i, phi_j, G2[phi_i][phi_j]] | e2 = [phi_i, phi_j, G2[phi_i][phi_j]] | ||||
| min_cost = min(cf.ces(e, e2, G1, G2), | min_cost = min(cf.ces(e, e2, G1, G2), | ||||
| cf.ced(e, G1), cf.cei(e2, G2)) | |||||
| cf.ced(e, G1) + cf.cei(e2, G2)) | |||||
| ged += min_cost | ged += min_cost | ||||
| else: | else: | ||||
| ged += cf.ced(e, G1) | ged += cf.ced(e, G1) | ||||