Ticket #5793: cliquer-4-rebased-sage.4.1.patch
File cliquer-4-rebased-sage.4.1.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 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 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 62e6ac4e5888 -r 258d6d888eee 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 62e6ac4e5888 -r 258d6d888eee sage/graphs/graph.py
a b 9848 9848 ( algorithm="cliquer" ) but you can also chose the networkx 9849 9849 algorithm instead ( algorithm="networkx" ) 9850 9850 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 !!! 9853 9855 9854 9856 Currently only implemented for undirected graphs. Use 9855 9857 to_undirected to convert a digraph to an undirected graph. … … 9885 9887 9886 9888 sage: C=graphs.PetersenGraph() 9887 9889 sage: C.maximum_clique() 9888 [ 6, 8]9890 [7, 9] 9889 9891 """ 9890 9892 from sage.graphs.cliquer import max_clique 9891 9893 return max_clique(self) … … 9918 9920 9919 9921 sage: C=graphs.PetersenGraph() 9920 9922 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]] 9922 9924 """ 9923 9925 9924 9926 from sage.graphs.cliquer import all_max_clique 9925 9927 return all_max_clique(self) 9926 9928 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): 9928 9930 r""" 9929 9931 Returns a list of sizes of the largest maximal cliques containing 9930 9932 each vertex. (Returns a single value if only one input vertex). … … 9934 9936 9935 9937 INPUT: 9936 9938 9937 9939 - ``algorithm'' - "cliquer" or "networkx" 9940 9938 9941 - ``vertices`` - the vertices to inspect (default is 9939 9942 entire graph) 9943 ONLY USED BY NetworkX !!! 9940 9944 9941 9945 - ``with_labels`` - (boolean) default False returns 9942 9946 list as above True returns a dictionary keyed by vertex labels 9947 ONLY USED BY NetworkX !!! 9943 9948 9944 9949 - ``cliques`` - list of cliques (if already 9945 9950 computed) 9946 9951 ONLY USED BY NetworkX !!! 9947 9952 9948 9953 EXAMPLES:: 9949 9954 … … 9953 9958 sage: E = C.cliques() 9954 9959 sage: E 9955 9960 [[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") 9957 9962 [2, 4, 4, 4, 4] 9958 9963 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") 9960 9965 sage: for v in sorted(X.iterkeys()): 9961 9966 ... print v, X[v] 9962 9967 (0, 0) 2 … … 9972 9977 sage: G.cliques_vertex_clique_number() 9973 9978 [3, 3, 3, 3] 9974 9979 """ 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 9977 9996 9978 9997 def cliques_number_of(self, vertices=None, cliques=None, with_labels=False): 9979 9998 """