Ignore:
Timestamp:
02/06/08 17:48:21 (5 years ago)
Author:
Emily Kirkman
Branch:
default
Message:

genus improvements and bm planarity

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/graphs/graph.py

    r8732 r8734  
    49724972        return result 
    49734973 
    4974     def genus(self): 
     4974    def genus(self,set_embedding=True, minimal=True): 
    49754975        """ 
    49764976        Returns the minimal genus of the graph.  The genus of a compact  
     
    49954995        if not self.is_connected(): 
    49964996            raise TypeError("Graph must be connected to use Euler's Formula to compute minimal genus.") 
    4997         from sage.rings.infinity import Infinity 
    49984997        from sage.combinat.all import CyclicPermutationsOfPartition 
    49994998        from sage.graphs.graph_genus1 import trace_faces, nice_copy 
     
    50045003        edges = len(graph.edges()) 
    50055004         
    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 
    50235032        return (2-verts+edges-max_faces)/2 
    50245033 
Note: See TracChangeset for help on using the changeset viewer.