Ticket #5793: cliquer-4.patch
File cliquer-4.patch, 7.0 KB (added by , 14 years ago) |
---|
-
sage/graphs/cliquer.pxd
# HG changeset patch # User Nathann Cohen <nathann.cohen@gmail.com> # Date 1248164118 -7200 # Node ID b302bba958c131e1bc1723a6af18d4388fe17cc0 # Parent 20f9a6be873e92343d7d6c502a6a5bf709590e84 - 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 20f9a6be873e -r b302bba958c1 sage/graphs/cliquer.pxd
a b 23 23 24 24 cdef extern from "cliquer/graph.h": 25 25 cdef graph_t * graph_new(int n) 26 cdef void graph_print(graph_t *g) 26 27 -
sage/graphs/cliquer.pyx
diff -r 20f9a6be873e -r b302bba958c1 sage/graphs/cliquer.pyx
a b 7 7 8 8 EXAMPLES:: 9 9 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] 13 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 14 19 cdef graph_t *g 15 20 g=graph_new(graph.order()) 16 21 buf="p edges %d %d" %(graph.order(),graph.size()) … … 28 33 cdef int i 29 34 for i in range(size): 30 35 b.append(list[i]) 31 return b36 return list_composition(b,d_inv) 32 37 33 38 34 39 # computes all the maximum clique of a graph and return its list … … 42 47 43 48 EXAMPLES:: 44 49 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]] 48 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 49 60 cdef graph_t *g 50 61 g=graph_new(graph.order()) 51 62 buf="p edges %d %d" %(graph.order(),graph.size()) … … 66 77 if(list[i]!=-1): 67 78 c.append(list[i]) 68 79 else: 69 b.append( c)80 b.append(list_composition(c,d_inv)) 70 81 c=[] 71 82 return b 72 83 … … 91 102 sage: clique_number(G) 92 103 3 93 104 """ 105 graph=graph.relabel(inplace=False) 94 106 cdef graph_t *g 95 107 g=graph_new(graph.order()) 96 108 buf="p edges %d %d" %(graph.order(),graph.size()) … … 103 115 return sage_clique_number(g) 104 116 105 117 118 def list_composition(a,b): 119 value=[] 120 for i in a: 121 value.append(b[i]) 122 return value 123 106 124 107 -
sage/graphs/graph.py
diff -r 20f9a6be873e -r b302bba958c1 sage/graphs/graph.py
a b 9246 9246 ( algorithm="cliquer" ) but you can also chose the networkx 9247 9247 algorithm instead ( algorithm="networkx" ) 9248 9248 9249 The parameter 'cliques' is an optional list of cliques that can be input if already computed. 9250 ONLY USED BY NetworkX !!! 9249 INPUT : 9250 9251 - ``cliques'' : This parameter is an optional list of cliques that can be input if already computed. 9252 ONLY USED BY NetworkX !!! 9251 9253 9252 9254 Currently only implemented for undirected graphs. Use 9253 9255 to_undirected to convert a digraph to an undirected graph. … … 9283 9285 9284 9286 sage: C=graphs.PetersenGraph() 9285 9287 sage: C.maximum_clique() 9286 [ 6, 8]9288 [7, 9] 9287 9289 """ 9288 9290 from sage.graphs.cliquer import max_clique 9289 9291 return max_clique(self) … … 9316 9318 9317 9319 sage: C=graphs.PetersenGraph() 9318 9320 sage: C.maximum_cliques() 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]]9321 [[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]] 9320 9322 """ 9321 9323 9322 9324 from sage.graphs.cliquer import all_max_clique 9323 9325 return all_max_clique(self) 9324 9326 9325 def cliques_vertex_clique_number(self, vertices=None, with_labels=False, cliques=None):9327 def cliques_vertex_clique_number(self, algorithm="cliquer",vertices=None, with_labels=False, cliques=None): 9326 9328 r""" 9327 9329 Returns a list of sizes of the largest maximal cliques containing 9328 9330 each vertex. (Returns a single value if only one input vertex). … … 9332 9334 9333 9335 INPUT: 9334 9336 9335 9337 - ``algorithm'' - "cliquer" or "networkx" 9338 9336 9339 - ``vertices`` - the vertices to inspect (default is 9337 9340 entire graph) 9341 ONLY USED BY NetworkX !!! 9338 9342 9339 9343 - ``with_labels`` - (boolean) default False returns 9340 9344 list as above True returns a dictionary keyed by vertex labels 9345 ONLY USED BY NetworkX !!! 9341 9346 9342 9347 - ``cliques`` - list of cliques (if already 9343 9348 computed) 9344 9349 ONLY USED BY NetworkX !!! 9345 9350 9346 9351 EXAMPLES:: 9347 9352 … … 9351 9356 sage: E = C.cliques() 9352 9357 sage: E 9353 9358 [[4, 1, 2, 3], [4, 0]] 9354 sage: C.cliques_vertex_clique_number(cliques=E )9359 sage: C.cliques_vertex_clique_number(cliques=E,algorithm="networkx") 9355 9360 [2, 4, 4, 4, 4] 9356 9361 sage: F = graphs.Grid2dGraph(2,3) 9357 sage: F.cliques_vertex_clique_number(with_labels=True )9362 sage: F.cliques_vertex_clique_number(with_labels=True,algorithm="networkx") 9358 9363 {(0, 1): 2, (1, 2): 2, (0, 0): 2, (1, 1): 2, (1, 0): 2, (0, 2): 2} 9359 9364 sage: F.cliques_vertex_clique_number(vertices=[(0, 1), (1, 2)]) 9360 9365 [2, 2] … … 9363 9368 sage: G.cliques_vertex_clique_number() 9364 9369 [3, 3, 3, 3] 9365 9370 """ 9366 import networkx.cliques 9367 return networkx.cliques.node_clique_number(self.networkx_graph(copy=False), vertices, with_labels, cliques) 9371 9372 if algorithm=="cliquer": 9373 from sage.graphs.cliquer import clique_number 9374 if vertices==None: 9375 vertices=self 9376 value=[] 9377 for v in vertices: 9378 value.append(1+clique_number(self.subgraph(self.neighbors(v)))) 9379 self.subgraph(self.neighbors(v)).plot() 9380 return value 9381 elif algorithm=="networkx": 9382 import networkx.cliques 9383 return networkx.cliques.node_clique_number(self.networkx_graph(copy=False), vertices, with_labels, cliques) 9384 else: 9385 raise NotImplementedError("Only 'networkx' and 'cliquer' are supported.") 9386 9368 9387 9369 9388 def cliques_number_of(self, vertices=None, cliques=None, with_labels=False): 9370 9389 """