Ticket #5793: cliquer-3.patch

File cliquer-3.patch, 7.3 KB (added by ncohen, 12 years ago)
  • deleted file sage/ext/cliquer.pxd

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1248115108 -7200
    # Node ID 20f9a6be873e92343d7d6c502a6a5bf709590e84
    # Parent  48b4cef43b2e6e2414d7d40fe341578697f72bd7
    fixes to use different algorithms in graph.clique_number
    doctest in graphs/cliquer.pyx
    bug in the cliquer interface repaired
    And small other things !
    
    diff -r 48b4cef43b2e -r 20f9a6be873e sage/ext/cliquer.pxd
    + -  
    1 cdef extern from "cliquer/graph.h":
    2     struct graph_t:
    3        pass
    4 
    5 cdef extern from "cliquer/cliquer.h":
    6     struct clique_options:
    7        pass
    8 
    9 
    10 cdef 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 
    14 cdef 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 
    18 cdef 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 
    24 cdef extern from "cliquer/graph.h":
    25      cdef graph_t * graph_new(int n)
    26 
  • new file sage/graphs/cliquer.pxd

    diff -r 48b4cef43b2e -r 20f9a6be873e 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
  • sage/graphs/cliquer.pyx

    diff -r 48b4cef43b2e -r 20f9a6be873e sage/graphs/cliquer.pyx
    a b  
    1 include '../ext/cliquer.pxd'
    2 
    3 # computes the maximum clique of a graph and return the list of its members
    4 
    51def 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    """
    614    cdef graph_t *g
    715    g=graph_new(graph.order())
    816    buf="p edges %d %d" %(graph.order(),graph.size())
     
    1018
    1119    for e in graph.edge_iterator():
    1220          (u,v,w)=e
    13           buf=' e %d %d' %(u,v)
     21          buf=' e %d %d' %(u+1,v+1)
    1422          parse_input(buf,g)
    1523
    16 
    1724    cdef int* list
    1825    cdef int size
    1926    size=sage_clique_max(g, &list)
     
    2734# computes all the maximum clique of a graph and return its list
    2835
    2936def all_max_clique(graph):
     37    """
     38    Returns the vertex sets of *ALL* the maximum complete subgraphs.
     39   
     40    Currently only implemented for undirected graphs. Use
     41    to_undirected to convert a digraph to an undirected graph.
     42   
     43    EXAMPLES::
     44   
     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]]
     48    """
    3049    cdef graph_t *g
    3150    g=graph_new(graph.order())
    3251    buf="p edges %d %d" %(graph.order(),graph.size())
     
    3453
    3554    for e in graph.edge_iterator():
    3655          (u,v,w)=e
    37           buf=' e %d %d' %(u,v)
     56          buf=' e %d %d' %(u+1,v+1)
    3857          parse_input(buf,g)
    3958
    4059    cdef int* list
     
    5574#computes the clique number of a graph
    5675
    5776def clique_number(graph):
     77    """
     78    Returns the size of the largest clique of the graph (clique
     79    number).
     80   
     81    Currently only implemented for undirected graphs. Use
     82    to_undirected to convert a digraph to an undirected graph.
     83   
     84    EXAMPLES::
     85   
     86    sage: C = Graph('DJ{')
     87    sage: clique_number(C)
     88    4
     89    sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]})
     90    sage: G.show(figsize=[2,2])
     91    sage: clique_number(G)
     92    3
     93    """
    5894    cdef graph_t *g
    5995    g=graph_new(graph.order())
    6096    buf="p edges %d %d" %(graph.order(),graph.size())
     
    6298
    6399    for e in graph.edge_iterator():
    64100          (u,v,w)=e
    65           buf=' e %d %d' %(u,v)
     101          buf=' e %d %d' %(u+1,v+1)
    66102          parse_input(buf,g)
    67103    return sage_clique_number(g)
     104
     105
     106
     107
  • sage/graphs/graph.py

    diff -r 48b4cef43b2e -r 20f9a6be873e sage/graphs/graph.py
    a b  
    92389238        from bipartite_graph import BipartiteGraph
    92399239        return BipartiteGraph(networkx.cliques.make_clique_bipartite(self.networkx_graph(copy=False), **kwds))
    92409240
    9241     def clique_number(self,algorithm="cliquer"):
     9241
     9242    def clique_number(self,algorithm="cliquer",cliques=None):
    92429243        """
    92439244        Returns the size of the largest clique of the graph (clique
    92449245        number). By default, the Cliquer algorithm is used
    92459246        ( algorithm="cliquer" ) but you can also chose the networkx
    92469247        algorithm instead ( algorithm="networkx" )
     9248
     9249        The parameter 'cliques' is an optional list of cliques that can be input if already computed.
     9250        ONLY USED BY NetworkX !!!
    92479251       
    92489252        Currently only implemented for undirected graphs. Use
    92499253        to_undirected to convert a digraph to an undirected graph.
     
    92639267            return clique_number(self)       
    92649268        elif algorithm=="networkx":
    92659269            import networkx.cliques
    9266             return networkx.cliques.graph_clique_number(self.networkx_graph(copy=False))
     9270            return networkx.cliques.graph_clique_number(self.networkx_graph(copy=False),cliques)
    92679271        else:
    92689272            raise NotImplementedError("Only 'networkx' and 'cliquer' are supported.")
    92699273
     9274
    92709275    def maximum_clique(self):
    92719276        """
    92729277        Returns the vertex set of a maximum complete subgraph.
     
    92779282        EXAMPLES::
    92789283       
    92799284        sage: C=graphs.PetersenGraph()
    9280         sage: C.maximum_cliq()
    9281         C.maximum_clique   C.maximum_cliques 
    92829285        sage: C.maximum_clique()
    9283         [7, 9]
     9286        [6, 8]
    92849287        """
    92859288        from sage.graphs.cliquer import max_clique
    92869289        return max_clique(self)
     
    93139316       
    93149317        sage: C=graphs.PetersenGraph()
    93159318        sage: C.maximum_cliques()
    9316        
    9317         [[2, 7],
    9318         [7, 9],
    9319         [6, 8],
    9320         [6, 9],
    9321         [0, 4],
    9322         [4, 9],
    9323         [5, 7],
    9324         [0, 5],
    9325         [5, 8],
    9326         [3, 4],
    9327         [2, 3],
    9328         [3, 8],
    9329         [1, 6],
    9330         [0, 1],
    9331         [1, 2]]
     9319        [[1, 6], [6, 8], [5, 7], [5, 8], [3, 8], [4, 6], [4, 7], [2, 3], [1, 2], [2, 7], [0, 5], [0, 1]]
    93329320        """
    93339321
    93349322        from sage.graphs.cliquer import all_max_clique