Commit 999a3b4f authored by Carlos GO's avatar Carlos GO
Browse files

custom indel

parent 3c4fd1e6
......@@ -102,7 +102,7 @@ def edge_edit_cost_custom(u,v, g1, g2, node, sub_matrix, indel_cost=4, sub_cost=
cost = indel_cost
else:
cost = 0
return cost + edge_edit_cost(u,v,g1,g2,node.parent)
return cost + edge_edit_cost_custom(u,v,g1,g2,node.parent, sub_mat)
def edge_edit_cost(u,v, g1, g2, node, indel_cost=4, sub_cost=1, ss_break_cost=2):
"""
Recursively search for edge substitution.
......@@ -173,7 +173,7 @@ def node_cost(op, G1, G2):
else:
return 0
def cost(op, G1, G2, parent, loop_cost=True, skeleton=False, sub_matrix=None):
def cost(op, G1, G2, parent, loop_cost=True, skeleton=False, sub_matrix=None, indel=4):
"""
Returns the cost of an operation.
TODO: add edge edit cost here.
......@@ -188,7 +188,7 @@ def cost(op, G1, G2, parent, loop_cost=True, skeleton=False, sub_matrix=None):
if loop_cost:
return edge_edit_cost(u,v,G1,G2,parent) + node_cost(op, G1, G2)
elif sub_matrix:
return edge_edit_cost_custom(u,v,G1,G2, parent, sub_matrix)
return edge_edit_cost_custom(u,v,G1,G2, parent, sub_matrix, indel=indel)
else:
return edge_edit_cost(u,v,G1,G2, parent)
......@@ -273,7 +273,8 @@ def local_heuristic(op, parent, g1, g2):
diff = 2 * (abs(len(unmapped_nei_v) - len(unmapped_nei_u)))
return diff
def ged(graphs, with_heuristic=False, timeout=30, halt=None, source_only=False, sub_matrix=None):
def ged(graphs, with_heuristic=False, timeout=30, halt=None, source_only=False,
sub_matrix=None, indel=4):
"""
Compute GED of two graphs.
"""
......@@ -296,14 +297,14 @@ def ged(graphs, with_heuristic=False, timeout=30, halt=None, source_only=False,
for n in g2_nodes:
op = (g1_nodes[0], n)
c = cost(op, g1, g2, None, sub_matrix=sub_matrix)
c = cost(op, g1, g2, None, sub_matrix=sub_matrix, indel=indel)
h=0
if with_heuristic:
h = heuristic(op,None, g1, g2)
heappush(open, (c+h, count, OpNode(op, c, root)))
count += 1
del_op = (g1_nodes[0], 'NILL')
c = cost(del_op, g1, g2, None, sub_matrix=sub_matrix)
c = cost(del_op, g1, g2, None, sub_matrix=sub_matrix, indel=indel)
h = 0
if with_heuristic:
h = heuristic(op,None, g1, g2)
......@@ -329,14 +330,14 @@ def ged(graphs, with_heuristic=False, timeout=30, halt=None, source_only=False,
ops = [(g1_nodes[p_min.depth], u) for u in g2.nodes if
u not in p_min.target_map]
for op in ops:
c = cost(op, g1, g2, p_min, sub_matrix=sub_matrix) + cum_cost
c = cost(op, g1, g2, p_min, sub_matrix=sub_matrix, indel=indel) + cum_cost
h=0
if with_heuristic:
h = heuristic(op,p_min, g1, g2)
heappush(open, (c+h , count, OpNode(op,c,p_min)))
count += 1
del_op = (g1_nodes[p_min.depth], 'NILL')
c = cost(del_op, g1, g2, p_min, sub_matrix=sub_matrix) + cum_cost
c = cost(del_op, g1, g2, p_min, sub_matrix=sub_matrix, indel=indel) + cum_cost
h=0
if with_heuristic:
h = heuristic(op,p_min, g1, g2)
......@@ -351,7 +352,7 @@ def ged(graphs, with_heuristic=False, timeout=30, halt=None, source_only=False,
cur_node = p_min
return (p_min, graphs, time.time() - start)
for op in ops:
c = cost(op, g1, g2, p_min, sub_matrix=sub_matrix) + cum_cost
c = cost(op, g1, g2, p_min, sub_matrix=sub_matrix, indel=indel) + cum_cost
h=0
if with_heuristic:
h = heuristic(op,p_min, g1, g2)
......
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