def _minimum_spanning_tree_subgraph(G): mst_subgraph = Graph() if type(G) is not Graph: raise Exception("input graph must be undirected") mst_df = minimum_spanning_tree_wrapper.minimum_spanning_tree(G) if G.renumbered: mst_df = G.unrenumber(mst_df, "src") mst_df = G.unrenumber(mst_df, "dst") mst_subgraph.from_cudf_edgelist( mst_df, source="src", destination="dst", edge_attr="weight" ) return mst_subgraph
def _maximum_spanning_tree_subgraph(G): mst_subgraph = Graph() if type(G) is not Graph: raise Exception("input graph must be undirected") if G.adjlist.weights is not None: G.adjlist.weights = G.adjlist.weights.mul(-1) mst_df = minimum_spanning_tree_wrapper.minimum_spanning_tree(G) # revert to original weights if G.adjlist.weights is not None: G.adjlist.weights = G.adjlist.weights.mul(-1) mst_df["weight"] = mst_df["weight"].mul(-1) if G.renumbered: mst_df = G.unrenumber(mst_df, "src") mst_df = G.unrenumber(mst_df, "dst") mst_subgraph.from_cudf_edgelist( mst_df, source="src", destination="dst", edge_attr="weight" ) return mst_subgraph