Ticket #8513: trac_8513_graph_theory_documentation-abm.patch
File trac_8513_graph_theory_documentation-abm.patch, 8.4 KB (added by , 11 years ago) |
---|
-
doc/en/reference/graphs.rst
# HG changeset patch # User Alexandre Blondin Masse < alexandre.blondin.masse at gmail.com> # Date 1269287092 -3600 # Node ID fb26ae3b55b2a1491727483c8d1ed5ed845f760c # Parent 2b6f82c8b0075babce925e6f0cc90a792c7b8515 #8513 Including the files digraph.py and generic_graph.py in the doctree. Also removes all the warnings displayed when the documentation is generated by Sphinx. diff --git a/doc/en/reference/graphs.rst b/doc/en/reference/graphs.rst
a b Graph Theory 5 5 :maxdepth: 2 6 6 7 7 sage/graphs/cliquer 8 sage/graphs/digraph 9 sage/graphs/generic_graph 8 10 sage/graphs/graph 9 11 sage/graphs/graph_coloring 10 12 sage/graphs/graph_generators -
sage/graphs/generic_graph.py
diff --git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
a b class GenericGraph(GenericGraph_pyx): 1949 1949 1950 1950 INPUT: 1951 1951 1952 - ``root_vertex`` -- integer (default: the first vertex) This is the vertex 1953 that will be used as root for all spanning out-trees if the graph 1954 is a directed graph. 1955 This argument is ignored if the graph is not a digraph. 1956 1952 - ``root_vertex`` -- integer (default: the first vertex) This is 1953 the vertex that will be used as root for all spanning out-trees 1954 if the graph is a directed graph. This argument is ignored if 1955 the graph is not a digraph. 1956 1957 1957 1958 REFERENCES: 1958 1959 1959 -[1] http://mathworld.wolfram.com/MatrixTreeTheorem.html1960 1961 - [2] Lih-Hsing Hsu, Cheng-Kuan Lin, "Graph Theory and Interconnection1962 Networks" 1960 [1] http://mathworld.wolfram.com/MatrixTreeTheorem.html 1961 1962 [2] Lih-Hsing Hsu, Cheng-Kuan Lin, "Graph Theory and Interconnection Networks" 1963 1963 1964 1964 1965 AUTHORS: 1965 1966 1966 1967 - Anders Jonsson (2009-10-10) 1967 1968 1969 1968 1970 EXAMPLES:: 1969 1971 1970 1972 sage: G = graphs.PetersenGraph() … … class GenericGraph(GenericGraph_pyx): 2014 2016 possible maximum outdegree of the current graph. 2015 2017 2016 2018 Given a Graph `G`, is is polynomial to compute an orientation 2017 `D` of the edges of `G` such that the maximum out-degree in `D`2018 2019 `D` of the edges of `G` such that the maximum out-degree in 2020 `D` is minimized. This problem, though, is NP-complete in the 2019 2021 weighted case [AMOZ06]_. 2020 2022 2021 2023 INPUT: 2022 2024 2023 2025 - ``use_edge_labels`` (boolean) 2024 2026 2025 2026 2027 2028 2029 - When set to ``False`` (default), gives a weight of 12030 to all the edges. 2027 - When set to ``True``, uses edge labels as weights to 2028 compute the orientation and assumes a weight of `1` 2029 when there is no value available for a given edge. 2030 - When set to ``False`` (default), gives a weight of 1 2031 to all the edges. 2032 2031 2033 2032 2034 EXAMPLE: 2033 2035 2034 2036 Given a complete bipartite graph `K_{n,m}`, the maximum out-degree 2035 of an optimal orientation is 2036 `\left\lceil \frac {nm} {n+m}\right\rceil`:: 2037 of an optimal orientation is `\left\lceil \frac {nm} {n+m}\right\rceil`:: 2037 2038 2038 2039 sage: g = graphs.CompleteBipartiteGraph(3,4) 2039 2040 sage: o = g.minimum_outdegree_orientation() # optional - requires GLPK or CBC 2040 2041 sage: max(o.out_degree()) == ceil((4*3)/(3+4)) # optional - requires GLPK or CBC 2041 2042 True 2042 2043 2043 2044 2045 2044 REFERENCES: 2046 2045 2047 2046 .. [AMOZ06] Asahiro, Y. and Miyano, E. and Ono, H. and Zenmyo, K. … … class GenericGraph(GenericGraph_pyx): 2049 2048 Proceedings of the 12th Computing: The Australasian Theroy Symposium 2050 2049 Volume 51, page 20 2051 2050 Australian Computer Society, Inc. 2006 2052 2053 2051 """ 2054 2052 2055 2053 if self.is_directed(): … … class GenericGraph(GenericGraph_pyx): 7815 7813 Returns the Wiener index of the graph. 7816 7814 7817 7815 The Wiener index of a graph `G` can be defined in two equivalent 7818 ways [ KRG96]_:7816 ways [1] : 7819 7817 7820 7818 - `W(G) = \frac 1 2 \sum_{u,v\in G} d(u,v)` where `d(u,v)` denotes the distance between 7821 7819 vertices `u` and `v`. … … class GenericGraph(GenericGraph_pyx): 7827 7825 7828 7826 EXAMPLE: 7829 7827 7830 From [ GYLL93]_, cited in [KRG96]_::7828 From [2], cited in [1]:: 7831 7829 7832 7830 sage: g=graphs.PathGraph(10) 7833 7831 sage: w=lambda x: (x*(x*x -1)/6) … … class GenericGraph(GenericGraph_pyx): 7836 7834 7837 7835 REFERENCE: 7838 7836 7839 .. [KRG96] Klavzar S., Rajapakse A., Gutman I. (1996). The Szeged and 7840 the Wiener index of graphs . 7841 Applied Mathematics Letters, 9 (5), pp. 45-49. 7837 [1] Klavzar S., Rajapakse A., Gutman I. (1996). The Szeged and the 7838 Wiener index of graphs. Applied Mathematics Letters, 9 (5), pp. 45-49. 7839 7840 [2] I Gutman, YN Yeh, SL Lee, YL Luo (1993), Some recent results in 7841 the theory of the Wiener number. INDIAN JOURNAL OF CHEMISTRY SECTION A 7842 PUBLICATIONS & INFORMATION DIRECTORATE, CSIR 7843 """ 7844 7845 return sum([sum(v.itervalues()) for v in self.distance_all_pairs().itervalues()])/2 7846 7847 def average_distance(self): 7848 r""" 7849 Returns the average distance between vertices of the graph. 7850 7851 Formally, for a graph `G` this value is equal to 7852 `\frac 1 {n(n-1)} \sum_{u,v\in G} d(u,v)` where `d(u,v)` 7853 denotes the distance between vertices `u` and `v` and `n` 7854 is the number of vertices in `G`. 7855 7856 EXAMPLE: 7857 7858 From [GYLL93]_:: 7859 7860 sage: g=graphs.PathGraph(10) 7861 sage: w=lambda x: (x*(x*x -1)/6)/(x*(x-1)/2) 7862 sage: g.average_distance()==w(10) 7863 True 7864 7865 7866 REFERENCE: 7842 7867 7843 7868 .. [GYLL93] I Gutman, YN Yeh, SL Lee, YL Luo (1993), 7844 7869 Some recent results in the theory of the Wiener number. 7845 7870 INDIAN JOURNAL OF CHEMISTRY SECTION A 7846 7871 PUBLICATIONS & INFORMATION DIRECTORATE, CSIR 7847 7848 """7849 7850 return sum([sum(v.itervalues()) for v in self.distance_all_pairs().itervalues()])/27851 7852 def average_distance(self):7853 r"""7854 Returns the average distance between vertices of the graph.7855 7856 Formally, for a graph `G` this value is equal to7857 `\frac 1 {n(n-1)} \sum_{u,v\in G} d(u,v)` where `d(u,v)`7858 denotes the distance between vertices `u` and `v` and `n`7859 is the number of vertices in `G`.7860 7861 EXAMPLE:7862 7863 From [GYLL93]_::7864 7865 sage: g=graphs.PathGraph(10)7866 sage: w=lambda x: (x*(x*x -1)/6)/(x*(x-1)/2)7867 sage: g.average_distance()==w(10)7868 True7869 7870 7871 REFERENCE:7872 7873 .. [GYLL93] I Gutman, YN Yeh, SL Lee, YL Luo (1993),7874 Some recent results in the theory of the Wiener number.7875 INDIAN JOURNAL OF CHEMISTRY SECTION A7876 PUBLICATIONS & INFORMATION DIRECTORATE, CSIR7877 7872 7878 7873 """ 7879 7874 … … class GenericGraph(GenericGraph_pyx): 7886 7881 For any `uv\in E(G)`, let 7887 7882 `N_u(uv) = \{w\in G:d(u,w)<d(v,w)\}, n_u(uv)=|N_u(uv)|` 7888 7883 7889 The Szeged index of a graph is then defined as [ KRG96]_:7884 The Szeged index of a graph is then defined as [1]: 7890 7885 `\sum_{uv \in E(G)}n_u(uv)\times n_v(uv)` 7891 7886 7892 7887 EXAMPLE: 7893 7888 7894 True for any connected graph [ KRG96]_::7889 True for any connected graph [1]:: 7895 7890 7896 7891 sage: g=graphs.PetersenGraph() 7897 7892 sage: g.wiener_index()<= g.szeged_index() 7898 7893 True 7899 7894 7900 True for all trees [ KRG96]_::7895 True for all trees [1]:: 7901 7896 7902 7897 sage: g=Graph() 7903 7898 sage: g.add_edges(graphs.CubeGraph(5).min_spanning_tree()) … … class GenericGraph(GenericGraph_pyx): 7907 7902 7908 7903 REFERENCE: 7909 7904 7910 .. [KRG96] Klavzar S., Rajapakse A., Gutman I. (1996). The Szeged and 7911 the Wiener index of graphs . 7912 Applied Mathematics Letters, 9 (5), pp. 45-49. 7913 7905 [1] Klavzar S., Rajapakse A., Gutman I. (1996). The Szeged and the 7906 Wiener index of graphs. Applied Mathematics Letters, 9 (5), pp. 45-49. 7914 7907 """ 7915 7908 distances=self.distance_all_pairs() 7916 7909 s=0