00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _CMGRAPHS_DOTGRAPH_H_
00035 #define _CMGRAPHS_DOTGRAPH_H_
00036
00037
00038
00039 #include <string>
00040 #include <ostream>
00041 #include <cmath>
00042 #include <vector>
00043
00044
00045 #include "chomp/system/config.h"
00046 #include "chomp/system/textfile.h"
00047 #include "chomp/cubes/cube.h"
00048
00049
00050 #include "config.h"
00051 #include "typedefs.h"
00052 #include "eigenval.h"
00053
00054
00055
00056
00057
00058
00059
00060
00061 inline std::ostream &writeDotGraph (std::ostream &out,
00062 const chomp::homology::diGraph<> &g,
00063 const std::vector<int> &sizes,
00064 const std::vector<theConleyIndexType> &indices,
00065 const std::vector<IndexEigenValues> &eigenValues,
00066 const std::vector<int> &wrongIndices,
00067 const std::vector<int> &skippedIndices,
00068 const std::vector<int> &attractors)
00069 {
00070
00071 int nVert = g. countVertices ();
00072
00073
00074 std::vector<bool> wrong (nVert, false);
00075 for (std::vector<int>::const_iterator it = wrongIndices. begin ();
00076 it != wrongIndices. end (); ++ it)
00077 {
00078 if (*it < 0)
00079 continue;
00080 else if (*it >= nVert)
00081 throw "Too large Morse set number with wrong index.";
00082 wrong [*it] = true;
00083 }
00084
00085
00086 std::vector<bool> skipped (nVert, false);
00087 for (std::vector<int>::const_iterator it = skippedIndices. begin ();
00088 it != skippedIndices. end (); ++ it)
00089 {
00090 if (*it < 0)
00091 continue;
00092 else if (*it >= nVert)
00093 throw "Too large number of a skipped index.";
00094 skipped [*it] = true;
00095 }
00096
00097
00098 std::vector<bool> attr (nVert, false);
00099 for (std::vector<int>::const_iterator it = attractors. begin ();
00100 it != attractors. end (); ++ it)
00101 {
00102 if (*it < 0)
00103 continue;
00104 else if (*it >= nVert)
00105 throw "Too large attractor number.";
00106 attr [*it] = true;
00107 }
00108
00109
00110 std::vector<int> incomingEdgesCount (nVert, 0);
00111 for (int v = 0; v < nVert; ++ v)
00112 {
00113 int nEdges = g. countEdges (v);
00114 for (int e = 0; e < nEdges; ++ e)
00115 {
00116 int target = g. getEdge (v, e);
00117 if ((target < 0) || (target >= nVert))
00118 throw "Wrong edge while writing dot graph.";
00119 ++ (incomingEdgesCount [target]);
00120 }
00121 }
00122
00123
00124 out << "digraph G {";
00125 bool first = true;
00126 for (int v = 0; v < nVert; ++ v)
00127 {
00128
00129 out << (first ? "" : " ") << "v" << v << " [label=\"";
00130
00131
00132 out << v << ": " << sizes [v] << "\\n";
00133
00134
00135 bool showindex = !eigenValues [v]. trivial ();
00136 int dim = indices [v]. dim ();
00137 for (int d = 0; !showindex && (d <= dim); ++ d)
00138 {
00139 if (indices [v]. BettiNumber (d) ||
00140 (indices [v]. Coefficient (d, 0) != 0) ||
00141 indices [v]. Map (d) -> getncols ())
00142 {
00143 showindex = true;
00144 }
00145 }
00146
00147
00148 if (wrong [v])
00149 {
00150 out << "[no isolation]\\n";
00151 }
00152 else if (skipped [v])
00153 {
00154 out << "[index skipped]\\n";
00155 }
00156 else if (showindex)
00157 {
00158
00159 out << "H = (" << indices [v]. HomString () <<
00160 ")\\n";
00161
00162
00163 for (int d = 0; d <= indices [v]. dim (); ++ d)
00164 {
00165 if (indices [v]. Map (d) -> getncols ())
00166 {
00167 out << indices [v].
00168 MapString (d, "\\n");
00169 }
00170 }
00171
00172
00173 eigenValues [v]. write (out, ", ", "\\n");
00174 }
00175
00176
00177 out << "\"";
00178
00179
00180 if (attr [v])
00181 {
00182 out << " shape=box style=filled color=" <<
00183 (wrong [v] ? "red" : "yellow");
00184 }
00185
00186
00187
00188 else if (incomingEdgesCount [v] == 0)
00189 {
00190 out << " shape=box style=filled color=" <<
00191 (wrong [v] ? "red" : "greenyellow");
00192 }
00193 else if (!eigenValues [v]. trivial ())
00194 {
00195 out << " style=filled color=" <<
00196 (wrong [v] ? "red" : "lightblue");
00197 }
00198 else if (wrong [v])
00199 {
00200 out << " style=filled color=red";
00201 }
00202 out << "]";
00203
00204
00205 first = false;
00206 }
00207
00208
00209 if (attractors. size () > 1)
00210 {
00211 out << " {rank=same;";
00212 for (std::vector<int>::const_iterator it =
00213 attractors. begin ();
00214 it != attractors. end (); ++ it)
00215 {
00216 out << " v" << *it;
00217 }
00218 out << "}";
00219 }
00220
00221
00222 for (int v = 0; v < nVert; ++ v)
00223 {
00224 int nEdges = g. countEdges (v);
00225 for (int e = 0; e < nEdges; ++ e)
00226 {
00227 int target = g. getEdge (v, e);
00228 out << " v" << v << "->v" << target;
00229 }
00230 }
00231 out << "}";
00232
00233 return out;
00234 }
00235
00236
00237 #endif // _CMGRAPHS_DOTGRAPH_H_
00238