The Conley-Morse Graphs Software
mapopt.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file mapopt.h
4///
5/// Map optimization data saving, retrieving, and sending.
6///
7/// @author Pawel Pilarczyk
8///
9/////////////////////////////////////////////////////////////////////////////
10
11// Copyright (C) 1997-2014 by Pawel Pilarczyk.
12//
13// This file is part of my research software package. This is free software:
14// you can redistribute it and/or modify it under the terms of the GNU
15// General Public License as published by the Free Software Foundation,
16// either version 3 of the License, or (at your option) any later version.
17//
18// This software is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with this software; see the file "license.txt". If not,
25// please, see <https://www.gnu.org/licenses/>.
26
27// Started on March 25, 2013. Last revision: November 17, 2013.
28
29
30#ifndef _CMGRAPHS_MAPOPT_H_
31#define _CMGRAPHS_MAPOPT_H_
32
33
34// include some standard C++ header files
35#include <string>
36#include <sstream>
37#include <vector>
38#include <iostream>
39#include <iomanip>
40#include <algorithm>
41#include <memory>
42#include <utility>
43
44// include all the necessary header files from the CHomP library
45#include "chomp/system/config.h"
46#include "chomp/system/textfile.h"
47
48// include local header files
49#include "mapparam.h"
50
51
52// --------------------------------------------------
53// ------------- map optimization data --------------
54// --------------------------------------------------
55
56/// A class whose objects are responsible for adjusting the integration
57/// parameters such as step size and the number of steps for an ODE.
59{
60public:
61 /// The default constructor.
63
64 /// The destructor.
66
67 /// Returns the number of map optimization information lines.
68 size_t size () const;
69
70 /// Reads all the optimization data from a stream.
71 void loadData (std::istream &in);
72
73 /// Saves all the optimization data to a stream.
74 /// If requested, saves new information only
75 /// (without that loaded previously or saved earlier).
76 void saveData (std::ostream &out, bool incremental);
77
78 /// Adds a line of optimization data obtained from computation
79 /// or read from a file to the collection.
80 /// If the data does not add any new knowledge to the database
81 /// then this line is ignored.
82 /// The beginning of the line should contain the definition
83 /// of the parameters for which the information was computed.
84 void addData (const std::string &line, bool computed);
85
86 /// Prepares a collection of lines to consider while processing
87 /// a map with the given parameters.
88 void prepareData (std::vector<std::string> &data,
89 const double *leftParam, const double *rightParam,
90 int nParam);
91
92private:
93 /// The copy constructor should not be used.
95
96 /// The assignment operator should not be used.
98
99 /// Collected data lines
100 std::vector<std::string> dataLines;
101
102 /// Decoded parameter aggregates for each data line.
103 std::vector<MapParam> dataParam;
104
105 /// The number of data lines loaded previously or already saved.
106 size_t oldData;
107
108}; /* class MapOptimization */
109
110// --------------------------------------------------
111
113{
114 return;
115} /* MapOptimization::MapOptimization */
116
118{
119 return;
120} /* MapOptimization::~MapOptimization */
121
123{
124 throw "Trying to use the copy constructor of MapOptimization.";
125 return;
126} /* MapOptimization::MapOptimization */
127
129{
130 throw "Trying to use the assignment operator of MapOptimization.";
131 return *this;
132} /* MapOptimization::MapOptimization */
133
134inline size_t MapOptimization::size () const
135{
136 return dataLines. size ();
137} /* MapOptimization::size */
138
139inline void MapOptimization::loadData (std::istream &in)
140{
141 if (oldData != dataLines. size ())
142 {
143 throw "Trying to load map optimization data "
144 "on top of new data.";
145 }
146 chomp::homology::ignorecomments (in);
147 while (!in. eof ())
148 {
149 // read a line from the
150 std::string line;
151 std::getline (in, line);
152 if (in. bad ())
153 break;
154 chomp::homology::ignorecomments (in);
155
156 // TODO: check if this line adds essential information
157
158 // add this data line to the collection
159 addData (line, false);
160 }
161 oldData = dataLines. size ();
162
163 return;
164} /* MapOptimization::loadData */
165
166void MapOptimization::saveData (std::ostream &out, bool incremental)
167{
168 for (size_t n = incremental ? oldData : 0;
169 n < dataLines. size (); ++ n)
170 {
171 out << dataLines [n] << '\n';
172 }
173 oldData = dataLines. size ();
174
175 return;
176} /* MapOptimization::saveData */
177
178void MapOptimization::addData (const std::string &line, bool computed)
179{
180 // if the line is empty then ignore it
181 if (line. empty ())
182 return;
183
184 // TODO: check if this line adds essential information
185
186 // add the data line to the collection
187 dataLines. push_back (line);
188
189 // decode the parameters for faster access
190 MapParam par;
191 std::istringstream in (line);
192 par. read (in);
193 dataParam. push_back (par);
194
195 return;
196} /* MapOptimization::addData */
197
198void MapOptimization::prepareData (std::vector<std::string> &data,
199 const double *leftParam, const double *rightParam, int nParam)
200{
201 // TODO: make this procedure much smarter
202
203 // make sure that all the relevant data lines are pre-decoded
204 if (dataLines. size () != dataParam. size ())
205 throw "Map optimization lines-parameters mismatch.";
206
207 // create a data strurcutre with the requested parameters
208 MapParam parRequested;
209 parRequested. define (leftParam, rightParam, nParam);
210
211 // find all the lines that are relevant for these parameters
212 for (size_t n = 0; n < dataLines. size (); ++ n)
213 {
214 if (intersect (parRequested, dataParam [n]) &&
215 shareInteriors (parRequested, dataParam [n]))
216 {
217 data. push_back (dataLines [n]);
218 }
219 }
220
221 return;
222} /* MapOptimization::prepareData */
223
224
225#endif // _CMGRAPHS_MAPOPT_H_
226
A class whose objects are responsible for adjusting the integration parameters such as step size and ...
Definition: mapopt.h:59
size_t oldData
The number of data lines loaded previously or already saved.
Definition: mapopt.h:106
std::vector< std::string > dataLines
Collected data lines.
Definition: mapopt.h:100
void loadData(std::istream &in)
Reads all the optimization data from a stream.
Definition: mapopt.h:139
void saveData(std::ostream &out, bool incremental)
Saves all the optimization data to a stream.
Definition: mapopt.h:166
std::vector< MapParam > dataParam
Decoded parameter aggregates for each data line.
Definition: mapopt.h:103
MapOptimization()
The default constructor.
Definition: mapopt.h:112
MapOptimization & operator=(const MapOptimization &)
The assignment operator should not be used.
Definition: mapopt.h:128
~MapOptimization()
The destructor.
Definition: mapopt.h:117
size_t size() const
Returns the number of map optimization information lines.
Definition: mapopt.h:134
void prepareData(std::vector< std::string > &data, const double *leftParam, const double *rightParam, int nParam)
Prepares a collection of lines to consider while processing a map with the given parameters.
Definition: mapopt.h:198
void addData(const std::string &line, bool computed)
Adds a line of optimization data obtained from computation or read from a file to the collection.
Definition: mapopt.h:178
A data structure for storing map parameters.
Definition: mapparam.h:57
A simple aggregate data structure for map parameters.
bool intersect(const MapParam &par1, const MapParam &par2)
Checks if two aggregate parameter objects are so close to each other that after a small blow-up they ...
Definition: mapparam.h:257
bool shareInteriors(const MapParam &par1, const MapParam &par2)
Checks if two aggregate parameter objects that intersect actually share interiors in the parameters o...
Definition: mapparam.h:282