Ticket #5793: trac_5793-cliquer-flattened.patch

File trac_5793-cliquer-flattened.patch, 27.5 KB (added by rlm, 12 years ago)

Flattened patch based on sage-4.1.

  • module_list.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1247858635 -7200
    # Node ID d65a1f4b96c066d81184f19d6f6b25aa630e468d
    # Parent  1f1ae46151f41676c9bef9c20e5c5d55fbb983a6
    Cliquer for SAGE
    * * *
    - ext/cliquer.pxi moved to ext/cliquer.pxd
    - Small fix in function  graph.clique_number for algorithm=networkx
    - One typo
    * * *
    fixes to use different algorithms in graph.clique_number
    doctest in graphs/cliquer.pyx
    bug in the cliquer interface repaired
    And small other things !
    * * *
    - Cliquer now deals with graphs with vertex labels not in 0..n-1
    - Some functions of Graph could use cliquer and now can. ( some functions dealing with MAXIMAL cliques instead of MAXIMUM cliques can not use cliquer, though ! )
    - Some documentations have been rearranged
    - Cliquer's graph_print function is added to cliquer.pxd if needed
    * * *
    Editing for trac #5793
    
    diff -r 1f1ae46151f4 -r d65a1f4b96c0 module_list.py
    a b  
    232232    Extension('sage.graphs.chrompoly',
    233233              sources = ['sage/graphs/chrompoly.pyx']),
    234234
     235    Extension('sage.graphs.cliquer',
     236              sources = ['sage/graphs/cliquer.pyx'],
     237              libraries = ['cliquer']),
     238
    235239    Extension('sage.graphs.graph_fast',
    236240              sources = ['sage/graphs/graph_fast.pyx'],
    237241              libraries = ['gmp']),
  • sage/graphs/all.py

    diff -r 1f1ae46151f4 -r d65a1f4b96c0 sage/graphs/all.py
    a b  
    66import graph_list as graphs_list
    77import sage.graphs.graph_fast
    88import graph_coloring
    9 from graph_database import graph_db_info
    10  No newline at end of file
     9from sage.graphs.cliquer import *
     10from graph_database import graph_db_info
  • new file sage/graphs/cliquer.pxd

    diff -r 1f1ae46151f4 -r d65a1f4b96c0 sage/graphs/cliquer.pxd
    - +  
     1cdef extern from "cliquer/graph.h":
     2    struct graph_t:
     3       pass
     4
     5cdef extern from "cliquer/cliquer.h":
     6    struct clique_options:
     7       pass
     8
     9
     10cdef extern from "cliquer/reorder.h":
     11     cdef int *reorder_by_greedy_coloring(graph_t *g, bool weighted)
     12     cdef int *reorder_by_degree(graph_t *g, bool weighted)
     13
     14cdef extern from "cliquer/cliquer.h":
     15     bool clique_print_time(intlevel, int i, int n, int max, double cputime, double realtime, clique_options *opts)
     16
     17
     18cdef extern from "cliquer/cl.h":
     19     cdef int sage_clique_max(graph_t *g, int ** list)
     20     cdef int sage_all_clique_max(graph_t *g, int ** list)
     21     cdef int sage_clique_number(graph_t *g)
     22     cdef void parse_input(char *str,graph_t *g)
     23
     24cdef extern from "cliquer/graph.h":
     25     cdef graph_t * graph_new(int n)
     26     cdef void graph_print(graph_t *g)
     27
  • new file sage/graphs/cliquer.pyx

    diff -r 1f1ae46151f4 -r d65a1f4b96c0 sage/graphs/cliquer.pyx
    - +  
     1def max_clique(graph):
     2    """
     3    Returns the vertex set of a maximum complete subgraph.
     4   
     5    Currently only implemented for undirected graphs. Use
     6    to_undirected to convert a digraph to an undirected graph.
     7   
     8    EXAMPLES::
     9   
     10          sage: C=graphs.PetersenGraph()
     11          sage: max_clique(C)
     12          [7, 9]
     13    """
     14    graph,d = graph.relabel(inplace=False, return_map=True)
     15    d_inv = {}
     16    for v in d:
     17        d_inv[d[v]] = v
     18
     19    cdef graph_t *g
     20    g=graph_new(graph.order())
     21    buf="p edges %d %d" %(graph.order(),graph.size())
     22    parse_input(buf,g)
     23
     24    for e in graph.edge_iterator():
     25          (u,v,w)=e
     26          buf=' e %d %d' %(u+1,v+1)
     27          parse_input(buf,g)
     28
     29    cdef int* list
     30    cdef int size
     31    size=sage_clique_max(g, &list)
     32    b = []
     33    cdef int i
     34    for i in range(size):
     35        b.append(list[i])
     36    return list_composition(b,d_inv)
     37
     38
     39# computes all the maximum clique of a graph and return its list
     40
     41def all_max_clique(graph):
     42    """
     43    Returns the vertex sets of *ALL* the maximum complete subgraphs.
     44   
     45    Currently only implemented for undirected graphs. Use
     46    to_undirected to convert a digraph to an undirected graph.
     47   
     48    EXAMPLES::
     49   
     50          sage: C=graphs.PetersenGraph()
     51          sage: all_max_clique(C)
     52          [[2, 7], [7, 9], [6, 8], [6, 9], [0, 4], [4, 9], [5, 7], [0, 5], [5, 8], [3, 4], [2, 3], [3, 8], [1, 6], [0, 1], [1, 2]]
     53    """
     54
     55    graph,d = graph.relabel(inplace=False, return_map=True)
     56    d_inv = {}
     57    for v in d:
     58        d_inv[d[v]] = v
     59
     60    cdef graph_t *g
     61    g=graph_new(graph.order())
     62    buf="p edges %d %d" %(graph.order(),graph.size())
     63    parse_input(buf,g)
     64
     65    for e in graph.edge_iterator():
     66          (u,v,w)=e
     67          buf=' e %d %d' %(u+1,v+1)
     68          parse_input(buf,g)
     69
     70    cdef int* list
     71    cdef int size
     72    size=sage_all_clique_max(g, &list)
     73    b = []
     74    c=[]
     75    cdef int i
     76    for i in range(size):
     77        if(list[i]!=-1):
     78                c.append(list[i])
     79        else:
     80                b.append(list_composition(c,d_inv))
     81                c=[]
     82    return b
     83
     84
     85#computes the clique number of a graph
     86
     87def clique_number(graph):
     88    """
     89    Returns the size of the largest clique of the graph (clique
     90    number).
     91   
     92    Currently only implemented for undirected graphs. Use
     93    to_undirected to convert a digraph to an undirected graph.
     94   
     95    EXAMPLES::
     96   
     97        sage: C = Graph('DJ{')
     98        sage: clique_number(C)
     99        4
     100        sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
     101        sage: G.show(figsize=[2,2])
     102        sage: clique_number(G)
     103        3
     104    """
     105    graph=graph.relabel(inplace=False)
     106    cdef graph_t *g
     107    g=graph_new(graph.order())
     108    buf="p edges %d %d" %(graph.order(),graph.size())
     109    parse_input(buf,g)
     110
     111    for e in graph.edge_iterator():
     112          (u,v,w)=e
     113          buf=' e %d %d' %(u+1,v+1)
     114          parse_input(buf,g)
     115    return sage_clique_number(g)
     116
     117
     118def list_composition(a,b):
     119    """
     120    Composes a list ``a`` with a map ``b``.
     121   
     122    EXAMPLE::
     123   
     124        sage: from sage.graphs.cliquer import list_composition
     125        sage: list_composition([1,3,'a'], {'a':'b', 1:2, 2:3, 3:4})
     126        [2, 4, 'b']
     127   
     128    """
     129    value=[]
     130    for i in a:
     131        value.append(b[i])
     132    return value
     133   
     134
  • sage/graphs/graph.py

    diff -r 1f1ae46151f4 -r d65a1f4b96c0 sage/graphs/graph.py
    a b  
    97559755
    97569756    ### Cliques
    97579757   
    9758     def cliques(self):
    9759         """
    9760         Returns the list of maximal cliques. Each maximal clique is
    9761         represented by a list of vertices.
    9762        
    9763         Currently only implemented for undirected graphs. Use
    9764         to_undirected to convert a digraph to an undirected graph.
    9765        
    9766         Maximal cliques are the largest complete subgraphs containing a
    9767         given point. This function is based on Networkx's implementation of
    9768         the Bron and Kerbosch Algorithm, [1].
    9769        
     9758    def cliques_maximal(self):
     9759        """
     9760        Returns the list of all maximal cliques, with each clique represented
     9761        by a list of vertices. A clique is an induced complete subgraph, and a
     9762        maximal clique is one not contained in a larger one.
     9763       
     9764        NOTES:
     9765       
     9766         - Currently only implemented for undirected graphs. Use to_undirected
     9767           to convert a digraph to an undirected graph.
     9768       
     9769        ALGORITHM:
     9770       
     9771         - This function is based on Networkx's implementation of the Bron and
     9772           Kerbosch Algorithm, [1].
     9773           
    97709774        REFERENCE:
    97719775
    97729776        - [1] Coen Bron and Joep Kerbosch. (1973). Algorithm 457:
     
    97769780       
    97779781        EXAMPLES::
    97789782       
    9779             sage: (graphs.ChvatalGraph()).cliques()
     9783            sage: graphs.ChvatalGraph().cliques_maximal()
    97809784            [[0, 1], [0, 4], [0, 6], [0, 9], [2, 1], [2, 3], [2, 6], [2, 8], [3, 4], [3, 7], [3, 9], [5, 1], [5, 4], [5, 10], [5, 11], [7, 1], [7, 8], [7, 11], [8, 4], [8, 10], [10, 6], [10, 9], [11, 6], [11, 9]]
    97819785            sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
    97829786            sage: G.show(figsize=[2,2])
    9783             sage: G.cliques()
     9787            sage: G.cliques_maximal()
    97849788            [[0, 1, 2], [0, 1, 3]]
     9789            sage: C=graphs.PetersenGraph()
     9790            sage: C.cliques_maximal()
     9791            [[0, 1], [0, 4], [0, 5], [2, 1], [2, 3], [2, 7], [3, 4], [3, 8], [6, 1], [6, 8], [6, 9], [7, 5], [7, 9], [8, 5], [9, 4]]
     9792            sage: C = Graph('DJ{')
     9793            sage: C.cliques_maximal()
     9794            [[4, 1, 2, 3], [4, 0]]
     9795
    97859796        """
    97869797        import networkx.cliques
    97879798        return networkx.cliques.find_cliques(self.networkx_graph(copy=False))
    97889799       
    9789     def cliques_get_max_clique_graph(self, name=''):
    9790         """
    9791         Returns a graph constructed with maximal cliques as vertices, and
    9792         edges between maximal cliques with common members in the original
    9793         graph.
    9794        
    9795         Currently only implemented for undirected graphs. Use
    9796         to_undirected to convert a digraph to an undirected graph.
    9797        
    9798         INPUT:
    9799        
    9800        
    9801         -  ``name`` - The name of the new graph.
    9802        
    9803        
    9804         EXAMPLES::
    9805        
    9806             sage: (graphs.ChvatalGraph()).cliques_get_max_clique_graph()
    9807             Graph on 24 vertices
    9808             sage: ((graphs.ChvatalGraph()).cliques_get_max_clique_graph()).show(figsize=[2,2], vertex_size=20, vertex_labels=False)
     9800    def cliques(self):
     9801        """
     9802        (Deprecated) alias for ``cliques_maximal``. See that function for more
     9803        details.
     9804       
     9805        EXAMPLE::
     9806       
     9807            sage: C = Graph('DJ{')
     9808            sage: C.cliques()
     9809            doctest:...: DeprecationWarning: The function 'cliques' has been deprecated. Use 'cliques_maximal' or 'cliques_maximum'.
     9810            [[4, 1, 2, 3], [4, 0]]
     9811
     9812        """
     9813        from sage.misc.misc import deprecation
     9814        deprecation("The function 'cliques' has been deprecated. Use " + \
     9815                    "'cliques_maximal' or 'cliques_maximum'.")
     9816        return self.cliques_maximal()
     9817       
     9818    def cliques_maximum(self):
     9819        """
     9820        Returns the list of all maximum cliques, with each clique represented
     9821        by a list of vertices. A clique is an induced complete subgraph, and a
     9822        maximum clique is one of maximal order.
     9823       
     9824        NOTES:
     9825       
     9826         - Currently only implemented for undirected graphs. Use to_undirected
     9827           to convert a digraph to an undirected graph.
     9828       
     9829        ALGORITHM:
     9830       
     9831         - This function is based on Cliquer, [1].
     9832           
     9833        REFERENCE:
     9834
     9835        - [1] Sampo Niskanen and Patric R. J. Östergård, "Cliquer User's Guide,
     9836          Version 1.0," Communications Laboratory, Helsinki University of
     9837          Technology, Espoo, Finland, Tech. Rep. T48, 2003.
     9838       
     9839        EXAMPLES::
     9840       
     9841            sage: graphs.ChvatalGraph().cliques_maximum()
     9842            [[0, 1], [0, 4], [0, 6], [0, 9], [1, 2], [1, 5], [1, 7], [2, 3], [2, 6], [2, 8], [3, 4], [3, 7], [3, 9], [4, 5], [4, 8], [5, 10], [5, 11], [6, 10], [6, 11], [7, 8], [7, 11], [8, 10], [9, 10], [9, 11]]
    98099843            sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
    98109844            sage: G.show(figsize=[2,2])
    9811             sage: G.cliques_get_max_clique_graph()
    9812             Graph on 2 vertices
    9813             sage: (G.cliques_get_max_clique_graph()).show(figsize=[2,2])
    9814         """
    9815         import networkx.cliques
    9816         return Graph(networkx.cliques.make_max_clique_graph(self.networkx_graph(copy=False), name=name, create_using=networkx.xgraph.XGraph()))
    9817 
    9818     def cliques_get_clique_bipartite(self, **kwds):
    9819         """
    9820         Returns a bipartite graph constructed such that cliques are the
    9821         right vertices and the left vertices are retained from the given
    9822         graph. Right and left vertices are connected if the bottom vertex
    9823         belongs to the clique represented by a top vertex.
    9824        
    9825         Currently only implemented for undirected graphs. Use
    9826         to_undirected to convert a digraph to an undirected graph.
    9827        
    9828         EXAMPLES::
    9829        
    9830             sage: (graphs.ChvatalGraph()).cliques_get_clique_bipartite()
    9831             Bipartite graph on 36 vertices
    9832             sage: ((graphs.ChvatalGraph()).cliques_get_clique_bipartite()).show(figsize=[2,2], vertex_size=20, vertex_labels=False)
    9833             sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
    9834             sage: G.show(figsize=[2,2])
    9835             sage: G.cliques_get_clique_bipartite()
    9836             Bipartite graph on 6 vertices
    9837             sage: (G.cliques_get_clique_bipartite()).show(figsize=[2,2])
    9838         """
    9839         import networkx.cliques
    9840         from bipartite_graph import BipartiteGraph
    9841         return BipartiteGraph(networkx.cliques.make_clique_bipartite(self.networkx_graph(copy=False), **kwds))
    9842 
    9843     def clique_number(self, cliques=None):
    9844         """
    9845         Returns the size of the largest clique of the graph (clique
     9845            sage: G.cliques_maximum()
     9846            [[0, 1, 2], [0, 1, 3]]
     9847            sage: C=graphs.PetersenGraph()
     9848            sage: C.cliques_maximum()
     9849            [[0, 1], [0, 4], [0, 5], [1, 2], [1, 6], [2, 3], [2, 7], [3, 4], [3, 8], [4, 9], [5, 7], [5, 8], [6, 8], [6, 9], [7, 9]]
     9850            sage: C = Graph('DJ{')
     9851            sage: C.cliques_maximum()
     9852            [[1, 2, 3, 4]]
     9853
     9854        """
     9855        from sage.graphs.cliquer import all_max_clique
     9856        return sorted(all_max_clique(self))
     9857
     9858    def clique_maximum(self):
     9859        """
     9860        Returns the vertex set of a maximal order complete subgraph.
     9861       
     9862        NOTE:
     9863       
     9864         - Currently only implemented for undirected graphs. Use to_undirected
     9865           to convert a digraph to an undirected graph.
     9866       
     9867        ALGORITHM:
     9868       
     9869         - This function is based on Cliquer, [1].
     9870           
     9871        REFERENCE:
     9872
     9873        - [1] Sampo Niskanen and Patric R. J. Östergård, "Cliquer User's Guide,
     9874          Version 1.0," Communications Laboratory, Helsinki University of
     9875          Technology, Espoo, Finland, Tech. Rep. T48, 2003.
     9876       
     9877        EXAMPLES::
     9878       
     9879            sage: C=graphs.PetersenGraph()
     9880            sage: C.clique_maximum()
     9881            [7, 9]
     9882            sage: C = Graph('DJ{')
     9883            sage: C.clique_maximum()
     9884            [1, 2, 3, 4]
     9885
     9886        """
     9887        from sage.graphs.cliquer import max_clique
     9888        return max_clique(self)
     9889
     9890    def clique_number(self, algorithm="cliquer", cliques=None):
     9891        """
     9892        Returns the order of the largest clique of the graph (the clique
    98469893        number).
    9847        
    9848         Currently only implemented for undirected graphs. Use
    9849         to_undirected to convert a digraph to an undirected graph.
    9850        
    9851         INPUT:
    9852        
    9853        
    9854         -  ``cliques`` - list of cliques (if already
    9855            computed)
    9856        
     9894
     9895        NOTE:
     9896       
     9897         - Currently only implemented for undirected graphs. Use to_undirected
     9898           to convert a digraph to an undirected graph.
     9899
     9900        INPUT:
     9901       
     9902         - ``algorithm`` - either ``cliquer`` or ``networkx``
     9903       
     9904           - ``cliquer`` - This wraps the C program Cliquer, [1].
     9905       
     9906           - ``networkx`` - This function is based on Networkx's implementation
     9907                of the Bron and Kerbosch Algorithm, [2].
     9908           
     9909         - ``cliques'' - an optional list of cliques that can be input if
     9910              already computed. Ignored unless ``algorithm=='networkx'``.
     9911       
     9912        REFERENCE:
     9913
     9914        - [1] Sampo Niskanen and Patric R. J. Östergård, "Cliquer User's Guide,
     9915          Version 1.0," Communications Laboratory, Helsinki University of
     9916          Technology, Espoo, Finland, Tech. Rep. T48, 2003.
     9917
     9918        - [2] Coen Bron and Joep Kerbosch. (1973). Algorithm 457:
     9919          Finding All Cliques of an Undirected Graph. Commun. ACM. v
     9920          16. n 9.  pages 575-577. ACM Press. [Online] Available:
     9921          http://www.ram.org/computing/rambin/rambin.html
    98579922       
    98589923        EXAMPLES::
    98599924       
    98609925            sage: C = Graph('DJ{')
    98619926            sage: C.clique_number()
    98629927            4
    9863             sage: E = C.cliques()
    9864             sage: E
    9865             [[4, 1, 2, 3], [4, 0]]
    9866             sage: C.clique_number(cliques=E)
    9867             4
    98689928            sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
    98699929            sage: G.show(figsize=[2,2])
    98709930            sage: G.clique_number()
    98719931            3
    9872         """
    9873         import networkx.cliques
    9874         return networkx.cliques.graph_clique_number(self.networkx_graph(copy=False), cliques)
    9875        
    9876     def cliques_vertex_clique_number(self, vertices=None, with_labels=False, cliques=None):
    9877         r"""
    9878         Returns a list of sizes of the largest maximal cliques containing
    9879         each vertex. (Returns a single value if only one input vertex).
    9880        
    9881         Currently only implemented for undirected graphs. Use
    9882         to_undirected to convert a digraph to an undirected graph.
    9883        
    9884         INPUT:
    9885        
    9886        
    9887         -  ``vertices`` - the vertices to inspect (default is
    9888            entire graph)
    9889        
    9890         -  ``with_labels`` - (boolean) default False returns
    9891            list as above True returns a dictionary keyed by vertex labels
    9892        
    9893         -  ``cliques`` - list of cliques (if already
    9894            computed)
    9895        
    9896        
    9897         EXAMPLES::
    9898        
    9899             sage: C = Graph('DJ{')
    9900             sage: C.cliques_vertex_clique_number()
    9901             [2, 4, 4, 4, 4]
    9902             sage: E = C.cliques()
    9903             sage: E
    9904             [[4, 1, 2, 3], [4, 0]]
    9905             sage: C.cliques_vertex_clique_number(cliques=E)
    9906             [2, 4, 4, 4, 4]
    9907             sage: F = graphs.Grid2dGraph(2,3)
    9908             sage: X = F.cliques_vertex_clique_number(with_labels=True)
    9909             sage: for v in sorted(X.iterkeys()):
    9910             ...    print v, X[v]
    9911             (0, 0) 2
    9912             (0, 1) 2
    9913             (0, 2) 2
    9914             (1, 0) 2
    9915             (1, 1) 2
    9916             (1, 2) 2
    9917             sage: F.cliques_vertex_clique_number(vertices=[(0, 1), (1, 2)])
    9918             [2, 2]
    9919             sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
    9920             sage: G.show(figsize=[2,2])
    9921             sage: G.cliques_vertex_clique_number()
    9922             [3, 3, 3, 3]
    9923         """
    9924         import networkx.cliques
    9925         return networkx.cliques.node_clique_number(self.networkx_graph(copy=False), vertices, with_labels, cliques)
    9926        
     9932
     9933        """
     9934        if algorithm=="cliquer":
     9935            from sage.graphs.cliquer import clique_number
     9936            return clique_number(self)       
     9937        elif algorithm=="networkx":
     9938            import networkx.cliques
     9939            return networkx.cliques.graph_clique_number(self.networkx_graph(copy=False),cliques)
     9940        else:
     9941            raise NotImplementedError("Only 'networkx' and 'cliquer' are supported.")
     9942
    99279943    def cliques_number_of(self, vertices=None, cliques=None, with_labels=False):
    99289944        """
    99299945        Returns a list of the number of maximal cliques containing each
    99309946        vertex. (Returns a single value if only one input vertex).
    99319947       
    9932         Currently only implemented for undirected graphs. Use
    9933         to_undirected to convert a digraph to an undirected graph.
    9934        
    9935         INPUT:
    9936        
     9948        NOTES:
     9949       
     9950         - Currently only implemented for undirected graphs. Use to_undirected
     9951           to convert a digraph to an undirected graph.
     9952       
     9953        INPUT:
    99379954       
    99389955        -  ``vertices`` - the vertices to inspect (default is
    99399956           entire graph)
     
    99509967            sage: C = Graph('DJ{')
    99519968            sage: C.cliques_number_of()
    99529969            [1, 1, 1, 1, 2]
    9953             sage: E = C.cliques()
     9970            sage: E = C.cliques_maximal()
    99549971            sage: E
    99559972            [[4, 1, 2, 3], [4, 0]]
    99569973            sage: C.cliques_number_of(cliques=E)
     
    99759992        import networkx.cliques
    99769993        return networkx.cliques.number_of_cliques(self.networkx_graph(copy=False), vertices, cliques, with_labels)
    99779994       
     9995    def cliques_get_max_clique_graph(self, name=''):
     9996        """
     9997        Returns a graph constructed with maximal cliques as vertices, and
     9998        edges between maximal cliques with common members in the original
     9999        graph.
     10000       
     10001        NOTES:
     10002       
     10003         - Currently only implemented for undirected graphs. Use to_undirected
     10004           to convert a digraph to an undirected graph.
     10005       
     10006        INPUT:
     10007       
     10008        -  ``name`` - The name of the new graph.
     10009       
     10010        EXAMPLES::
     10011       
     10012            sage: (graphs.ChvatalGraph()).cliques_get_max_clique_graph()
     10013            Graph on 24 vertices
     10014            sage: ((graphs.ChvatalGraph()).cliques_get_max_clique_graph()).show(figsize=[2,2], vertex_size=20, vertex_labels=False)
     10015            sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
     10016            sage: G.show(figsize=[2,2])
     10017            sage: G.cliques_get_max_clique_graph()
     10018            Graph on 2 vertices
     10019            sage: (G.cliques_get_max_clique_graph()).show(figsize=[2,2])
     10020        """
     10021        import networkx.cliques
     10022        return Graph(networkx.cliques.make_max_clique_graph(self.networkx_graph(copy=False), name=name, create_using=networkx.xgraph.XGraph()))
     10023
     10024    def cliques_get_clique_bipartite(self, **kwds):
     10025        """
     10026        Returns a bipartite graph constructed such that maximal cliques are the
     10027        right vertices and the left vertices are retained from the given
     10028        graph. Right and left vertices are connected if the bottom vertex
     10029        belongs to the clique represented by a top vertex.
     10030       
     10031        NOTES:
     10032       
     10033         - Currently only implemented for undirected graphs. Use to_undirected
     10034           to convert a digraph to an undirected graph.
     10035       
     10036        EXAMPLES::
     10037       
     10038            sage: (graphs.ChvatalGraph()).cliques_get_clique_bipartite()
     10039            Bipartite graph on 36 vertices
     10040            sage: ((graphs.ChvatalGraph()).cliques_get_clique_bipartite()).show(figsize=[2,2], vertex_size=20, vertex_labels=False)
     10041            sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
     10042            sage: G.show(figsize=[2,2])
     10043            sage: G.cliques_get_clique_bipartite()
     10044            Bipartite graph on 6 vertices
     10045            sage: (G.cliques_get_clique_bipartite()).show(figsize=[2,2])
     10046        """
     10047        import networkx.cliques
     10048        from bipartite_graph import BipartiteGraph
     10049        return BipartiteGraph(networkx.cliques.make_clique_bipartite(self.networkx_graph(copy=False), **kwds))
     10050
     10051    def independent_set(self):
     10052        """
     10053        Returns a maximal independent set, which is a set of vertices which
     10054        induces an empty subgraph. Uses Cliquer.
     10055       
     10056        NOTES:
     10057       
     10058         - Currently only implemented for undirected graphs. Use to_undirected
     10059           to convert a digraph to an undirected graph.
     10060       
     10061        EXAMPLES::
     10062       
     10063        sage: C=graphs.PetersenGraph()
     10064        sage: C.independent_set()
     10065        [0, 3, 6, 7]
     10066
     10067        """
     10068        from sage.graphs.cliquer import max_clique
     10069        return max_clique(self.complement())
     10070
     10071    def cliques_vertex_clique_number(self, algorithm="cliquer", vertices=None,
     10072                                     with_labels=False, cliques=None):
     10073        r"""
     10074        Returns a list of sizes of the largest maximal cliques containing
     10075        each vertex. (Returns a single value if only one input vertex).
     10076       
     10077        NOTES:
     10078       
     10079         - Currently only implemented for undirected graphs. Use to_undirected
     10080           to convert a digraph to an undirected graph.
     10081       
     10082        INPUT:
     10083       
     10084         - ``algorithm`` - either ``cliquer`` or ``networkx``
     10085       
     10086           - ``cliquer`` - This wraps the C program Cliquer, [1].
     10087       
     10088           - ``networkx`` - This function is based on Networkx's implementation
     10089                of the Bron and Kerbosch Algorithm, [2].
     10090
     10091        -  ``vertices`` - the vertices to inspect (default is entire graph).
     10092           Ignored unless ``algorithm=='networkx'``.
     10093       
     10094        -  ``with_labels`` - (boolean) default False returns list as above
     10095           True returns a dictionary keyed by vertex labels. Ignored unless
     10096           ``algorithm=='networkx'``.
     10097       
     10098        -  ``cliques`` - list of cliques (if already computed).  Ignored unless
     10099           ``algorithm=='networkx'``.
     10100       
     10101        EXAMPLES::
     10102       
     10103            sage: C = Graph('DJ{')
     10104            sage: C.cliques_vertex_clique_number()
     10105            [2, 4, 4, 4, 4]
     10106            sage: E = C.cliques_maximal()
     10107            sage: E
     10108            [[4, 1, 2, 3], [4, 0]]
     10109            sage: C.cliques_vertex_clique_number(cliques=E,algorithm="networkx")
     10110            [2, 4, 4, 4, 4]
     10111            sage: F = graphs.Grid2dGraph(2,3)
     10112            sage: X = F.cliques_vertex_clique_number(with_labels=True,algorithm="networkx")
     10113            sage: for v in sorted(X.iterkeys()):
     10114            ...    print v, X[v]
     10115            (0, 0) 2
     10116            (0, 1) 2
     10117            (0, 2) 2
     10118            (1, 0) 2
     10119            (1, 1) 2
     10120            (1, 2) 2
     10121            sage: F.cliques_vertex_clique_number(vertices=[(0, 1), (1, 2)])
     10122            [2, 2]
     10123            sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
     10124            sage: G.show(figsize=[2,2])
     10125            sage: G.cliques_vertex_clique_number()
     10126            [3, 3, 3, 3]
     10127
     10128        """
     10129
     10130        if algorithm=="cliquer":
     10131            from sage.graphs.cliquer import clique_number
     10132            if vertices==None:
     10133                vertices=self
     10134            value=[]
     10135            for v in vertices:
     10136                value.append(1+clique_number(self.subgraph(self.neighbors(v))))
     10137                self.subgraph(self.neighbors(v)).plot()
     10138            return value
     10139        elif algorithm=="networkx":
     10140            import networkx.cliques
     10141            return networkx.cliques.node_clique_number(self.networkx_graph(copy=False), vertices, with_labels, cliques)
     10142        else:
     10143            raise NotImplementedError("Only 'networkx' and 'cliquer' are supported.")
     10144
    997810145    def cliques_containing_vertex(self, vertices=None, cliques=None, with_labels=False):
    997910146        """
    998010147        Returns the cliques containing each vertex, represented as a list
    998110148        of lists. (Returns a single list if only one input vertex).
    998210149       
    9983         Currently only implemented for undirected graphs. Use
    9984         to_undirected to convert a digraph to an undirected graph.
    9985        
    9986         INPUT:
    9987        
     10150        NOTE:
     10151       
     10152         - Currently only implemented for undirected graphs. Use to_undirected
     10153           to convert a digraph to an undirected graph.
     10154       
     10155        INPUT:
    998810156       
    998910157        -  ``vertices`` - the vertices to inspect (default is
    999010158           entire graph)
     
    999510163        -  ``cliques`` - list of cliques (if already
    999610164           computed)
    999710165       
    9998        
    999910166        EXAMPLES::
    1000010167       
    1000110168            sage: C = Graph('DJ{')
    1000210169            sage: C.cliques_containing_vertex()
    1000310170            [[[4, 0]], [[4, 1, 2, 3]], [[4, 1, 2, 3]], [[4, 1, 2, 3]], [[4, 1, 2, 3], [4, 0]]]
    10004             sage: E = C.cliques()
     10171            sage: E = C.cliques_maximal()
    1000510172            sage: E
    1000610173            [[4, 1, 2, 3], [4, 0]]
    1000710174            sage: C.cliques_containing_vertex(cliques=E)
     
    1002210189            sage: G.show(figsize=[2,2])
    1002310190            sage: G.cliques_containing_vertex()
    1002410191            [[[0, 1, 2], [0, 1, 3]], [[0, 1, 2], [0, 1, 3]], [[0, 1, 2]], [[0, 1, 3]]]
     10192
    1002510193        """
    1002610194        import networkx.cliques
    1002710195        return networkx.cliques.cliques_containing_node(self.networkx_graph(copy=False), vertices, cliques, with_labels)