Changeset 2975:d68224c5b35a
- Timestamp:
- 01/25/07 00:31:57 (6 years ago)
- Branch:
- default
- Location:
- sage/graphs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sage/graphs/all.py
r2553 r2975 1 1 from graph_generators import graphs 2 2 from graph_database import graphs_database 3 from graph import Graph, DiGraph 3 from graph import Graph, DiGraph, graph -
sage/graphs/graph.py
r2974 r2975 681 681 Returns the graph6 representation of the graph as an ASCII string. 682 682 """ 683 from sage.rings.integer_ring import ZZ 683 684 n = self.order() 684 685 if n > 262143: … … 1280 1281 self.plot(pos, vertex_labels, node_size).show() 1281 1282 1282 class Network(GenericGraph):1283 def graph(data, format=None): 1283 1284 """ 1284 Weighted multigraph: directed or undirected, allowing loops (non-hyper). 1285 Converts several data types into Graph objects. 1286 1287 INPUT: 1288 data -- the data to be converted to a Graph or DiGraph class instance. 1289 format -- the format of data: can be 1290 'graph6' -- if format = 'graph6', then data is assumed to be a graph6 string 1285 1291 """ 1286 pass 1287 1288 ### Hypergraphs and Complexes 1289 1290 class HyperGraph(SageObject): 1291 """ 1292 Edges are simply subsets of the vertex set. 1293 """ 1294 pass 1295 1296 class GenericComplex(SageObject): 1297 pass 1298 1299 class SimplicialComplex(GenericComplex): 1300 pass 1301 1302 class CubicalComplex(GenericComplex): 1303 pass 1304 1292 # TODO: format = 'matrix' 1293 if format == 'graph6' or (format is None and isinstance(data, str)): 1294 if not isinstance(data, str): 1295 raise ValueError, 'If input format is graph6, then data must be a string' 1296 from sage.rings.integer import Integer 1297 data = data.split('\n') 1298 Glist = [] 1299 for s in data: 1300 if s[0] == chr(126): # first four bytes are N 1301 n = ZZ(Integer(ord(s[1])-63).binary() + Integer(ord(s[2])-63).binary() + Integer(ord(s[3])-63).binary(),base=2) 1302 s = s[4:] 1303 else: # only first byte is N 1304 n = ord(s[0]) - 63 1305 s = s[1:] 1306 l = [Integer(ord(i)-63).binary() for i in s] 1307 for i in range(len(l)): 1308 l[i] = '0'* (6-len(l[i])) + l[i] 1309 m = '' 1310 for i in l: 1311 m += i 1312 m = m[:(n*(n-1)/2)] 1313 G = Graph() 1314 k = 0 1315 for i in range(n): 1316 for j in range(i): 1317 if m[k] == '1': 1318 G.add_edge(j,i) 1319 k += 1 1320 Glist.append(G) 1321 if len(Glist) == 1: 1322 return Glist[0] 1323 else: 1324 return Glist 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
Note: See TracChangeset
for help on using the changeset viewer.
