30#ifndef _CMGRAPHS_MAPPARAM_H_
31#define _CMGRAPHS_MAPPARAM_H_
45#include "chomp/system/config.h"
46#include "chomp/system/textfile.h"
47#include "chomp/struct/autoarray.h"
48#include "chomp/multiwork/mwdata.h"
66 void define (
const double *leftParam,
const double *rightParam,
73 const double &
left (
size_t n)
const;
76 const double &
right (
size_t n)
const;
79 template <
class OutputStream>
80 OutputStream &
write (OutputStream &out)
const;
83 template <
class InputStream>
84 InputStream &
read (InputStream &in);
88 std::vector<std::pair<double,double> >
param;
105 const double *rightParam,
int nParam)
107 param. resize (nParam);
108 for (
int i = 0; i < nParam; ++ i)
110 param [i]. first = leftParam [i];
111 param [i]. second = rightParam [i];
123 return param [n]. first;
128 return param [n]. second;
131template <
class OutputStream>
134 int precision = out. precision ();
136 out << std::setprecision (hiprec);
137 for (
size_t n = 0; n <
param.
size (); ++ n)
139 out << (n ?
"x[" :
"[") <<
param [n]. first <<
"," <<
140 param [n]. second <<
"]";
142 out << std::setprecision (precision);
146template <
class InputStream>
149 using chomp::homology::ignorecomments;
155 if (in. get () !=
'[')
156 throw "Can't read parameters: Missing '['.";
158 std::pair<double,double> x;
161 if (in. get () !=
',')
162 throw "Can't read paramters: Missing comma.";
166 if (in. get () !=
']')
167 throw "Can't read parameters: Missing ']'.";
169 param. push_back (x);
170 if (in. peek () !=
'x')
183 size_t size (a. size ());
184 if (size != b. size ())
186 for (
size_t i = 0; i < size; ++ i)
188 if (a. left (i) != b. left (i))
190 if (a. right (i) != b. right (i))
198template <
class InputStream>
201 return param. read (in);
204template <
class OutputStream>
207 return param. write (out);
213inline chomp::multiwork::mwData &
operator << (chomp::multiwork::mwData &data,
216 int nParam (mapParam. size ());
218 for (
int i = 0; i < nParam; ++ i)
220 data << mapParam. left (i);
221 data << mapParam. right (i);
227inline chomp::multiwork::mwData &
operator >> (chomp::multiwork::mwData &data,
233 throw "A negative number of map parameters in mwData.";
236 mapParam. define (0, 0, 0);
240 chomp::homology::auto_array<double> paramPtr
241 (
new double [nParam << 1]);
242 double *param (paramPtr. get ());;
243 for (
int i = 0; i < nParam; ++ i)
246 data >> param [nParam + i];
248 mapParam. define (param, param + nParam, nParam);
259 if (par1. size () != par2. size ())
261 double margin = 0.00001;
262 for (
size_t n = 0; n < par1. size (); ++ n)
264 double left1 = par1. left (n);
265 left1 *= (left1 > 0) ? (1.0 - margin) : (1.0 + margin);
266 double right1 = par1. right (n);
267 right1 *= (right1 > 0) ? (1.0 + margin) : (1.0 - margin);
268 double left2 = par2. left (n);
269 left2 *= (left2 > 0) ? (1.0 - margin) : (1.0 + margin);
270 double right2 = par2. right (n);
271 right2 *= (right2 > 0) ? (1.0 + margin) : (1.0 - margin);
272 if ((right1 < left2) || (right2 < left1))
284 if (par1. size () != par2. size ())
286 double marginFraction = 0.1;
287 for (
size_t n = 0; n < par1. size (); ++ n)
289 double left1 = par1. left (n);
290 double right1 = par1. right (n);
293 double left2 = par2. left (n);
294 double right2 = par2. right (n);
297 double margin1 = marginFraction * (right1 - left1);
300 double margin2 = marginFraction * (right2 - left2);
303 if ((right1 < left2) || (right2 < left1))
A data structure for storing map parameters.
void define(const double *leftParam, const double *rightParam, int nParam)
Defines a data structure based on the given parameters.
const double & left(size_t n) const
Returns the n-th left bound for the parameters.
InputStream & read(InputStream &in)
Reads a parameter aggregate data object from an input stream.
std::vector< std::pair< double, double > > param
An aggregate data container for the parameters.
const double & right(size_t n) const
Returns the n-th right bound for the parameters.
OutputStream & write(OutputStream &out) const
Writes a parameter aggregate data object to an output stream.
size_t size() const
Returns the number of parameters.
MapParam()
The default constructor.
~MapParam()
The destructor.
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 ...
bool operator==(const MapParam &a, const MapParam &b)
Checks if the two collections of parameters are exactly the same.
OutputStream & operator<<(OutputStream &out, const MapParam ¶m)
bool shareInteriors(const MapParam &par1, const MapParam &par2)
Checks if two aggregate parameter objects that intersect actually share interiors in the parameters o...
InputStream & operator>>(InputStream &in, MapParam ¶m)