Ticket #5793: cliquer-3.patch
File cliquer-3.patch, 7.3 KB (added by , 14 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 pass4 5 cdef extern from "cliquer/cliquer.h":6 struct clique_options:7 pass8 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
- + 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 -
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 members4 5 1 def 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 """ 6 14 cdef graph_t *g 7 15 g=graph_new(graph.order()) 8 16 buf="p edges %d %d" %(graph.order(),graph.size()) … … 10 18 11 19 for e in graph.edge_iterator(): 12 20 (u,v,w)=e 13 buf=' e %d %d' %(u ,v)21 buf=' e %d %d' %(u+1,v+1) 14 22 parse_input(buf,g) 15 23 16 17 24 cdef int* list 18 25 cdef int size 19 26 size=sage_clique_max(g, &list) … … 27 34 # computes all the maximum clique of a graph and return its list 28 35 29 36 def 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 """ 30 49 cdef graph_t *g 31 50 g=graph_new(graph.order()) 32 51 buf="p edges %d %d" %(graph.order(),graph.size()) … … 34 53 35 54 for e in graph.edge_iterator(): 36 55 (u,v,w)=e 37 buf=' e %d %d' %(u ,v)56 buf=' e %d %d' %(u+1,v+1) 38 57 parse_input(buf,g) 39 58 40 59 cdef int* list … … 55 74 #computes the clique number of a graph 56 75 57 76 def 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 """ 58 94 cdef graph_t *g 59 95 g=graph_new(graph.order()) 60 96 buf="p edges %d %d" %(graph.order(),graph.size()) … … 62 98 63 99 for e in graph.edge_iterator(): 64 100 (u,v,w)=e 65 buf=' e %d %d' %(u ,v)101 buf=' e %d %d' %(u+1,v+1) 66 102 parse_input(buf,g) 67 103 return sage_clique_number(g) 104 105 106 107 -
sage/graphs/graph.py
diff -r 48b4cef43b2e -r 20f9a6be873e sage/graphs/graph.py
a b 9238 9238 from bipartite_graph import BipartiteGraph 9239 9239 return BipartiteGraph(networkx.cliques.make_clique_bipartite(self.networkx_graph(copy=False), **kwds)) 9240 9240 9241 def clique_number(self,algorithm="cliquer"): 9241 9242 def clique_number(self,algorithm="cliquer",cliques=None): 9242 9243 """ 9243 9244 Returns the size of the largest clique of the graph (clique 9244 9245 number). By default, the Cliquer algorithm is used 9245 9246 ( algorithm="cliquer" ) but you can also chose the networkx 9246 9247 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 !!! 9247 9251 9248 9252 Currently only implemented for undirected graphs. Use 9249 9253 to_undirected to convert a digraph to an undirected graph. … … 9263 9267 return clique_number(self) 9264 9268 elif algorithm=="networkx": 9265 9269 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) 9267 9271 else: 9268 9272 raise NotImplementedError("Only 'networkx' and 'cliquer' are supported.") 9269 9273 9274 9270 9275 def maximum_clique(self): 9271 9276 """ 9272 9277 Returns the vertex set of a maximum complete subgraph. … … 9277 9282 EXAMPLES:: 9278 9283 9279 9284 sage: C=graphs.PetersenGraph() 9280 sage: C.maximum_cliq()9281 C.maximum_clique C.maximum_cliques9282 9285 sage: C.maximum_clique() 9283 [ 7, 9]9286 [6, 8] 9284 9287 """ 9285 9288 from sage.graphs.cliquer import max_clique 9286 9289 return max_clique(self) … … 9313 9316 9314 9317 sage: C=graphs.PetersenGraph() 9315 9318 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]] 9332 9320 """ 9333 9321 9334 9322 from sage.graphs.cliquer import all_max_clique