This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Edge contraction as per http://en.wikipedia.org/wiki/Edge_contraction | |
def contract_edges(G,nodes, new_node, attr_dict=None, **attr): | |
'''Contracts the edges of the nodes in the set "nodes" ''' | |
#Add the node with its attributes | |
G.add_node(new_node, attr_dict, **attr) | |
#Create the set of the edges that are to be contracted | |
cntr_edge_set = G.edges(nodes, data = True) | |
#Add edges from new_node to all target nodes in the set of edges that are to be contracted | |
#Possibly also checking that edge attributes are preserved and not overwritten, |