The Conley-Morse Graphs Software
dotgraph.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file dotgraph.h
4///
5/// Writing a graph in the "dot" format.
6/// This file contains the definition of a function
7/// which writes a Conley-Morse graph to an output stream
8/// in the format suitable for plotting by the "dot" program.
9///
10/// @author Pawel Pilarczyk
11///
12/////////////////////////////////////////////////////////////////////////////
13
14// Copyright (C) 1997-2014 by Pawel Pilarczyk.
15//
16// This file is part of my research software package. This is free software:
17// you can redistribute it and/or modify it under the terms of the GNU
18// General Public License as published by the Free Software Foundation,
19// either version 3 of the License, or (at your option) any later version.
20//
21// This software is distributed in the hope that it will be useful,
22// but WITHOUT ANY WARRANTY; without even the implied warranty of
23// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24// GNU General Public License for more details.
25//
26// You should have received a copy of the GNU General Public License
27// along with this software; see the file "license.txt". If not,
28// please, see <https://www.gnu.org/licenses/>.
29
30// Started on February 11, 2008. Last revision: July 2, 2012.
31
32
33#ifndef _CMGRAPHS_DOTGRAPH_H_
34#define _CMGRAPHS_DOTGRAPH_H_
35
36
37// include some standard C++ header files
38#include <string>
39#include <ostream>
40#include <cmath>
41#include <vector>
42
43// include selected header files from the CHomP library
44#include "chomp/system/config.h"
45#include "chomp/system/textfile.h"
46#include "chomp/cubes/cube.h"
47
48// include local header files
49#include "config.h"
50#include "typedefs.h"
51#include "typedyns.h"
52#include "eigenval.h"
53
54
55// --------------------------------------------------
56// ------ encoding graphs for the dot program -------
57// --------------------------------------------------
58
59/// Writes the given Conley-Morse graph to the output stream
60/// in the format for the 'dot' program.
61inline std::ostream &writeDotGraph (std::ostream &out,
62 const chomp::homology::diGraph<> &g,
63 const std::vector<int_t> &sizes,
64 const std::vector<theConleyIndexType> &indices,
65 const std::vector<IndexEigenValues> &eigenValues,
66 const std::vector<int> &wrongIndices,
67 const std::vector<int> &skippedIndices,
68 const std::vector<int> &attractors)
69{
70 // determine the number of vertices in the graph
71 int_t nVert = g. countVertices ();
72
73 // prepare a vector of bits indicating which indices are wrong
74 std::vector<bool> wrong (nVert, false);
75 for (std::vector<int>::const_iterator it = wrongIndices. begin ();
76 it != wrongIndices. end (); ++ it)
77 {
78 if (*it < 0)
79 continue;
80 else if (static_cast<int_t> (*it) >= nVert)
81 throw "Too large Morse set number with wrong index.";
82 wrong [*it] = true;
83 }
84
85 // prepare a vector of bits indicating which indices were skipped
86 std::vector<bool> skipped (nVert, false);
87 for (std::vector<int>::const_iterator it = skippedIndices. begin ();
88 it != skippedIndices. end (); ++ it)
89 {
90 if (*it < 0)
91 continue;
92 else if (static_cast<int_t> (*it) >= nVert)
93 throw "Too large number of a skipped index.";
94 skipped [*it] = true;
95 }
96
97 // prepare a vector of bits indicating which sets are attractors
98 std::vector<bool> attr (nVert, false);
99 for (std::vector<int>::const_iterator it = attractors. begin ();
100 it != attractors. end (); ++ it)
101 {
102 if (*it < 0)
103 continue;
104 else if (static_cast<int_t> (*it) >= nVert)
105 throw "Too large attractor number.";
106 attr [*it] = true;
107 }
108
109 // count the number of incoming edges
110 std::vector<int_t> incomingEdgesCount (nVert, 0);
111 for (int_t v = 0; v < nVert; ++ v)
112 {
113 int_t nEdges = g. countEdges (v);
114 for (int_t e = 0; e < nEdges; ++ e)
115 {
116 int_t target = g. getEdge (v, e);
117 if ((target < 0) || (target >= nVert))
118 throw "Wrong edge while writing dot graph.";
119 ++ (incomingEdgesCount [target]);
120 }
121 }
122
123 // write the graph for the 'dot' program
124 out << "digraph G {";
125 bool first = true;
126 for (int_t v = 0; v < nVert; ++ v)
127 {
128 // begin the definition of the vertex of the C-M graph
129 out << (first ? "" : " ") << "v" << v << " [label=\"";
130
131 // show the number of the Morse set and its size in cubes
132 out << v << ": " << sizes [v] << "\\n";
133
134 // check if there is anything nonzero to show
135 bool showindex = !eigenValues [v]. trivial ();
136 int dim = indices [v]. dim ();
137 for (int d = 0; !showindex && (d <= dim); ++ d)
138 {
139 if (indices [v]. BettiNumber (d) ||
140 (indices [v]. Coefficient (d, 0) != 0) ||
141 indices [v]. Map (d) -> getncols ())
142 {
143 showindex = true;
144 }
145 }
146
147 // show the Conley index
148 if (skipped [v])
149 {
150 out << "[index not computed]\\n";
151 }
152 else if (wrong [v])
153 {
154 out << "[no isolation]\\n";
155 }
156 else if (showindex)
157 {
158 // show the homology groups
159 out << "H = (" << indices [v]. HomString () <<
160 ")\\n";
161
162 // show the homomorphism in homology
163 for (int d = 0; d <= indices [v]. dim (); ++ d)
164 {
165 if (indices [v]. Map (d) -> getncols ())
166 {
167 out << indices [v].
168 MapString (d, "\\n");
169 }
170 }
171
172 // show the eigenvalues
173 eigenValues [v]. write (out, ", ", "\\n");
174 }
175
176 // finish writing the label of the vertex
177 out << "\"";
178
179 // add necessary features of the boxes
180 if (attr [v])
181 {
182 out << " shape=box style=filled color=" <<
183 (wrong [v] ? "red" : "yellow");
184 }
185 // else if (g. countEdges (v) == 0)
186 // {
187 // }
188 else if (incomingEdgesCount [v] == 0)
189 {
190 out << " shape=box style=filled color=" <<
191 (wrong [v] ? "red" : "greenyellow");
192 }
193 else if (!eigenValues [v]. trivial ())
194 {
195 out << " style=filled color=" <<
196 (wrong [v] ? "red" : "lightblue");
197 }
198 else if (wrong [v])
199 {
200 out << " style=filled color=red";
201 }
202 out << "]";
203
204 // make a note that this is no longer the first vertex
205 first = false;
206 }
207
208 // make sure all the attractors are at the same level
209 if (attractors. size () > 1)
210 {
211 out << " {rank=same;";
212 for (std::vector<int>::const_iterator it =
213 attractors. begin ();
214 it != attractors. end (); ++ it)
215 {
216 out << " v" << *it;
217 }
218 out << "}";
219 }
220
221 // the edges emanating from each vertex
222 for (int_t v = 0; v < nVert; ++ v)
223 {
224 int_t nEdges = g. countEdges (v);
225 for (int_t e = 0; e < nEdges; ++ e)
226 {
227 int_t target = g. getEdge (v, e);
228 out << " v" << v << "->v" << target;
229 }
230 }
231 out << "}";
232
233 return out;
234} /* writeDotGraph */
235
236
237#endif // _CMGRAPHS_DOTGRAPH_H_
238
Choice of configuration settings.
std::ostream & writeDotGraph(std::ostream &out, const chomp::homology::diGraph<> &g, const std::vector< int_t > &sizes, const std::vector< theConleyIndexType > &indices, const std::vector< IndexEigenValues > &eigenValues, const std::vector< int > &wrongIndices, const std::vector< int > &skippedIndices, const std::vector< int > &attractors)
Writes the given Conley-Morse graph to the output stream in the format for the 'dot' program.
Definition: dotgraph.h:61
Eigenvalues of the Conley index map.
Customizable data types for the Conley-Morse graphs computation program.
Data types for the dynamical systems data structures.