34#ifndef _CHOMP_HOMOLOGY_INDXPALG_H_
35#define _CHOMP_HOMOLOGY_INDXPALG_H_
56template <
class TCube,
class TSetOfCubes>
64 throw "The map has not been defined.";
74template <
class TCube = Cube>
86 double *left,
double *right);
104template <
class TCube>
114 const int dim = q. dim ();
119 double *left =
new double [dim];
120 double *right =
new double [dim];
121 f (coord, left, right);
128 for (
int i = 0; i < dim; ++ i)
130 ileft [i] =
static_cast<TCoordType> (left [i]);
131 if ((ileft [i] + 1 < left [i]) ||
132 (ileft [i] - 1 > left [i]))
133 throw "Conversion error: double to coord - "
135 for (
int j = 0; j < 10; ++ j)
137 if (ileft [i] >= left [i])
142 if (ileft [i] >= left [i])
143 throw "Outer approximation failure (left).";
144 iright [i] =
static_cast<TCoordType> (right [i]);
145 if ((iright [i] + 1 < right [i]) ||
146 (iright [i] - 1 > right [i]))
147 throw "Conversion error: double to coord - "
149 for (
int j = 0; j < 10; ++ j)
151 if (iright [i] <= right [i])
156 if (iright [i] <= right [i])
157 throw "Outer approximation failure (right).";
166 while ((c = r. get ()) != 0)
167 img. add (TCube (c, dim));
175template <
class TCube>
189template <
class TSetOfCubes>
194 typedef typename TSetOfCubes::value_type cubetype;
195 typedef typename cubetype::CoordType coordtype;
197 const int maxdim = cubetype::MaxDim;
200 coordtype mincoord [maxdim], maxcoord [maxdim];
203 int_t ncount = X. size ();
204 for (
int_t n = 0; n < ncount; ++ n)
207 int dim = X [n]. dim ();
208 X [n]. coord (mincoord);
212 for (
int i = 0; i < dim; ++ i)
214 maxcoord [i] = mincoord [i];
223 while ((c = r. get ()) != 0)
224 result. add (cubetype (c, dim));
237template <
class TSetOfCubes,
class TMap>
241 int_t ncount = X. size ();
247 for (
int_t n = 0; n < ncount; ++ n)
250 const TSetOfCubes &img = F (X [n]);
251 int_t icount = img. size ();
252 for (
int_t i = 0; i < icount; ++ i)
254 int_t number = X. getnumber (img [i]);
265 int_t count =
SCC (g, compVertices, compEnds,
269 int_t nVertices = ncount;
270 char *forward =
new char [nVertices];
271 for (
int_t i = 0; i < nVertices; ++ i)
273 for (
int_t cur = 0; cur < count; ++ cur)
275 g. DFScolor (forward,
'\1',
276 compVertices [cur ? compEnds [cur - 1] :
277 static_cast<int_t> (0)]);
281 char *backward =
new char [nVertices];
282 for (
int_t i = 0; i < nVertices; ++ i)
284 for (
int_t cur = 0; cur < count; ++ cur)
286 gT. DFScolor (backward,
'\1',
287 compVertices [cur ? compEnds [cur - 1] :
288 static_cast<int_t> (0)]);
292 for (
int_t i = 0; i < nVertices; ++ i)
293 if (forward [i] && backward [i])
311 int_t countX = X. size ();
312 if (countX && Y. empty ())
315 for (
int_t i = 0; i < countX; ++ i)
316 if (!Y. check (X [i]))
327template <
class TSetOfCubes,
class TMap>
328int ExitSetM (
const TSetOfCubes &N,
const TSetOfCubes &Q1,
329 const TMap &F, TSetOfCubes &resultQ2)
332 int_t countQ1 = Q1. size ();
336 while (n < countQ1 + resultQ2. size ())
339 const TSetOfCubes &img =
340 F ((n < countQ1) ? Q1 [n] : resultQ2 [n - countQ1]);
343 int_t countImg = img. size ();
344 for (
int_t i = 0; i < countImg; ++ i)
346 if (!N. check (img [i]))
348 if (Q1. check (img [i]))
350 resultQ2. add (img [i]);
360template <
class TSetOfCubes,
class TMap>
362 TSetOfCubes &resultQ1, TSetOfCubes &resultQ2)
365 TSetOfCubes S = initialS;
369 sout <<
"Starting with " << S. size () <<
" cubes in S_0, " <<
370 N. size () <<
" cubes in N.\n";
375 sout <<
"S := Inv(N)... ";
376 scon <<
"(computing)\b\b\b\b\b\b\b\b\b\b\b";
381 sout << S. size () <<
" cubes; o(S) has ";
386 sout << newN. size () <<
" cubes.\n";
394 sout <<
"Set N := o(S). ";
413template <
class TSetOfCubes,
class TMap>
415 TSetOfCubes &resultQ1, TSetOfCubes &resultQ2)
420 sout <<
"Computing the map on Q1 (" << resultQ1. size () <<
422 for (
int_t i = 0; i < resultQ1. size (); ++ i)
424 const TSetOfCubes &img = F (resultQ1 [i]);
425 for (
int_t j = 0; j < img. size (); ++ j)
427 if (!resultQ1. check (img [j]))
428 resultQ2. add (img [j]);
431 sout << resultQ2. size () <<
" cubes added to Q2.\n";
439 sout <<
"Increasing Q1 and Q2 until F(Q2) is disjoint from Q1... ";
441 int_t countimages = 0;
447 if (cur >= resultQ2. size ())
449 if (removed. empty ())
451 resultQ2. remove (removed);
460 if (!(counter % 373))
461 scon << std::setw (12) << counter <<
462 "\b\b\b\b\b\b\b\b\b\b\b\b";
465 bool intersects =
false;
466 const TSetOfCubes &img = F (resultQ2 [cur]);
468 for (
int_t j = 0; j < img. size (); ++ j)
470 if (resultQ1. check (img [j]))
480 for (
int_t j = 0; j < img. size (); ++ j)
482 if (!resultQ1. check (img [j]))
483 resultQ2. add (img [j]);
486 resultQ1. add (resultQ2 [cur]);
487 removed. add (resultQ2 [cur]);
493 sout << countimages <<
" analyzed.\n";
This file includes header files with various definitions of cubical cells and defines the standard ty...
This class is a wrapper for a map that computes the image of a cube as a rectangular box (i....
int(* map)(const TCoordType *coord, double *left, double *right)
The class of a map that computes the image of a unitary cube.
TCube::CoordType TCoordType
The type of coordinates of a cube.
BufferedMapClass(map _f)
The constructor.
hashedset< TCube > TSetOfCubes
The type of the set of cubes.
mvmap< TCube, TCube > F
The multivalued cubical map computed so far.
map f
A pointer to the map which computes images of cubes.
const TSetOfCubes & operator()(const TCube &q) const
Computes the image of a cube under the map and adds the image cubes to the given set.
This is a general map class that may be inherited by your particular class that computes a map.
const TSetOfCubes & operator()(const TCube &q) const
Computes the image of a cube under the map and adds the image cubes to the given set.
This class defines a directed graph with very limited number of operations, and a few specific algori...
This is a template for a set of objects of the given type.
This class defines a multivalued map.
This class can be used for iterating a rectangular set of points, given its left and right bound.
This file includes header files with various definitions of full cubes and defines the standard types...
This file contains an interface to procedures for full cubical reduction.
This header file contains the definition of a weighted directed graph class and several algorithms on...
int int_t
Index type for indexing arrays, counting cubes, etc.
This namespace contains the core of the homology computation procedures and related classes and templ...
int ExitSetM(const TSetOfCubes &N, const TSetOfCubes &Q1, const TMap &F, TSetOfCubes &resultQ2)
Computes iteratively Q2 := (F (Q1 + Q2) - Q1) * N.
outputstream sout
A replacement for standard output stream, with optional logging and other features provided by the cl...
tRectangle< coordinate > rectangle
The rectangle class with the default type of coordinates.
std::ostream & operator<<(std::ostream &out, const bincube< Dim, twoPower > &b)
bool inclusion(const HSet &X, const HSet &Y)
Verifies if X is a subset of Y. Returns true if yes, false if not.
int neighborhood(const TSetOfCubes &X, TSetOfCubes &result)
Computes a cubical neighborhood of width 1 around the set.
int IndexPairM(const TMap &F, const TSetOfCubes &initialS, TSetOfCubes &resultQ1, TSetOfCubes &resultQ2)
Constructs a combinatorial index pair satisfying Mrozek's definition.
outputstream scon
The console output stream to which one should put all the junk that spoils the log file,...
void invariantpart(TSetOfCubes &X, const TMap &F, TSetOfCubes &result)
Computes X := Inv (X).
int_t SCC(const diGraph< wType > &g, Table1 &compVertices, Table2 &compEnds, diGraph< wType > *scc=0, diGraph< wType > *transposed=0, bool copyweights=false)
Computes strongly connected components of the graph 'g'.
int IndexPairP(const TMap &F, const TSetOfCubes &initialS, TSetOfCubes &resultQ1, TSetOfCubes &resultQ2)
Constructs a combinatorial index pair satisfying Pilarczyk's definition.
This namespace contains the entire CHomP library interface.