예제 #1
0
 def test_padding(self):
     codes = (b":Cdv", b":DaYn", b":EaYnN", b":FaYnL", b":GaYnLz")
     for n, code in enumerate(codes, start=4):
         G = nx.path_graph(n)
         result = BytesIO()
         nx.write_sparse6(G, result, header=False)
         assert result.getvalue() == code + b"\n"
예제 #2
0
 def test_complete_bipartite(self):
     G = nx.complete_bipartite_graph(6, 9)
     result = BytesIO()
     nx.write_sparse6(G, result)
     # Compared with sage
     expected = b'>>sparse6<<:Nk' + b'?G`cJ' * 9 + b'\n'
     assert_equal(result.getvalue(), expected)
예제 #3
0
 def test_padding(self):
     codes = (b':Cdv', b':DaYn', b':EaYnN', b':FaYnL', b':GaYnLz')
     for n, code in enumerate(codes, start=4):
         G = nx.path_graph(n)
         result = BytesIO()
         nx.write_sparse6(G, result, header=False)
         assert result.getvalue() == code + b'\n'
예제 #4
0
 def test_complete_bipartite(self):
     G = nx.complete_bipartite_graph(6, 9)
     result = BytesIO()
     nx.write_sparse6(G, result)
     # Compared with sage
     expected = b'>>sparse6<<:Nk' + b'?G`cJ' * 9 + b'\n'
     assert result.getvalue() == expected
예제 #5
0
 def test_write_sparse6(self):
     fh = StringIO()
     nx.write_sparse6(nx.complete_bipartite_graph(6,9), fh)
     fh.seek(0)
     assert_equal(fh.read(),
                  '>>sparse6<<:Nk?G`cJ?G`cJ?G`cJ?G`'+
                  'cJ?G`cJ?G`cJ?G`cJ?G`cJ?G`cJ\n')
예제 #6
0
 def test_padding(self):
     codes = (b':Cdv', b':DaYn', b':EaYnN', b':FaYnL', b':GaYnLz')
     for n, code in enumerate(codes, start=4):
         G = nx.path_graph(n)
         result = BytesIO()
         nx.write_sparse6(G, result, header=False)
         self.assertEqual(result.getvalue(), code + b'\n')
예제 #7
0
 def test_write_sparse6(self):
     fh = StringIO()
     nx.write_sparse6(nx.complete_bipartite_graph(6, 9), fh)
     fh.seek(0)
     assert_equal(
         fh.read(), '>>sparse6<<:Nk?G`cJ?G`cJ?G`cJ?G`' +
         'cJ?G`cJ?G`cJ?G`cJ?G`cJ?G`cJ\n')
예제 #8
0
def store_graph(G, dir_name, pos, labels):
    path = os.path.join(GRAPH_ROOT, dir_name)
    if not os.path.isdir(path):
        os.makedirs(path)
    nx.write_sparse6(G, os.path.join(path, "graph.sparse6"))
    np.savez_compressed(os.path.join(path, "node_pos.npz"), pos)
    np.savez_compressed(os.path.join(path, "node_labels.npz"), labels)
    weights = list(G.edges(data='weight'))
    if weights:
        np.savez_compressed(os.path.join(path, "edge_weights.npz"),
                            np.array(weights)[:, -1])
예제 #9
0
 def test_read_write_inverse(self):
     for i in list(range(13)) + [31, 47, 62, 63, 64, 72]:
         m = min(2 * i, i * i // 2)
         g = nx.random_graphs.gnm_random_graph(i, m, seed=i)
         gstr = BytesIO()
         nx.write_sparse6(g, gstr, header=False)
         # Strip the trailing newline.
         gstr = gstr.getvalue().rstrip()
         g2 = nx.from_sparse6_bytes(gstr)
         assert_equal(g2.order(), g.order())
         assert_edges_equal(g2.edges(), g.edges())
예제 #10
0
 def test_read_write_inverse(self):
     for i in list(range(13)) + [31, 47, 62, 63, 64, 72]:
         m = min(2 * i, i * i // 2)
         g = nx.random_graphs.gnm_random_graph(i, m, seed=i)
         gstr = BytesIO()
         nx.write_sparse6(g, gstr, header=False)
         # Strip the trailing newline.
         gstr = gstr.getvalue().rstrip()
         g2 = nx.from_sparse6_bytes(gstr)
         assert g2.order() == g.order()
         assert_edges_equal(g2.edges(), g.edges())
예제 #11
0
 def test_write_path(self):
     # On Windows, we can't reopen a file that is open
     # So, for test we get a valid name from tempfile but close it.
     with tempfile.NamedTemporaryFile() as f:
         fullfilename = f.name
     # file should be closed now, so write_sparse6 can open it
     nx.write_sparse6(nx.null_graph(), fullfilename)
     fh = open(fullfilename, mode='rb')
     self.assertEqual(fh.read(), b'>>sparse6<<:?\n')
     fh.close()
     import os
     os.remove(fullfilename)
예제 #12
0
 def test_write_path(self):
     # On Windows, we can't reopen a file that is open
     # So, for test we get a valid name from tempfile but close it.
     with tempfile.NamedTemporaryFile() as f:
         fullfilename = f.name
     # file should be closed now, so write_sparse6 can open it
     nx.write_sparse6(nx.null_graph(), fullfilename)
     fh = open(fullfilename, mode='rb')
     assert fh.read() == b'>>sparse6<<:?\n'
     fh.close()
     import os
     os.remove(fullfilename)
예제 #13
0
 def no_directed_graphs(self):
     with self.assertRaises(nx.NetworkXNotImplemented):
         nx.write_sparse6(nx.DiGraph(), BytesIO())
 def test_complete_graph(self):
     G = nx.complete_graph(4)
     result = BytesIO()
     nx.write_sparse6(G, result)
     self.assertEqual(result.getvalue(), '>>sparse6<<:CcKI\n')
 def test_null_graph(self):
     G = nx.null_graph()
     result = BytesIO()
     nx.write_sparse6(G, result)
     self.assertEqual(result.getvalue(), '>>sparse6<<:?\n')
	elif(output_file_type=='Pajek'):
		
			try:
				G = nx.write_pajek(G,output_file_path)
		#if the file format isin ---Pajek----  write  graph G
				break
			except IOError:
				print("The out put type:"+output_file_type+"please select another output file path\n")
		
	elif(output_file_type=='SparseGraph6'):

		a=input("enter 1.for Sparse6 \n2.for graph6 format\n")
		if(a==1):
			
			try:
				G = nx.write_sparse6(G,output_file_path)
		#if the file format isin ---sparse6---  write  graph G
				break
			except IOError:
				print("The out put type:"+output_file_type+"please select another output file path\n")
			
		else :
			
			try:
				G=nx.write_graph6(G,output_file_path)
		#if the file format isin ---graph6----  write  graph G
				break
			except IOError:
				print("The out put type:"+output_file_type+"please select another output file path\n")
			
		#if the file format isin ---SparseGraph6----  write  graph G
예제 #17
0
 def no_directed_graphs(self):
     with self.assertRaises(nx.NetworkXNotImplemented):
         nx.write_sparse6(nx.DiGraph(), BytesIO())
예제 #18
0
 def test_large_empty_graph(self):
     G = nx.empty_graph(68)
     result = BytesIO()
     nx.write_sparse6(G, result)
     assert result.getvalue() == b'>>sparse6<<:~?@C\n'
예제 #19
0
 def test_complete_graph(self):
     G = nx.complete_graph(4)
     result = BytesIO()
     nx.write_sparse6(G, result)
     assert result.getvalue() == b'>>sparse6<<:CcKI\n'
예제 #20
0
 def test_no_directed_graphs(self):
     with pytest.raises(nx.NetworkXNotImplemented):
         nx.write_sparse6(nx.DiGraph(), BytesIO())
예제 #21
0
 def test_null_graph(self):
     G = nx.null_graph()
     result = BytesIO()
     nx.write_sparse6(G, result)
     assert result.getvalue() == b'>>sparse6<<:?\n'
예제 #22
0
 def test_no_header(self):
     G = nx.complete_graph(4)
     result = BytesIO()
     nx.write_sparse6(G, result, header=False)
     self.assertEqual(result.getvalue(), b':CcKI\n')
예제 #23
0
 def test_complete_graph(self):
     G = nx.complete_graph(4)
     result = BytesIO()
     nx.write_sparse6(G, result)
     self.assertEqual(result.getvalue(), b'>>sparse6<<:CcKI\n')
예제 #24
0
 def test_very_large_empty_graph(self):
     G = nx.empty_graph(258049)
     result = BytesIO()
     nx.write_sparse6(G, result)
     self.assertEqual(result.getvalue(), b'>>sparse6<<:~~???~?@\n')
예제 #25
0
 def test_large_empty_graph(self):
     G = nx.empty_graph(68)
     result = BytesIO()
     nx.write_sparse6(G, result)
     self.assertEqual(result.getvalue(), b'>>sparse6<<:~?@C\n')
예제 #26
0
 def test_trivial_graph(self):
     G = nx.trivial_graph()
     result = BytesIO()
     nx.write_sparse6(G, result)
     self.assertEqual(result.getvalue(), b'>>sparse6<<:@\n')
예제 #27
0
 def test_write_path(self):
     with tempfile.NamedTemporaryFile() as f:
         nx.write_sparse6(nx.null_graph(), f.name)
         self.assertEqual(f.read(), b'>>sparse6<<:?\n')
예제 #28
0
 def test_trivial_graph(self):
     G = nx.trivial_graph()
     result = BytesIO()
     nx.write_sparse6(G, result)
     self.assertEqual(result.getvalue(), b'>>sparse6<<:@\n')
예제 #29
0
 def test_trivial_graph(self):
     G = nx.trivial_graph()
     result = BytesIO()
     nx.write_sparse6(G, result)
     assert result.getvalue() == b'>>sparse6<<:@\n'
예제 #30
0
 def test_empty_graph(self):
     G = nx.empty_graph(5)
     result = BytesIO()
     nx.write_sparse6(G, result)
     self.assertEqual(result.getvalue(), b'>>sparse6<<:D\n')
예제 #31
0
 def test_very_large_empty_graph(self):
     G = nx.empty_graph(258049)
     result = BytesIO()
     nx.write_sparse6(G, result)
     assert result.getvalue() == b'>>sparse6<<:~~???~?@\n'
#     nx.draw(g)
#     plt.show()
# except:
#     pass
# for x in (g.vs):
#     print x;
#

# g.add_edges([(g.vs.select(name=int(row[0]))[0],g.vs.select(name=int(row[1]))[0]) for row in rows ])
try:
    nx.write_gpickle(g,"user user org.pic")
except:
    pass
try:
    nx.write_dot(g,"user user org.dot")
except:
    pass
try:
    nx.write_graphml(g,"user user org.graphml")
except:
    pass
try:
    nx.write_gml(g,"user user org.gml")
except:
    pass
nx.write_edgelist(g,"user user org.edges")
nx.write_sparse6(g,"user user org.sprse")
nx.write_adjlist(g,"user user org.adj")

nx.write_pajek(g,"user user org.net")
예제 #33
0
 def test_no_header(self):
     G = nx.complete_graph(4)
     result = BytesIO()
     nx.write_sparse6(G, result, header=False)
     assert result.getvalue() == b':CcKI\n'
예제 #34
0
 def test_empty_graph(self):
     G = nx.empty_graph(5)
     result = BytesIO()
     nx.write_sparse6(G, result)
     assert result.getvalue() == b">>sparse6<<:D\n"
예제 #35
0
 def test_write_path(self):
     with tempfile.NamedTemporaryFile() as f:
         nx.write_sparse6(nx.null_graph(), f.name)
         self.assertEqual(f.read(), b'>>sparse6<<:?\n')
#     nx.draw(g)
#     plt.show()
# except:
#     pass
# for x in (g.vs):
#     print x;
#

# g.add_edges([(g.vs.select(name=int(row[0]))[0],g.vs.select(name=int(row[1]))[0]) for row in rows ])
try:
    nx.write_gpickle(g, "user user org.pic")
except:
    pass
try:
    nx.write_dot(g, "user user org.dot")
except:
    pass
try:
    nx.write_graphml(g, "user user org.graphml")
except:
    pass
try:
    nx.write_gml(g, "user user org.gml")
except:
    pass
nx.write_edgelist(g, "user user org.edges")
nx.write_sparse6(g, "user user org.sprse")
nx.write_adjlist(g, "user user org.adj")

nx.write_pajek(g, "user user org.net")