Ticket #8923: trac_8923.patch

File trac_8923.patch, 2.0 KB (added by ncohen, 11 years ago)
  • sage/graphs/graph_generators.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1273259757 14400
    # Node ID c752b8bf2a1ed5fce69672ccbea972bf4174adf4
    # Parent  263f1caae32dd7ac94a108e8b279a9872b56f260
    Trac 8923 : graphs.CompleteMultipartiteGraph
    
    diff -r 263f1caae32d -r c752b8bf2a1e sage/graphs/graph_generators.py
    a b  
    8686        - CirculantGraph
    8787        - CompleteGraph
    8888        - CompleteBipartiteGraph
     89        - CompleteMultipartiteGraph
    8990        - CubeGraph
    9091        - FibonacciTree
    9192        - GeneralizedPetersenGraph
     
    229230                    - CirculantGraph
    230231                    - CompleteGraph
    231232                    - CompleteBipartiteGraph
     233                    - CompleteMultipartiteGraph
    232234                    - CubeGraph
    233235                    - FibonacciTree
    234236                    - KneserGraph
     
    28002802        G = networkx.complete_bipartite_graph(n1,n2)
    28012803        return bipartite_graph.BipartiteGraph(G, pos=pos_dict, name="Complete bipartite graph")
    28022804
     2805    def CompleteMultipartiteGraph(self, l):
     2806        r"""
     2807        Returns a complete multipartite graph.
     2808
     2809        INPUT:
     2810
     2811        - ``l`` -- a list of integers : the respective sizes
     2812          of the components.
     2813
     2814        EXAMPLE:
     2815
     2816        A complete tripartite graph with sets of sizes
     2817        `5, 6, 8`::
     2818
     2819            sage: g = graphs.CompleteMultipartiteGraph([5, 6, 8]); g
     2820            Multipartite Graph with set sizes [5, 6, 8]: Graph on 19 vertices
     2821
     2822        It clearly has a chromatic number of 3::
     2823
     2824            sage: g.chromatic_number()
     2825            3
     2826        """
     2827
     2828        from sage.graphs.graph import Graph
     2829        g = Graph()
     2830        for i in l:
     2831            g = g + self.CompleteGraph(i)
     2832           
     2833        g = g.complement()
     2834        g.name("Multipartite Graph with set sizes "+str(l))
     2835
     2836        return g
     2837
    28032838    def CubeGraph(self, n):
    28042839        r"""
    28052840        Returns the hypercube in `n` dimensions.