Ticket #5793: cliquer-4-rebased-sage.4.1.patch

File cliquer-4-rebased-sage.4.1.patch, 7.0 KB (added by rlm, 12 years ago)
  • sage/graphs/cliquer.pxd

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1248164118 -7200
    # Node ID 258d6d888eeeaa7ce869d11ebed73ef5766c5669
    # Parent  62e6ac4e588811442a8a4b21d4fa7678e7d76b69
    - 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
    
    diff -r 62e6ac4e5888 -r 258d6d888eee sage/graphs/cliquer.pxd
    a b  
    2323
    2424cdef extern from "cliquer/graph.h":
    2525     cdef graph_t * graph_new(int n)
     26     cdef void graph_print(graph_t *g)
    2627
  • sage/graphs/cliquer.pyx

    diff -r 62e6ac4e5888 -r 258d6d888eee sage/graphs/cliquer.pyx
    a b  
    77   
    88    EXAMPLES::
    99   
    10     sage: C=graphs.PetersenGraph()
    11     sage: max_clique(C)
    12     [7, 9]
     10          sage: C=graphs.PetersenGraph()
     11          sage: max_clique(C)
     12          [7, 9]
    1313    """
     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
    1419    cdef graph_t *g
    1520    g=graph_new(graph.order())
    1621    buf="p edges %d %d" %(graph.order(),graph.size())
     
    2833    cdef int i
    2934    for i in range(size):
    3035        b.append(list[i])
    31     return b
     36    return list_composition(b,d_inv)
    3237
    3338
    3439# computes all the maximum clique of a graph and return its list
     
    4247   
    4348    EXAMPLES::
    4449   
    45     sage: C=graphs.PetersenGraph()
    46     sage: all_max_clique(C)
    47     [[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]]
     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]]
    4853    """
     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
    4960    cdef graph_t *g
    5061    g=graph_new(graph.order())
    5162    buf="p edges %d %d" %(graph.order(),graph.size())
     
    6677        if(list[i]!=-1):
    6778                c.append(list[i])
    6879        else:
    69                 b.append(c)
     80                b.append(list_composition(c,d_inv))
    7081                c=[]
    7182    return b
    7283
     
    91102    sage: clique_number(G)
    92103    3
    93104    """
     105    graph=graph.relabel(inplace=False)
    94106    cdef graph_t *g
    95107    g=graph_new(graph.order())
    96108    buf="p edges %d %d" %(graph.order(),graph.size())
     
    103115    return sage_clique_number(g)
    104116
    105117
     118def list_composition(a,b):
     119    value=[]
     120    for i in a:
     121        value.append(b[i])
     122    return value
     123   
    106124
    107 
  • sage/graphs/graph.py

    diff -r 62e6ac4e5888 -r 258d6d888eee sage/graphs/graph.py
    a b  
    98489848        ( algorithm="cliquer" ) but you can also chose the networkx
    98499849        algorithm instead ( algorithm="networkx" )
    98509850
    9851         The parameter 'cliques' is an optional list of cliques that can be input if already computed.
    9852         ONLY USED BY NetworkX !!!
     9851        INPUT :
     9852
     9853        - ``cliques'' : This parameter is an optional list of cliques that can be input if already computed.         
     9854                        ONLY USED BY NetworkX !!!
    98539855       
    98549856        Currently only implemented for undirected graphs. Use
    98559857        to_undirected to convert a digraph to an undirected graph.
     
    98859887       
    98869888        sage: C=graphs.PetersenGraph()
    98879889        sage: C.maximum_clique()
    9888         [6, 8]
     9890        [7, 9]
    98899891        """
    98909892        from sage.graphs.cliquer import max_clique
    98919893        return max_clique(self)
     
    99189920       
    99199921        sage: C=graphs.PetersenGraph()
    99209922        sage: C.maximum_cliques()
    9921         [[1, 6], [6, 8], [5, 7], [5, 8], [3, 8], [4, 6], [4, 7], [2, 3], [1, 2], [2, 7], [0, 5], [0, 1]]
     9923        [[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]]
    99229924        """
    99239925
    99249926        from sage.graphs.cliquer import all_max_clique
    99259927        return all_max_clique(self)
    99269928
    9927     def cliques_vertex_clique_number(self, vertices=None, with_labels=False, cliques=None):
     9929    def cliques_vertex_clique_number(self, algorithm="cliquer",vertices=None, with_labels=False, cliques=None):
    99289930        r"""
    99299931        Returns a list of sizes of the largest maximal cliques containing
    99309932        each vertex. (Returns a single value if only one input vertex).
     
    99349936       
    99359937        INPUT:
    99369938       
    9937        
     9939        -  ``algorithm'' - "cliquer" or "networkx"
     9940
    99389941        -  ``vertices`` - the vertices to inspect (default is
    99399942           entire graph)
     9943                        ONLY USED BY NetworkX !!!           
    99409944       
    99419945        -  ``with_labels`` - (boolean) default False returns
    99429946           list as above True returns a dictionary keyed by vertex labels
     9947                        ONLY USED BY NetworkX !!!
    99439948       
    99449949        -  ``cliques`` - list of cliques (if already
    99459950           computed)
    9946        
     9951                        ONLY USED BY NetworkX !!!       
    99479952       
    99489953        EXAMPLES::
    99499954       
     
    99539958            sage: E = C.cliques()
    99549959            sage: E
    99559960            [[4, 1, 2, 3], [4, 0]]
    9956             sage: C.cliques_vertex_clique_number(cliques=E)
     9961            sage: C.cliques_vertex_clique_number(cliques=E,algorithm="networkx")
    99579962            [2, 4, 4, 4, 4]
    99589963            sage: F = graphs.Grid2dGraph(2,3)
    9959             sage: X = F.cliques_vertex_clique_number(with_labels=True)
     9964            sage: X = F.cliques_vertex_clique_number(with_labels=True,algorithm="networkx")
    99609965            sage: for v in sorted(X.iterkeys()):
    99619966            ...    print v, X[v]
    99629967            (0, 0) 2
     
    99729977            sage: G.cliques_vertex_clique_number()
    99739978            [3, 3, 3, 3]
    99749979        """
    9975         import networkx.cliques
    9976         return networkx.cliques.node_clique_number(self.networkx_graph(copy=False), vertices, with_labels, cliques)
     9980
     9981        if algorithm=="cliquer":
     9982            from sage.graphs.cliquer import clique_number
     9983            if vertices==None:
     9984                vertices=self
     9985            value=[]
     9986            for v in vertices:
     9987                value.append(1+clique_number(self.subgraph(self.neighbors(v))))
     9988                self.subgraph(self.neighbors(v)).plot()
     9989            return value
     9990        elif algorithm=="networkx":
     9991            import networkx.cliques
     9992            return networkx.cliques.node_clique_number(self.networkx_graph(copy=False), vertices, with_labels, cliques)
     9993        else:
     9994            raise NotImplementedError("Only 'networkx' and 'cliquer' are supported.")
     9995
    99779996       
    99789997    def cliques_number_of(self, vertices=None, cliques=None, with_labels=False):
    99799998        """