# 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
|
|
2960 | 2960 | |
2961 | 2961 | if keep_labels: |
2962 | 2962 | 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 | |
2965 | 2968 | else: |
2966 | 2969 | 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) |
2969 | 2976 | |
2970 | 2977 | return g |
2971 | 2978 | |
… |
… |
|
2974 | 2981 | Returns whether the current ``DiGraph`` is strongly connected. |
2975 | 2982 | |
2976 | 2983 | EXAMPLE: |
2977 | | |
| 2984 | |
2978 | 2985 | The circuit is obviously strongly connected :: |
2979 | 2986 | |
2980 | 2987 | sage: g = digraphs.Circuit(5) |
diff --git a/sage/graphs/graph.py b/sage/graphs/graph.py
a
|
b
|
|
2506 | 2506 | from sage.graphs.chrompoly import chromatic_polynomial |
2507 | 2507 | return chromatic_polynomial(self) |
2508 | 2508 | |
2509 | | def chromatic_number(self, algorithm="DLX"): |
| 2509 | def chromatic_number(self, algorithm="DLX", verbose = 0): |
2510 | 2510 | r""" |
2511 | 2511 | Returns the minimal number of colors needed to color the vertices |
2512 | 2512 | of the graph `G`. |
… |
… |
|
2533 | 2533 | (see the :mod:`MILP module <sage.numerical.mip>`, or Sage's tutorial |
2534 | 2534 | on Linear Programming). |
2535 | 2535 | |
| 2536 | - ``verbose`` -- integer (default: ``0``). Sets the level of verbosity |
| 2537 | for the MILP algorithm. Its default value is 0, which means *quiet*. |
| 2538 | |
2536 | 2539 | .. SEEALSO:: |
2537 | 2540 | |
2538 | 2541 | For more functions related to graph coloring, see the |
… |
… |
|
2564 | 2567 | # package: choose any of GLPK or CBC. |
2565 | 2568 | elif algorithm == "MILP": |
2566 | 2569 | 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) |
2568 | 2571 | # another algorithm with bad performance; only good for small graphs |
2569 | 2572 | elif algorithm == "CP": |
2570 | 2573 | f = self.chromatic_polynomial() |
… |
… |
|
2575 | 2578 | else: |
2576 | 2579 | raise ValueError("The 'algorithm' keyword must be set to either 'DLX', 'MILP' or 'CP'.") |
2577 | 2580 | |
2578 | | def coloring(self, algorithm="DLX", hex_colors=False): |
| 2581 | def coloring(self, algorithm="DLX", hex_colors=False, verbose = 0): |
2579 | 2582 | r""" |
2580 | 2583 | Returns the first (optimal) proper vertex-coloring found. |
2581 | 2584 | |
… |
… |
|
2595 | 2598 | - ``hex_colors`` -- (default: ``False``) if ``True``, return a |
2596 | 2599 | dictionary which can easily be used for plotting. |
2597 | 2600 | |
| 2601 | - ``verbose`` -- integer (default: ``0``). Sets the level of verbosity |
| 2602 | for the MILP algorithm. Its default value is 0, which means *quiet*. |
| 2603 | |
2598 | 2604 | .. SEEALSO:: |
2599 | 2605 | |
2600 | 2606 | For more functions related to graph coloring, see the |
… |
… |
|
2631 | 2637 | """ |
2632 | 2638 | if algorithm == "MILP": |
2633 | 2639 | 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) |
2635 | 2641 | elif algorithm == "DLX": |
2636 | 2642 | from sage.graphs.graph_coloring import first_coloring |
2637 | 2643 | return first_coloring(self, hex_colors=hex_colors) |