This file contains hidden or 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, ): | |
G2 = nx.MultiGraph() | |
G2.add_nodes_from(G.nodes(data=True)) | |
G2.add_edges_from(G.edges(data=True)) | |
# Add the node with its attributes | |
G2.add_node(new_node) | |
# Create the set of the edges that are to be contracted |