Changeset 8734:d84d24c8d5bb for sage/graphs/graph.py
- Timestamp:
- 02/06/08 17:48:21 (5 years ago)
- Branch:
- default
- File:
-
- 1 edited
-
sage/graphs/graph.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/graphs/graph.py
r8732 r8734 4972 4972 return result 4973 4973 4974 def genus(self ):4974 def genus(self,set_embedding=True, minimal=True): 4975 4975 """ 4976 4976 Returns the minimal genus of the graph. The genus of a compact … … 4995 4995 if not self.is_connected(): 4996 4996 raise TypeError("Graph must be connected to use Euler's Formula to compute minimal genus.") 4997 from sage.rings.infinity import Infinity4998 4997 from sage.combinat.all import CyclicPermutationsOfPartition 4999 4998 from sage.graphs.graph_genus1 import trace_faces, nice_copy … … 5004 5003 edges = len(graph.edges()) 5005 5004 5006 # Construct a list of all rotation systems for graph 5007 part = [] 5008 for vertex in graph.vertices(): 5009 part.append(graph.neighbors(vertex)) 5010 5011 all_perms = [] 5012 for p in CyclicPermutationsOfPartition(part): 5013 all_perms.append(p) 5014 5015 max_faces = -Infinity 5016 for p in all_perms: 5017 print p 5018 t = trace_faces(graph, p) 5019 print t 5020 faces = len(t) 5021 if faces > max_faces: 5022 max_faces = faces 5005 if not minimal: 5006 if not hasattr(graph,'__embedding__'): 5007 raise NoEmbeddingDefinedDipfuckError 5008 p = graph.__embedding__.values() 5009 max_faces = len(trace_faces(graph, p)) 5010 else: 5011 # Construct an intitial combinatorial embedding for graph 5012 part = [] 5013 for vertex in graph.vertices(): 5014 part.append(graph.neighbors(vertex)) 5015 5016 # Iterate through all embeddings 5017 max_faces = -1 5018 min_embedding = [] 5019 for p in CyclicPermutationsOfPartition(part): 5020 t = trace_faces(graph, p) 5021 faces = len(t) 5022 if faces > max_faces: 5023 max_faces = faces 5024 min_embedding = p 5025 if set_embedding: 5026 # Make dict of node labels embedding 5027 comb_emb = {} 5028 labels = graph.vertices() 5029 for i in range(len(min_embedding)): 5030 comb_emb[labels[i]] = min_embedding[i] 5031 self.__embedding__ = comb_emb 5023 5032 return (2-verts+edges-max_faces)/2 5024 5033
Note: See TracChangeset
for help on using the changeset viewer.
