The Conley-Morse Graphs Software
indpair.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file indpair.h
4///
5/// The Conley index pair computation.
6/// This file contains the definition of routines for the computation
7/// of the Conley index pair using a combinatorial cubical multivalued map.
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 July 19, 2006. Last revision: March 19, 2013.
30
31
32#ifndef _CMGRAPHS_INDPAIR_H_
33#define _CMGRAPHS_INDPAIR_H_
34
35
36// include some standard C++ header files
37#include <iostream>
38#include <algorithm>
39#include <new>
40#include <memory>
41
42// include selected header files from the CHomP library
43#include "chomp/system/textfile.h"
44#include "chomp/system/timeused.h"
45#include "chomp/struct/hashsets.h"
46#include "chomp/cubes/cube.h"
47
48// include local header files
49#include "config.h"
50#include "typedefs.h"
51#include "spacewrap.h"
52
53
54// --------------------------------------------------
55// ------------------- INDEX PAIR -------------------
56// --------------------------------------------------
57// The interface of a class that feeds cubes to the
58// Conley index computation procedure.
59
60/// The empty index pair class simulates an empty index pair.
61/// This is a general template for you to build an appropriate index pair.
62/// This might just be an interface to access an array of cubes in which
63/// the isolating neighborhood occupies the front of the array, and then
64/// cubes that form the exit set follow. Afterwards, all the other cubes
65/// that appear in the images of those two groups of cubes are listed.
67{
68public:
69 /// The type of a cube.
70 typedef chomp::homology::Cube CubeType;
71
72 /// The type of a set of cubes.
73 typedef chomp::homology::SetOfCubes CubSetType;
74
75 /// Returns the dimension of the underlying space.
76 int dim () const {return 1;}
77
78 /// Returns the number of cubes in the isolating neighborhood.
79 int_t countInv () const {return 0;}
80
81 /// Returns the number of cubes in the exit set.
82 int_t countExit () const {return 0;}
83
84 /// Returns the coordinates of the n-th cube
85 /// (first Inv, then Exit, followed by outside).
86 template <class IntType>
87 int getcube (int_t n, IntType *coord) const {return 0;}
88
89 /// Returns the number of cubes in the image of the n-th cube.
90 int_t imgcount (int_t n) const {return 0;}
91
92 /// Returns the number of the n-th cube in the image.
93 int_t getimgcube (int_t n, int_t i) const {return 0;}
94
95}; /* class EmptyIndexPair */
96
97// --------------------------------------------------
98
99/// A generic class that computes an index pair given the isolating
100/// neighborhood and a means to compute the multivalued cubical map.
101template <class mapcomp, class cubetype = chomp::homology::cube,
102 class cubsettype = chomp::homology::hashedset<cubetype> >
104{
105public:
106 /// The type of a cube.
107 typedef cubetype CubeType;
108
109 /// The type of a set of cubes.
110 typedef cubsettype CubSetType;
111
112 /// The only allowed constructor.
113 IndexPair (const mapcomp &_theCubMap = mapcomp ());
114
115 /// Adds a cube to S.
116 int add (const cubetype &q);
117
118 /// Returns the dimension of the phase space.
119 int dim () const;
120
121 /// Returns the number of cubes in the isolating neighborhood.
122 int_t countInv () const;
123
124 /// Returns the invariant part as a set of cubes.
125 const cubsettype &getInv () const;
126
127 /// Returns the number of cubes in the exit set.
128 int_t countExit () const;
129
130 /// Returns the exit set as a set of cubes.
131 const cubsettype &getExit () const;
132
133 /// Retrieves the coordinates of the n-th cube.
134 template <class IntType>
135 int getcube (int_t n, IntType *coord) const;
136
137 /// Returns the number of cubes in the image of the n-th cube
138 /// (which is either in S, or in the exit set).
139 int_t imgcount (int_t n) const;
140
141 /// Returns the number of the i-th cube
142 /// in the image of the n-th cube.
143 int_t getimgcube (int_t n, int_t i) const;
144
145 /// Computes the map on the entire set S, adds the necessary cubes
146 /// to the exit set, and also computes the map on the exit set,
147 /// so that the entire information necessary to compute the index map
148 /// on this index pair is obatined and stored within this object.
149 int compute ();
150
151 /// Clears the sets and the stored map.
152 int clear ();
153
154private:
155 /// The isolating neighborhood whose Conley index is computed.
156 cubsettype S;
157
158 /// The image of S without S.
159 cubsettype exitSet;
160
161 /// Additional images of cubes from the exit set.
162 cubsettype outside;
163
164 /// The multivalued cubical map that has been computed so far.
165 chomp::homology::mvmap<cubetype,cubetype> F;
166
167 /// The map object.
168 const mapcomp &theCubMap;
169
170 /// Adds the image of the map computed on one cube.
171 /// If the cube is in S, then the part of its image
172 /// that sticks out of S is added to the exit set.
173 int addimage (int_t n, const cubsettype &img);
174
175}; /* class IndexPair */
176
177// --------------------------------------------------
178
179template <class mapcomp, class cubetype, class cubsettype>
181 (const mapcomp &_theCubMap): theCubMap (_theCubMap)
182{
183 return;
184} /* IndexPair::IndexPair */
185
186template <class mapcomp, class cubetype, class cubsettype>
188{
189 if (!S. empty ())
190 return S [0]. dim ();
191 else if (!exitSet. empty ())
192 return exitSet [0]. dim ();
193 else
194 return -1;
195} /* IndexPair::dim */
196
197template <class mapcomp, class cubetype, class cubsettype>
199{
200 return S. size ();
201} /* IndexPair::countInv */
202
203template <class mapcomp, class cubetype, class cubsettype>
205 const
206{
207 return S;
208} /* IndexPair::getInv */
209
210template <class mapcomp, class cubetype, class cubsettype>
212{
213 return exitSet. size ();
214} /* IndexPair::countExit */
215
216template <class mapcomp, class cubetype, class cubsettype>
218 const
219{
220 return exitSet;
221} /* IndexPair::getExit */
222
223template <class mapcomp, class cubetype, class cubsettype>
224template <class IntType>
226 (int_t n, IntType *coord) const
227{
228 int_t countS = S. size ();
229 if (n < countS)
230 {
231 S [n]. coord (coord);
232 return 0;
233 }
234 int_t countExit = exitSet. size ();
235 if (n < countS + countExit)
236 {
237 exitSet [n - countS]. coord (coord);
238 return 0;
239 }
240 outside [n - countS - countExit]. coord (coord);
241 return 0;
242} /* IndexPair::getcube */
243
244template <class mapcomp, class cubetype, class cubsettype>
246{
247 int_t countS = S. size ();
248 if (n < countS)
249 return F (S [n]). size ();
250 else
251 return F (exitSet [n - countS]). size ();
252} /* IndexPair::imgcount */
253
254template <class mapcomp, class cubetype, class cubsettype>
256 (int_t n, int_t i) const
257{
258 int_t countS = S. size ();
259 const cubetype &q = (n < countS) ? (F (S [n])) [i] :
260 (F (exitSet [n - countS])) [i];
261 int_t num = S. getnumber (q);
262 if (num >= 0)
263 return num;
264 num = exitSet. getnumber (q);
265 if (num >= 0)
266 return (countS + num);
267 int_t countExit = exitSet. size ();
268 num = outside. getnumber (q);
269 if (num >= 0)
270 return (countS + countExit + num);
271 throw "Index pair not prepared.";
272// num = countS + exitSet. size () + outside. size ();
273// outside. add (q);
274// return num;
275} /* IndexPair::getimgcube */
276
277// --------------------------------------------------
278
279template <class mapcomp, class cubetype, class cubsettype>
281 const cubsettype &img)
282{
283 // add the cubes in the image to the exit set or to the outside set
284 int_t countS = S. size ();
285 int_t imgSize = img. size ();
286 for (int_t i = 0; i < imgSize; ++ i)
287 {
288 const cubetype &qImg (img [i]);
289 if (n < countS)
290 {
291 if (!S. check (qImg))
292 exitSet. add (qImg);
293 }
294 else // if (n >= countS)
295 {
296 if (S. check (qImg))
297 throw "Wrong index pair detected.";
298 else if (!exitSet. check (qImg))
299 outside. add (qImg);
300 }
301 }
302
303 // verify if the size of the index pair is within the given limit
304 if (countS + exitSet. size () + outside. size () > maxIndexPairSize)
305 throw "Excessive index pair size.";
306
307 return 0;
308} /* IndexPair::addimage */
309
310template <class mapcomp, class cubetype, class cubsettype>
312{
313 // set space wrapping if necessary and make sure that the wrapping
314 // will be unset upon exiting this procedure;
315 // if the servants are launched in separate processes then this is
316 // not necessary, I only put it here for testing the local servant
317 localSpaceWrapping wrapping (theCubMap. intWidth ());
318
319 // determine the size of the isolating neighborhood
320 int_t countS = S. size ();
321
322 chomp::homology::sbug << "Computing the index pair... ";
323
324 // compute the images of all the cubes
325 int_t countSX = countS;
326 for (int_t n = 0; n < countSX; ++ n)
327 {
328 // determine the cube whose image is to be computed
329 const cubetype &q ((n < countS) ? S [n] :
330 exitSet [n - countS]);
331
332 // compute the image of this cube
333 cubsettype &img = F [q];
334 theCubMap (q, &img, 0, 0, 0, !ignoreIsolationForConleyIndex);
335
336 // add the image of the cube to respective sets if necessary
337 addimage (n, img);
338
339 // update the end-of-the-loop bound to include the exit set
340 if (n == countS - 1)
341 {
342 chomp::homology::sbug << "* ";
343 countSX = countS + exitSet. size ();
344 }
345 }
346
347 chomp::homology::sbug << S. size () << " + " << exitSet. size () <<
348 " + " << outside. size () << " cubes.\n";
349 return 0;
350} /* IndexPair::compute */
351
352template <class mapcomp, class cubetype, class cubsettype>
354{
355 typename cubetype::CoordType coord [cubetype::MaxDim];
356 q. coord (coord);
357 cubetype r (coord, q. dim ());
358 S. add (r);
359 return 0;
360} /* IndexPair::add */
361
362template <class mapcomp, class cubetype, class cubsettype>
364{
365 cubsettype empty;
366 S = empty;
367 exitSet = empty;
368 outside = empty;
369 chomp::homology::mvmap<cubetype,cubetype> nomap;
370 F = nomap;
371 return 0;
372} /* IndexPair::clear */
373
374
375#endif // _CMGRAPHS_INDPAIR_H_
376
377
The empty index pair class simulates an empty index pair.
Definition: indpair.h:67
int_t imgcount(int_t n) const
Returns the number of cubes in the image of the n-th cube.
Definition: indpair.h:90
chomp::homology::Cube CubeType
The type of a cube.
Definition: indpair.h:70
chomp::homology::SetOfCubes CubSetType
The type of a set of cubes.
Definition: indpair.h:73
int_t countExit() const
Returns the number of cubes in the exit set.
Definition: indpair.h:82
int getcube(int_t n, IntType *coord) const
Returns the coordinates of the n-th cube (first Inv, then Exit, followed by outside).
Definition: indpair.h:87
int_t getimgcube(int_t n, int_t i) const
Returns the number of the n-th cube in the image.
Definition: indpair.h:93
int_t countInv() const
Returns the number of cubes in the isolating neighborhood.
Definition: indpair.h:79
int dim() const
Returns the dimension of the underlying space.
Definition: indpair.h:76
A generic class that computes an index pair given the isolating neighborhood and a means to compute t...
Definition: indpair.h:104
int addimage(int_t n, const cubsettype &img)
Adds the image of the map computed on one cube.
Definition: indpair.h:280
cubetype CubeType
The type of a cube.
Definition: indpair.h:107
int dim() const
Returns the dimension of the phase space.
Definition: indpair.h:187
const cubsettype & getInv() const
Returns the invariant part as a set of cubes.
Definition: indpair.h:204
int clear()
Clears the sets and the stored map.
Definition: indpair.h:363
IndexPair(const mapcomp &_theCubMap=mapcomp())
The only allowed constructor.
Definition: indpair.h:181
int_t getimgcube(int_t n, int_t i) const
Returns the number of the i-th cube in the image of the n-th cube.
Definition: indpair.h:256
cubsettype outside
Additional images of cubes from the exit set.
Definition: indpair.h:162
int compute()
Computes the map on the entire set S, adds the necessary cubes to the exit set, and also computes the...
Definition: indpair.h:311
int_t countInv() const
Returns the number of cubes in the isolating neighborhood.
Definition: indpair.h:198
const cubsettype & getExit() const
Returns the exit set as a set of cubes.
Definition: indpair.h:217
int_t imgcount(int_t n) const
Returns the number of cubes in the image of the n-th cube (which is either in S, or in the exit set).
Definition: indpair.h:245
cubsettype exitSet
The image of S without S.
Definition: indpair.h:159
int add(const cubetype &q)
Adds a cube to S.
Definition: indpair.h:353
const mapcomp & theCubMap
The map object.
Definition: indpair.h:168
chomp::homology::mvmap< cubetype, cubetype > F
The multivalued cubical map that has been computed so far.
Definition: indpair.h:165
cubsettype S
The isolating neighborhood whose Conley index is computed.
Definition: indpair.h:156
int getcube(int_t n, IntType *coord) const
Retrieves the coordinates of the n-th cube.
Definition: indpair.h:226
cubsettype CubSetType
The type of a set of cubes.
Definition: indpair.h:110
int_t countExit() const
Returns the number of cubes in the exit set.
Definition: indpair.h:211
Sets space wrapping locally.
Definition: spacewrap.h:82
Choice of configuration settings.
const bool ignoreIsolationForConleyIndex
Ignoring the isolation problem while computing the Conley index.
Definition: p_differ.h:216
const int maxIndexPairSize
The maximal allowed size of the index pair.
Definition: p_differ.h:173
Helper functions and an auxiliary class for space wrapping.
Customizable data types for the Conley-Morse graphs computation program.