Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 19204
1
r"""
2
An improved Graph class
3
=======================
4
5
The ``graph_improved`` module defines
6
the ``GraphImproved`` class, which represents
7
a Graph and some of its computed properties, such as its clique polynomial.
8
9
AUTHORS:
10
11
- Paul Leopardi (2016-10-05): initial version
12
13
"""
14
#*****************************************************************************
15
# Copyright (C) 2016-17 Paul Leopardi [email protected]
16
#
17
# Distributed under the terms of the GNU General Public License (GPL)
18
# as published by the Free Software Foundation; either version 2 of
19
# the License, or (at your option) any later version.
20
# http://www.gnu.org/licenses/
21
#*****************************************************************************
22
23
from sage.graphs.graph import Graph
24
25
from boolean_cayley_graphs.saveable import Saveable
26
27
28
class GraphImproved(Graph, Saveable):
29
r"""
30
A Graph and some of its computed properties, such as its clique polynomial.
31
32
The constructor is based on the ``Graph`` constructor and takes the same arguments.
33
34
EXAMPLES:
35
36
::
37
38
sage: P = graphs.PetersenGraph()
39
sage: P.clique_polynomial()
40
15*t^2 + 10*t + 1
41
sage: from boolean_cayley_graphs.graph_improved import GraphImproved
42
sage: PI = GraphImproved(P)
43
sage: PI.stored_clique_polynomial
44
15*t^2 + 10*t + 1
45
sage: dir = tmp_dir()
46
sage: PI.save_mangled('PetersenGraph', dir=dir)
47
sage: LPI = GraphImproved.load_mangled('PetersenGraph', dir=dir)
48
sage: LPI.stored_clique_polynomial
49
15*t^2 + 10*t + 1
50
sage: GraphImproved.remove_mangled('PetersenGraph', dir=dir)
51
sage: os.rmdir(dir)
52
53
TESTS:
54
55
::
56
57
sage: from boolean_cayley_graphs.graph_improved import GraphImproved
58
sage: P = graphs.PetersenGraph()
59
sage: PI = GraphImproved(P)
60
sage: print(PI)
61
Petersen graph
62
63
sage: from boolean_cayley_graphs.graph_improved import GraphImproved
64
sage: P = graphs.PetersenGraph()
65
sage: PI = GraphImproved(P)
66
sage: latex(PI)
67
\begin{tikzpicture}
68
\definecolor{cv0}{rgb}{0.0,0.0,0.0}
69
\definecolor{cfv0}{rgb}{1.0,1.0,1.0}
70
\definecolor{clv0}{rgb}{0.0,0.0,0.0}
71
...
72
\definecolor{cv6v8}{rgb}{0.0,0.0,0.0}
73
\definecolor{cv6v9}{rgb}{0.0,0.0,0.0}
74
\definecolor{cv7v9}{rgb}{0.0,0.0,0.0}
75
%
76
...
77
%
78
\Edge[lw=0.1cm,style={color=cv0v1,},](v0)(v1)
79
\Edge[lw=0.1cm,style={color=cv0v4,},](v0)(v4)
80
\Edge[lw=0.1cm,style={color=cv0v5,},](v0)(v5)
81
...
82
\Edge[lw=0.1cm,style={color=cv6v8,},](v6)(v8)
83
\Edge[lw=0.1cm,style={color=cv6v9,},](v6)(v9)
84
\Edge[lw=0.1cm,style={color=cv7v9,},](v7)(v9)
85
%
86
\end{tikzpicture}
87
"""
88
89
90
def __init__(self, graph=None, **kwargs):
91
r"""
92
Constructor, based on the ``Graph`` constructor.
93
94
TESTS:
95
96
::
97
98
sage: c = graphs.ClebschGraph()
99
sage: c.clique_polynomial()
100
40*t^2 + 16*t + 1
101
sage: from boolean_cayley_graphs.graph_improved import GraphImproved
102
sage: ci = GraphImproved(c)
103
sage: ci.stored_clique_polynomial
104
40*t^2 + 16*t + 1
105
"""
106
Graph.__init__(self, graph, **kwargs)
107
self.stored_clique_polynomial = self.clique_polynomial()
108
109