29 #ifndef _CHAINCON_ATMODEL3R_H_ 30 #define _CHAINCON_ATMODEL3R_H_ 38 #include "chomp/system/config.h" 39 #include "chomp/system/textfile.h" 40 #include "chomp/system/timeused.h" 41 #include "chomp/struct/hashsets.h" 42 #include "chomp/struct/multitab.h" 43 #include "chomp/struct/integer.h" 44 #include "chomp/homology/chains.h" 55 #ifndef _product_is_identity_ 56 #define _product_is_identity_ 60 (
const chomp::homology::mmatrix<chomp::homology::integer> &A,
61 const chomp::homology::mmatrix<chomp::homology::integer> &G)
63 if (A. getncols () != G. getnrows ())
65 if (G. getncols () != A. getnrows ())
68 using chomp::homology::integer;
69 using chomp::homology::chain;
73 int_t nCols = A. getncols ();
74 for (int_t nCol = 0; nCol < nCols; ++ nCol)
76 const chain<integer> &col (A. getcol (nCol));
78 int_t size = col. size ();
79 for (int_t pos = 0; pos < size; ++ pos)
81 img. add (G. getcol (col. num (pos)),
84 if ((img. size () != 1) ||
85 (img. num (0) != nCol) ||
86 (img. coef (0) != one))
93 #endif // _product_is_identity_ 102 chomp::homology::integer (e) {}
105 operator int ()
const {
return static_cast<int> (num);}
123 template <
class CellT,
class CoefT,
class CellArray1,
class CellArray2,
129 const CellRestrT &restr)
131 using chomp::homology::chaincomplex;
132 using chomp::homology::chain;
133 using chomp::homology::mmatrix;
134 using chomp::homology::timeused;
135 using chomp::homology::sout;
137 using chomp::homology::sbug;
138 using chomp::homology::integer;
139 using chomp::homology::hashedset;
140 using chomp::homology::multitable;
151 sbug <<
"[AT Model Algorithm 3r.]\n";
152 sout <<
"Constructing the chain complex of K...\n";
157 integer::initialize (CoefT::getp ());
164 const int_t KSize = K. size ();
165 const int dim = K [KSize - 1]. dim ();
166 const int trace_generators = 1;
167 const int trace_bases = 1;
168 chaincomplex<integer> cx (dim, trace_generators, trace_bases);
171 multitable<hashedset<CellT> > cells;
172 for (int_t i = 0; i < KSize; ++ i)
175 const CellT &c = K [i];
181 throw "Reduced homology not supported " 183 "Please, use Algorithm 4 instead.";
187 int_t cNum = cells [d]. size ();
191 int_t bLen = c. boundaryLength ();
192 for (int_t j = 0; j < bLen; ++ j)
198 int_t bNum = cells [d - 1]. getnumber (bCell);
206 bCoef = c. boundaryCoef (j);
209 cx. add (d, bNum, cNum, bCoef);
215 for (
int d = 0; d <= dim; ++ d)
217 cx. def_gen (d, cells [d]. size ());
221 sout <<
"The chain complex created in " << constrTime <<
".\n";
224 sout <<
"Computing the SNF of the boundary operator...\n";
230 cx. simple_form (level, quiet);
239 sout <<
"The SNF computed in " << snfTime <<
".\n";
246 sout <<
"Change of basis check: ";
247 for (
int q = 0; q <= dim; ++ q)
249 const mmatrix<integer> &G (cx. gethomgen (q));
250 const mmatrix<integer> &A (cx. getchgbasis (q));
254 sout <<
"Failed at level " << q <<
".\n";
255 throw "Wrong change of basis detected.";
258 sout <<
"Completed successfully in " << verifTime <<
".\n";
262 sout <<
"Composing an algebraic topological model from the SNF...\n";
263 timeused composingTime;
271 multitable <mmatrix<integer> > psi;
274 const mmatrix<integer> zeroMatrix;
275 for (
int q = 0; q <= dim; ++ q)
278 int_t gen_number = 0;
282 const mmatrix<integer> &Dq = cx. getboundary (q);
284 const mmatrix<integer> &Dq1 = (q < dim) ?
285 cx. getboundary (q + 1) : zeroMatrix;
287 const mmatrix<integer> &Gq = cx. gethomgen (q);
289 const mmatrix<integer> &Aq = cx. getchgbasis (q);
294 psi [q - 1]. define (cells [q]. size (),
295 cells [q - 1]. size ());
299 int ncells = cells [q]. size ();
300 for (
int i = 0; i < ncells; ++ i)
303 const chain<integer> &column = Dq. getcol (i);
306 if (!column. empty ())
308 integer e (column. coef (0));
309 if (e. delta () != 1)
311 throw "Non-invertible coefficient " 312 "encountered in the SNF.";
314 int b = column. num (0);
316 throw "Negative psi index.";
317 psi [q - 1]. add (i, b, e );
321 else if ((q == dim) || (Dq1. getrow (i). empty ()))
328 const chain<integer> &genChain =
332 const CellT &repr = cells [q] [gen_number];
337 int_t genSize = genChain. size ();
338 for (int_t j = 0; j < genSize; ++ j)
340 int_t n = genChain. num (j);
341 integer e = genChain. coef (j);
342 const CellT &genCell = cells [q] [n];
343 incl. add (repr, genCell,
348 const chain<integer> &piRow =
350 int_t piRowSize = piRow. size ();
351 for (int_t j = 0; j < piRowSize; ++ j)
353 int_t num = piRow. num (j);
354 integer e = piRow. coef (j);
355 const CellT &cell = cells [q] [num];
365 sout <<
"Transferring the computed maps to the original basis...\n";
366 for (
int q = 1; q <= dim; ++ q)
369 const mmatrix<integer> &M_A = cx. getchgbasis (q - 1);
370 const mmatrix<integer> &M_psi = psi [q - 1];
371 const mmatrix<integer> &M_A1 = cx. gethomgen (q);
374 int_t sizeA = M_A. getncols ();
375 int_t sizePsi = M_psi. getncols ();
376 int_t sizeA1 = M_A1. getncols ();
379 for (int_t i = 0; i < sizeA; ++ i)
382 const chain<integer> &column = M_A. getcol (i);
386 int_t sizeC = column. size ();
387 for (int_t j = 0; j < sizeC; ++ j)
389 int_t n = column. num (j);
392 const integer &e = column. coef (j);
393 psiC. add (M_psi. getcol (n), e );
397 chain<integer> phiColumn;
398 int_t sizePsiC = psiC. size ();
399 for (
int j = 0; j < sizePsiC; ++ j)
401 int_t n = psiC. num (j);
404 const integer &e = psiC. coef (j);
405 phiColumn. add (M_A1. getcol (n), e );
409 int_t sizePhiColumn = phiColumn. size ();
410 for (
int j = 0; j < sizePhiColumn; ++ j)
412 int_t n = phiColumn. num (j);
413 integer e = phiColumn. coef (j);
414 phi. add (cells [q - 1] [i], cells [q] [n],
421 sout <<
"AT model composed from the SNF in " << composingTime <<
425 sout <<
"AT model computed in " << compTime <<
".\n";
431 #endif // _CHAINCON_ATMODEL3R_H_ bool product_is_identity(const chomp::homology::mmatrix< chomp::homology::integer > &A, const chomp::homology::mmatrix< chomp::homology::integer > &G)
Verifies if the product of the given two matrices is an identity matrix.
A linear map for coefficients in an arbitrary commutative ring.
A friend of the 'integer' class (from the CHomP package) that converts 'integer' objects to numbers o...
void algTopModel3(const CellArray1 &K, CellArray2 &H, tLinMap< CellT, CellT, CoefT > &pi, tLinMap< CellT, CellT, CoefT > &incl, tLinMap< CellT, CellT, CoefT > &phi, const CellRestrT &restr)
Computes an algebraic topological model for the given filtered finite cell complex "K"...
int integer2int(const chomp::homology::integer &e)
Translation of CHomP's 'integer' to an 'int' number.
integerFriend(const chomp::homology::integer &e)
Constructor of the object from an 'integer' object.
A chain with coefficients in an arbitrary commutative ring.