Ticket #12933: trac_12933.patch

File trac_12933.patch, 3.9 KB (added by ncohen, 9 years ago)
  • sage/graphs/digraph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1336652566 -7200
    # Node ID 190bbe45d83fb5b43a5f9820d13679c543a49729
    # Parent  91a0a028606fd8a49c5246091cf911dd533b3ccd
    Speedup in DiGraph.stronly_connected_components_digraph
    
    diff --git a/sage/graphs/digraph.py b/sage/graphs/digraph.py
    a b  
    29602960
    29612961        if keep_labels:
    29622962            g = DiGraph(multiedges=True, loops=True)
    2963             g.add_vertices(scc_set)
    2964             g.add_edges( set((scc_set[d[u]], scc_set[d[v]], label) for (u,v,label) in self.edges() ) )
     2963            g.add_vertices(range(len(scc)))
     2964
     2965            g.add_edges( set((d[u], d[v], label) for (u,v,label) in self.edges() ) )
     2966            g.relabel(scc_set, inplace = True)
     2967
    29652968        else:
    29662969            g = DiGraph(multiedges=False, loops=False)
    2967             g.add_vertices(scc_set)
    2968             g.add_edges( (scc_set[d[u]], scc_set[d[v]]) for u,v in self.edges(labels=False) )
     2970            g.add_vertices(range(len(scc)))
     2971
     2972            for u,v in self.edges(labels=False):
     2973                g.add_edge(d[u], d[v])
     2974
     2975            g.relabel(scc_set, inplace = True)
    29692976
    29702977        return g
    29712978
     
    29742981        Returns whether the current ``DiGraph`` is strongly connected.
    29752982
    29762983        EXAMPLE:
    2977        
     2984
    29782985        The circuit is obviously strongly connected ::
    29792986
    29802987            sage: g = digraphs.Circuit(5)
  • sage/graphs/graph.py

    diff --git a/sage/graphs/graph.py b/sage/graphs/graph.py
    a b  
    25062506        from sage.graphs.chrompoly import chromatic_polynomial
    25072507        return chromatic_polynomial(self)
    25082508
    2509     def chromatic_number(self, algorithm="DLX"):
     2509    def chromatic_number(self, algorithm="DLX", verbose = 0):
    25102510        r"""
    25112511        Returns the minimal number of colors needed to color the vertices
    25122512        of the graph `G`.
     
    25332533            (see the :mod:`MILP module <sage.numerical.mip>`, or Sage's tutorial
    25342534            on Linear Programming).
    25352535
     2536        - ``verbose`` -- integer (default: ``0``). Sets the level of verbosity
     2537          for the MILP algorithm. Its default value is 0, which means *quiet*.
     2538
    25362539        .. SEEALSO::
    25372540
    25382541            For more functions related to graph coloring, see the
     
    25642567        # package: choose any of GLPK or CBC.
    25652568        elif algorithm == "MILP":
    25662569            from sage.graphs.graph_coloring import vertex_coloring
    2567             return vertex_coloring(self, value_only=True)
     2570            return vertex_coloring(self, value_only=True, verbose = verbose)
    25682571        # another algorithm with bad performance; only good for small graphs
    25692572        elif algorithm == "CP":
    25702573            f = self.chromatic_polynomial()
     
    25752578        else:
    25762579            raise ValueError("The 'algorithm' keyword must be set to either 'DLX', 'MILP' or 'CP'.")
    25772580
    2578     def coloring(self, algorithm="DLX", hex_colors=False):
     2581    def coloring(self, algorithm="DLX", hex_colors=False, verbose = 0):
    25792582        r"""
    25802583        Returns the first (optimal) proper vertex-coloring found.
    25812584       
     
    25952598        - ``hex_colors`` -- (default: ``False``) if ``True``, return a
    25962599          dictionary which can easily be used for plotting.
    25972600
     2601        - ``verbose`` -- integer (default: ``0``). Sets the level of verbosity
     2602          for the MILP algorithm. Its default value is 0, which means *quiet*.
     2603
    25982604        .. SEEALSO::
    25992605
    26002606            For more functions related to graph coloring, see the
     
    26312637        """
    26322638        if algorithm == "MILP":
    26332639            from sage.graphs.graph_coloring import vertex_coloring
    2634             return vertex_coloring(self, hex_colors=hex_colors)
     2640            return vertex_coloring(self, hex_colors=hex_colors, verbose = verbose)
    26352641        elif algorithm == "DLX":
    26362642            from sage.graphs.graph_coloring import first_coloring
    26372643            return first_coloring(self, hex_colors=hex_colors)