The Conley-Morse Graphs Software
morsecache.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file morsecache.h
4///
5/// Caching Morse decompositions using compressed binary files.
6/// This file contains the definition of two functions,
7/// one for saving and another one for retrieving a Morse decomposition
8/// together with auxiliary data (as computed by computeMorseDecomposition).
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 July 7, 2014. Last revision: July 8, 2014.
31
32
33#ifndef _CMGRAPHS_MORSECACHE_H_
34#define _CMGRAPHS_MORSECACHE_H_
35
36
37// include some standard C++ header files
38#include <algorithm>
39#include <new>
40#include <string>
41#include <sstream>
42
43// include selected header files from the CHomP library
44#include "chomp/system/textfile.h"
45#include "chomp/cubes/pointset.h"
46#include "chomp/struct/digraph.h"
47#include "chomp/struct/multitab.h"
48#include "chomp/struct/hashsets.h"
49#include "chomp/system/timeused.h"
50
51// include local header files
52#include "config.h"
53#include "typedefs.h"
54#include "conindex.h"
55#include "morsedec.h"
56#include "typedyns.h"
57#include "utils.h"
58#include "bytecompr.h"
59#include "byteutil.h"
60
61
62
63
64// ----------------------------------------------------------------
65// TODO: Save and retrieve connections in the Morse decompositions,
66// and Conley indices, too!
67// ----------------------------------------------------------------
68
69
70
71// --------------------------------------------------
72// ---------- saving a Morse decomposition ----------
73// --------------------------------------------------
74
75/// Saves a Morse decomposition to a binary file.
76/// Throws an error message in case of failure.
77inline void saveMorseDecCache (const char *fileName,
78 const theMorseDecompositionType &morseDec,
79 const std::vector<int> &wrongIndices,
80 const std::vector<int> &skippedIndices,
81 const std::vector<int> &attractors)
82{
83 std::ofstream outStream (fileName, std::ios::out | std::ios::binary);
84 ByteCompressor out (outStream);
85 int nSets (morseDec. count ());
86 out << nSets;
87 for (int n = 0; n < nSets; ++ n)
88 out << morseDec [n];
89 for (int n = 0; n < nSets; ++ n)
90 {
91 std::ostringstream str;
92 str << morseDec. index (n);
93 out << str. str ();
94 }
95 for (int n = 0; n < nSets; ++ n)
96 {
97 for (int m = 0; m < nSets; ++ m)
98 {
99 out << (morseDec. connected (n, m) ? '\1' : '\0');
100 }
101 }
102 out << wrongIndices;
103 out << skippedIndices;
104 out << attractors;
105 out << static_cast<int> (controlNumber);
106 out. close ();
107 return;
108} /* saveMorseDecCache */
109
110
111// --------------------------------------------------
112// --------- loading a Morse decomposition ----------
113// --------------------------------------------------
114
115/// Loads a Morse decomposition from a binary file.
116/// Throws an error message in case of failure.
117inline void loadMorseDecCache (const char *fileName,
119 std::vector<int> &wrongIndices,
120 std::vector<int> &skippedIndices,
121 std::vector<int> &attractors)
122{
123 std::ifstream inStream (fileName, std::ios::in | std::ios::binary);
124 ByteDecompressor in (inStream);
125 int nSets (0);
126 in >> nSets;
127 morseDec. setnumber (nSets);
128 for (int n = 0; n < nSets; ++ n)
129 in >> morseDec [n];
130 for (int n = 0; n < nSets; ++ n)
131 {
132 std::string s;
133 in >> s;
134 std::istringstream str (s);
136 str >> ind;
137 morseDec. setindex (n, ind);
138 }
139 for (int n = 0; n < nSets; ++ n)
140 {
141 for (int m = 0; m < nSets; ++ m)
142 {
143 char c;
144 in >> c;
145 if (c)
146 morseDec. addconn (n, m);
147 }
148 }
149 in >> wrongIndices;
150 in >> skippedIndices;
151 in >> attractors;
152 int ctrl (0);
153 in >> ctrl;
154 if (ctrl != controlNumber)
155 throw "Wrong control number while loading cached Morse dec.";
156 in. close ();
157 return;
158} /* loadMorseDecCache */
159
160
161#endif // _CMGRAPHS_MORSECACHE_H_
162
Writing and reading binary data (int, double) with bzip2 compression.
Utility procedures for writing and reading entire data structures with bzip2 compression,...
const int controlNumber
The control number that is used to confirm the compatibility between the coordinator and workers.
Definition: c_differ.h:79
A simple wrapper for the bzip2 data compression to an output stream.
Definition: bytecompr.h:59
A simple wrapper for the bzip2 data decompression from an input stream.
Definition: bytecompr.h:295
The class that computes and returns properties of the Conley index.
Definition: conindex.h:86
The Morse decoposition class.
Definition: morsedec.h:65
Choice of configuration settings.
Conley index computation routines.
void loadMorseDecCache(const char *fileName, theMorseDecompositionType &morseDec, std::vector< int > &wrongIndices, std::vector< int > &skippedIndices, std::vector< int > &attractors)
Loads a Morse decomposition from a binary file.
Definition: morsecache.h:117
void saveMorseDecCache(const char *fileName, const theMorseDecompositionType &morseDec, const std::vector< int > &wrongIndices, const std::vector< int > &skippedIndices, const std::vector< int > &attractors)
Saves a Morse decomposition to a binary file.
Definition: morsecache.h:77
Morse decompositions.
Customizable data types for the Conley-Morse graphs computation program.
Data types for the dynamical systems data structures.
Utilites and helper functions.