The Conley-Morse Graphs Software
procharv.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file procharv.h
4///
5/// A plug-in for post-processing of Morse decompositions
6/// for the harvesting model.
7/// This is a replacement for "procmdec.h".
8///
9/// @author Pawel Pilarczyk
10///
11/////////////////////////////////////////////////////////////////////////////
12
13// Copyright (C) 1997-2014 by Pawel Pilarczyk.
14//
15// This file is part of my research software package. This is free software:
16// you can redistribute it and/or modify it under the terms of the GNU
17// General Public License as published by the Free Software Foundation,
18// either version 3 of the License, or (at your option) any later version.
19//
20// This software is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23// GNU General Public License for more details.
24//
25// You should have received a copy of the GNU General Public License
26// along with this software; see the file "license.txt". If not,
27// please, see <https://www.gnu.org/licenses/>.
28
29// Started on June 27, 2011. Last revision: June 28, 2011.
30
31
32#ifndef _CMGRAPHS_PROCHARV_H_
33#define _CMGRAPHS_PROCHARV_H_
34
35// include some standard C++ header files
36#include <sstream>
37#include <fstream>
38#include <string>
39
40// include selected header files from the CHomP library
41#include "chomp/system/textfile.h"
42#include "chomp/system/timeused.h"
43#include "chomp/struct/digraph.h"
44#include "chomp/struct/flatmatr.h"
45#include "chomp/struct/multitab.h"
46#include "chomp/cubes/neighbor.h"
47
48// include local header files
49#include "config.h"
50#include "typedefs.h"
51#include "conindex.h"
52#include "morsedec.h"
53#include "typedyns.h"
54#include "utils.h"
55
56
57namespace custom {
58
59/// Post-processing of Morse decompositions for the harvesting model.
60namespace procMorseDecHarv {
61
62
63// --------------------------------------------------
64// ------- post-process a Morse decomposition -------
65// --------------------------------------------------
66
67/// Post-processes a Morse decomposition by computing a decomposition
68/// of each Morse set into cycle sets and analyzing this decomposition.
69template <class CubSetType, class MorseDecType, class GraphType,
70 class CubMapType>
71inline void processMorseDec (const MorseDecType &morseDec,
72 const CubSetType &allCubes, const GraphType &g,
73 const CubMapType &theCubMap, const CubMapType &,
74 const std::string &cubesFilePrefix,
75 const std::string &procFilePrefix)
76{
77 using namespace chomp::homology;
78
79 sbug << "===== Post-processing the Morse sets. =====\n";
80 timeused timePostProc;
81 timePostProc = 0;
82
83 // prepare the size of attractor population size and attractor index
84 double attrPopSize = 0;
85 double attrPopSizes [spaceDim];
86 for (int i = 0; i < spaceDim; ++ i)
87 attrPopSizes [i] = 0;
88 int attractor = -1;
89
90 // analyze each Morse set
91 int nSets = morseDec. count ();
92 for (int n = 0; n < nSets; ++ n)
93 {
94 const CubSetType &morseCubes = morseDec [n];
95 int_t morseCount = morseCubes. size ();
96
97 // restrict the analysis to the given Morse set
98 sbug << "Morse set no. " << n << ": " <<
99 morseCount << " cubes, ";
100
101 // compute the real exit set for the Morse set
102 sbug << "exit set: ";
103 CubSetType exitSet;
104 for (int i = 0; i < morseCount; ++ i)
105 theCubMap (morseCubes [i], &exitSet, 0, 0, 0, false);
106 exitSet. remove (morseCubes);
107 sbug << exitSet. size () << " cubes.\n";
108
109 // save the exit set to a file if requested to
110 if (!cubesFilePrefix. empty ())
111 {
112 // prepare a file name for this set
113 std::ostringstream exitFileNameStr;
114 exitFileNameStr << cubesFilePrefix << n << "e.cub";
115 std::string exitFileName = exitFileNameStr. str ();
116
117 // save the exit set to a file
118 sbug << "Saving the exit set to '" <<
119 exitFileName << "'... ";
120 std::ofstream f (exitFileName. c_str ());
121 f << "; The exit set for the corresponding Morse "
122 "set (" << exitSet. size () << " cubes).\n";
123 f << exitSet;
124 f. close ();
125 sbug << "Done.\n";
126 }
127
128 // compute the average population size
129 double popSize = 0;
130 double popSizes [spaceDim];
131 double boxSize [spaceDim];
132 for (int i = 0; i < spaceDim; ++ i)
133 {
134 popSizes [i] = 0;
135 boxSize [i] = spaceWidth [i] / (1 << finalDepth);
136 }
137 for (int k = 0; k < morseCount; ++ k)
138 {
139 spcCoord c [spaceDim];
140 morseCubes [k]. coord (c);
141 double sum = 0;
142 for (int i = 0; i < spaceDim; ++ i)
143 {
144 double size = spaceOffset [i] +
145 (c [i] + 0.5) * boxSize [i];
146 sum += size;
147 popSizes [i] += size;
148 }
149 popSize += sum;
150 }
151 popSize /= morseCount;
152 sbug << "Avg pop sizes: ";
153 for (int i = 0; i < spaceDim; ++ i)
154 {
155 popSizes [i] /= morseCount;
156 sbug << (i ? " + " : "") << popSizes [i];
157 }
158 sbug << " = " << popSize << ".\n";
159
160 // determine if this Morse set is at the bottom of the CMG
161 bool bottom = true;
162 for (int m = 0; m < nSets; ++ m)
163 {
164 if (morseDec. connected (n, m))
165 {
166 bottom = false;
167 break;
168 }
169 }
170
171 // store the index of the attractor and the population size
172 if ((attractor < 0) && bottom)
173 {
174 attrPopSize = popSize;
175 for (int i = 0; i < spaceDim; ++ i)
176 attrPopSizes [i] = popSizes [i];
177 attractor = exitSet. empty () ? n : (-1 - n);
178 }
179 }
180
181 // output the index of the attractor and the attr. population size
182 int attrIndex = (attractor < 0) ? (-1 - attractor) : attractor;
183 sbug << ((attractor < 0) ? "Non-isol a" : "A") << "ttractor " <<
184 attrIndex << " (" << morseDec [attrIndex]. size () <<
185 " cubes), avg pop sizes: ";
186 for (int i = 0; i < spaceDim; ++ i)
187 sbug << (i ? " + " : "") << attrPopSizes [i];
188 sbug << " = " << attrPopSize << ". Coord ranges: ";
189 CoordMinMax coordMinMax;
190 coordMinMax (morseDec [attrIndex]);
191 sbug << coordMinMax << ".\n";
192
193 sbug << "===== Post-processing completed in " << timePostProc <<
194 ". =====\n";
195
196 return;
197} /* processMorseDec */
198
199
200} // namespace procMorseDecHarv
201} // namespace custom
202
203
204#endif // _CMGRAPHS_PROCHARV_H_
205
A class whose objects store, update and show coordinate ranges.
Definition: utils.h:444
Choice of configuration settings.
Conley index computation routines.
Morse decompositions.
const SpaceOffsetType spaceOffset
An imitation of an array which returns the offset of the rectangular area in the phase space which co...
Definition: p_differ.h:108
const int spaceDim
The dimension of the phase space.
Definition: p_differ.h:48
const SpaceWidthType spaceWidth
An imitation of an array which returns the width of the rectangular area in the phase space which con...
Definition: p_differ.h:128
const int finalDepth
The final depth of subdivisions in the phase space.
Definition: p_differ.h:58
void processMorseDec(const MorseDecType &morseDec, const CubSetType &allCubes, const GraphType &g, const CubMapType &theCubMap, const CubMapType &, const std::string &cubesFilePrefix, const std::string &procFilePrefix)
Post-processes a Morse decomposition by computing a decomposition of each Morse set into cycle sets a...
Definition: procharv.h:71
Customizable settings that are supposed to be modified and/or chosen by the user of the software.
Customizable data types for the Conley-Morse graphs computation program.
Data types for the dynamical systems data structures.
int spcCoord
The type of coordinates of cubes in the phase space.
Definition: typespace.h:50
Utilites and helper functions.