def test_min_maximal_matching(): # smoke test G = nx.Graph() assert len(a.min_maximal_matching(G)) == 0
(1, 7), (1, 8), (2, 11), (2, 16), (2, 17), (3, 14), (3, 16), (3, 17), (4, 7), (4, 13), (4, 17), (5, 6), (5, 11), (6 ,18), (9 ,12), (10, 13), (11, 17), (13, 15), (15 ,17), (16 ,19)] graph=nx.Graph() graph.add_edges_from(graphEdges) print(graph.nodes()) print(graph.edges()) print(min_maximal_matching(graph)) print(graph) g1=nx.barabasi_albert_graph(1000,400) print(nx.maximal_independent_set((g1))) solution=[-1]*g1
def test_min_maximal_matching(): # smoke test G = nx.Graph() assert_equal(len(a.min_maximal_matching(G)), 0)
def create_graph(edgelist): G = nx.DiGraph() G.add_weighted_edges_from(edgelist) # Graph layout pos = nx.spring_layout(G) # Remove nodes with out-degree = 1------------------------------------------ outdeg = nx.degree(G) while 1 in outdeg.values(): to_remove = [n for n in outdeg if outdeg[n] == 1] G.remove_nodes_from(to_remove) # Remove edges also checking the two values of the tuple edgelist = [x for x in edgelist if x[0] not in to_remove] edgelist = [x for x in edgelist if x[1] not in to_remove] outdeg = nx.degree(G) # --------------------------------------------------------------------------- # Node size ================================================================ d = nx.degree(G) nx.draw_networkx_nodes(G, pos, nodelist=d.keys(), node_size=[v * 100 for v in d.values()]) # =========================================================================== nx.draw_networkx_nodes(G, pos, cmap=plt.get_cmap("jet"), node_size=1) edge_labels = dict([((u, v), d["weight"]) for u, v, d in G.edges(data=True)]) nx.draw_networkx_edges(G, pos, width=0.5, alpha=0.2) nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels) labels = {} for node in G.nodes(): labels[node] = node nx.draw_networkx_labels(G, pos, labels, font_size=8) if not len(G) == 1: from networkx.algorithms import approximation as apxm print apxm.min_edge_dominating_set(G) print apxm.max_clique(G) print apxm.maximum_independent_set(G) print apxm.min_maximal_matching(G) print nx.degree_centrality(G) plt.savefig("directed.png") # save as png # clean old graph plt.clf()
def test_min_maximal_matching(): # smoke test G = nx.Graph() assert_equal(len(a.min_maximal_matching(G)),0)
with_labels=False, node_size=50, nodelist=vl) if el: nx.draw_networkx_edges(g, pos=pos, ax=ax, edge_color='r', width=3, edgelist=el) ax.set_title(title) ax.set_axis_off() ax.set_aspect('equal') if __name__ == '__main__': g = gen() fix_outer_cycle_pos(g, get_cycle(g, 3)) fix_all_pos(g) vc = min_weighted_vertex_cover(g) m = min_maximal_matching(g) print m fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4)) draw(g, ax1, 'vertex cover', vl=list(vc)) draw(g, ax2, 'matching', el=list(m)) plt.tight_layout() plt.show()