def test_strong_product_size(): K5 = nx.complete_graph(5) P5 = nx.path_graph(5) K3 = nx.complete_graph(3) G = nx.strong_product(P5, K3) assert_equal(nx.number_of_nodes(G), 5 * 3) G = nx.strong_product(K3, K5) assert_equal(nx.number_of_nodes(G), 3 * 5)
def test_strong_product_size(): K5=nx.complete_graph(5) P5=nx.path_graph(5) K3 = nx.complete_graph(3) G=strong_product(P5,K3) assert_equal(nx.number_of_nodes(G),5*3) G=strong_product(K3,K5) assert_equal(nx.number_of_nodes(G),3*5)
def test_strong_product_combinations(): P5 = nx.path_graph(5) K3 = nx.complete_graph(3) G = nx.strong_product(P5, K3) assert_equal(nx.number_of_nodes(G), 5 * 3) G = nx.strong_product(nx.MultiGraph(P5), K3) assert_equal(nx.number_of_nodes(G), 5 * 3) G = nx.strong_product(P5, nx.MultiGraph(K3)) assert_equal(nx.number_of_nodes(G), 5 * 3) G = nx.strong_product(nx.MultiGraph(P5), nx.MultiGraph(K3)) assert_equal(nx.number_of_nodes(G), 5 * 3)
def test_strong_product_combinations(): P5 = nx.path_graph(5) K3 = nx.complete_graph(3) G = strong_product(P5, K3) assert_equal(nx.number_of_nodes(G), 5 * 3) G = strong_product(nx.MultiGraph(P5), K3) assert_equal(nx.number_of_nodes(G), 5 * 3) G = strong_product(P5, nx.MultiGraph(K3)) assert_equal(nx.number_of_nodes(G), 5 * 3) G = strong_product(nx.MultiGraph(P5), nx.MultiGraph(K3)) assert_equal(nx.number_of_nodes(G), 5 * 3)
def graphStrongProdPower(graph, k): binaryOfK = bin(k)[2:] resultingGraph = "empty" currentProdGraph = graph #print(binaryOfK) for i in range(len(binaryOfK) - 1, -1, -1): if (binaryOfK[i] == '1'): if (resultingGraph == "empty"): resultingGraph = currentProdGraph else: resultingGraph = nx.strong_product(graph, currentProdGraph) if (i > 0): currentProdGraph = nx.strong_product(currentProdGraph, currentProdGraph) return resultingGraph
def graphStrongProdPower(graph, k): #we get the binary representation of k binaryOfK = bin(k)[2:] resultingGraph = "empty" currentProdGraph = graph #we go through and figure out which powers of 2 of the graph we need to get to figure out the strong graph product power for i in range(len(binaryOfK) - 1, -1, -1): if (binaryOfK[i] == '1'): if (resultingGraph == "empty"): resultingGraph = currentProdGraph else: resultingGraph = nx.strong_product(resultingGraph, currentProdGraph) if (i > 0): currentProdGraph = nx.strong_product(currentProdGraph, currentProdGraph) return resultingGraph
def test_strong_product_random(): G = nx.erdos_renyi_graph(10, 2 / 10.) H = nx.erdos_renyi_graph(10, 2 / 10.) GH = nx.strong_product(G, H) for (u_G, u_H) in GH.nodes(): for (v_G, v_H) in GH.nodes(): if (u_G == v_G and H.has_edge(u_H, v_H)) or \ (u_H == v_H and G.has_edge(u_G, v_G)) or \ (G.has_edge(u_G, v_G) and H.has_edge(u_H, v_H)): assert_true(GH.has_edge((u_G, u_H), (v_G, v_H))) else: assert_true(not GH.has_edge((u_G, u_H), (v_G, v_H)))
def test_strong_product_random(): G = nx.erdos_renyi_graph(10,2/10.) H = nx.erdos_renyi_graph(10,2/10.) GH = strong_product(G,H) for (u_G,u_H) in GH.nodes_iter(): for (v_G,v_H) in GH.nodes_iter(): if (u_G==v_G and H.has_edge(u_H,v_H)) or \ (u_H==v_H and G.has_edge(u_G,v_G)) or \ (G.has_edge(u_G,v_G) and H.has_edge(u_H,v_H)): assert_true(GH.has_edge((u_G,u_H),(v_G,v_H))) else: assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))
def test_strong_product_null(): null = nx.null_graph() empty10 = nx.empty_graph(10) K3 = nx.complete_graph(3) K10 = nx.complete_graph(10) P3 = nx.path_graph(3) P10 = nx.path_graph(10) # null graph G = nx.strong_product(null, null) assert_true(nx.is_isomorphic(G, null)) # null_graph X anything = null_graph and v.v. G = nx.strong_product(null, empty10) assert_true(nx.is_isomorphic(G, null)) G = nx.strong_product(null, K3) assert_true(nx.is_isomorphic(G, null)) G = nx.strong_product(null, K10) assert_true(nx.is_isomorphic(G, null)) G = nx.strong_product(null, P3) assert_true(nx.is_isomorphic(G, null)) G = nx.strong_product(null, P10) assert_true(nx.is_isomorphic(G, null)) G = nx.strong_product(empty10, null) assert_true(nx.is_isomorphic(G, null)) G = nx.strong_product(K3, null) assert_true(nx.is_isomorphic(G, null)) G = nx.strong_product(K10, null) assert_true(nx.is_isomorphic(G, null)) G = nx.strong_product(P3, null) assert_true(nx.is_isomorphic(G, null)) G = nx.strong_product(P10, null) assert_true(nx.is_isomorphic(G, null))
def test_strong_product_raises(): P = nx.strong_product(nx.DiGraph(), nx.Graph())
def test_strong_product_null(): null=nx.null_graph() empty10=nx.empty_graph(10) K3=nx.complete_graph(3) K10=nx.complete_graph(10) P3=nx.path_graph(3) P10=nx.path_graph(10) # null graph G=strong_product(null,null) assert_true(nx.is_isomorphic(G,null)) # null_graph X anything = null_graph and v.v. G=strong_product(null,empty10) assert_true(nx.is_isomorphic(G,null)) G=strong_product(null,K3) assert_true(nx.is_isomorphic(G,null)) G=strong_product(null,K10) assert_true(nx.is_isomorphic(G,null)) G=strong_product(null,P3) assert_true(nx.is_isomorphic(G,null)) G=strong_product(null,P10) assert_true(nx.is_isomorphic(G,null)) G=strong_product(empty10,null) assert_true(nx.is_isomorphic(G,null)) G=strong_product(K3,null) assert_true(nx.is_isomorphic(G,null)) G=strong_product(K10,null) assert_true(nx.is_isomorphic(G,null)) G=strong_product(P3,null) assert_true(nx.is_isomorphic(G,null)) G=strong_product(P10,null) assert_true(nx.is_isomorphic(G,null))
def test_strong_product_raises(): P = strong_product(nx.DiGraph(), nx.Graph())
#89149963 3/7 colors #89150081 3/7 #89150083 3/7 #69210692 2/3 i = 0 start = time.time() for s in s_gen: if i <= 69210691: i += 1 continue #generate the confusability graph G of X given Y, YR gxyyr = indset.generateGXYYR(s) gxyyr2 = nx.strong_product(gxyyr, gxyyr) #from that generate G R given K graphs. pairs = indset.generateGRK(gxyyr, s) # grklist = [grk for (grk, k) in pairs] # klist = [k for (grk, k) in pairs] r1 = 4 g1min = nx.Graph() k1min = [] for (g1, k1) in pairs: c = coloring.minimalColoring(g1, 0) if c < r1: r1 = c g1min = g1.copy()
def test_strong_product_raises(): with pytest.raises(nx.NetworkXError): P = nx.strong_product(nx.DiGraph(), nx.Graph())
import networkx as nx #basic example G = nx.cycle_graph(5) A1 = nx.nx_agraph.to_agraph(G) A1.draw('testpentagon', format='png', prog='circo') strong = nx.strong_product(G, G) A2 = nx.nx_agraph.to_agraph(strong) A2.draw('teststrong', format='png', prog='circo') print nx.maximum_independent_set(strong)
import networkx as nx import matplotlib.pyplot as plt from random import choice def setUtil(graph): if graph.number_of_nodes() == 0:#G is empty return 0 #v = any vertex in G v = choice(graph.nodes()) neighborhood = graph.copy().neighbors(v) + [v] #print neighborhood withV = graph.copy() withV.remove_nodes_from(neighborhood) withoutV = graph.copy() withoutV.remove_node(v) return max(1 + setUtil(withV), setUtil(withoutV)) G = nx.cycle_graph(7) S = nx.strong_product(G, G) Q = nx.strong_product(G, S) print setUtil(Q)