def core_substitution(graph, orig_cip_graph, new_cip_graph):
"""
graph is the whole graph..
subgraph is the interfaceregrion in that we will transplant
new_cip_graph which is the interface and the new core
"""
graph=_edge_to_vertex(graph)
assert( set(orig_cip_graph.nodes()) - set(graph.nodes()) == set([]) ), 'orig_cip_graph not in graph'
# select only the interfaces of the cips
new_graph_interface_nodes = [n for n, d in new_cip_graph.nodes(data=True) if 'core' not in d]
new_cip_interface_graph = nx.subgraph(new_cip_graph, new_graph_interface_nodes)
original_graph_interface_nodes = [n for n, d in orig_cip_graph.nodes(data=True) if 'core' not in d]
original_interface_graph = nx.subgraph(orig_cip_graph, original_graph_interface_nodes)
# get isomorphism between interfaces, if none is found we return an empty graph
iso = get_good_isomorphism(graph,
orig_cip_graph,
new_cip_graph,
original_interface_graph,
new_cip_interface_graph)
if len(iso) != len(original_interface_graph):
# print iso
# draw.display(orig_cip_graph)
# draw.display(new_cip_graph)
#draw.graphlearn([orig_cip_graph, new_cip_graph],size=10)
logger.log(5,"grammar hash collision, discovered in 'core_substution' ")
return None
# ok we got an isomorphism so lets do the merging
graph = nx.union(graph, new_cip_graph, rename=('', '-'))
# removing old core
# original_graph_core_nodes = [n for n, d in orig_cip_graph.nodes(data=True) if 'core' in d]
original_graph_core_nodes = [n for n, d in orig_cip_graph.nodes(data=True) if 'core' in d]
for n in original_graph_core_nodes:
graph.remove_node(str(n))
# merge interfaces
for k, v in iso.iteritems():
#graph.node[str(k)][
# 'intgggerface'] = True # i am marking the interface only for the backflow probability calculation in graphlearn, this is probably deleteable because we also do this in merge, also this line is superlong Ooo
merge(graph, str(k), '-' + str(v))
# unionizing killed my labels so we need to relabel
graph=eg._revert_edge_to_vertex_transform(graph)
re = nx.convert_node_labels_to_integers(graph)
graph_clean(re)
return re
评论列表
文章目录