30 #ifndef _CHAINCON_AMMODEL_H_ 31 #define _CHAINCON_AMMODEL_H_ 43 #include "chomp/system/config.h" 44 #include "chomp/system/textfile.h" 45 #include "chomp/system/timeused.h" 46 #include "chomp/struct/hashsets.h" 47 #include "chomp/struct/multitab.h" 48 #include "chomp/struct/integer.h" 49 #include "chomp/homology/chains.h" 73 template <
class CellT,
class CoefT,
class CellArray1,
class CellArray2,
74 class CellArray3,
class CoefArray>
76 CellArray2 &A, CellArray3 &B, CoefArray &Q,
81 using chomp::homology::sout;
83 using chomp::homology::sbug;
84 using chomp::homology::timeused;
85 using chomp::homology::multitable;
86 using chomp::homology::hashedset;
100 sout <<
"Splitting K into sets of cells of each dimension...\n";
105 multitable<hashedset<CellT> > cells;
111 const int_t KSize = K. size ();
112 for (int_t k = 0; k < KSize; ++ k)
114 const CellT &cell (K [k]);
115 int dim (cell. dim ());
117 cells [dim]. add (cell);
123 sout <<
"K split in " << splitTime <<
".\n";
126 sout <<
"Creating the matrices of the boundary operator on K...\n";
134 for (
int q = 0; q < maxDim; ++ q)
136 int_t nRows = (q > 0) ? cells [q - 1]. size () :
137 (CellT::EmptyType::exists () ? 1 : 0);
138 int_t nCols = cells [q]. size ();
139 matrix. setSize (q, nRows, nCols);
145 for (
int q = 0; q < maxDim; ++ q)
147 if ((q == 0) && !CellT::EmptyType::exists ())
149 int_t size (cells [q]. size ());
150 for (int_t cNum = 0; cNum < size; ++ cNum)
153 const CellT &c = cells [q] [cNum];
156 int_t bLen = c. boundaryLength ();
157 for (int_t j = 0; j < bLen; ++ j)
163 CoefT bCoef (c. boundaryCoef (j));
166 int_t bNum = (q > 0) ?
167 cells [q - 1]. getnumber (bCell) : 0;
177 matrix. add (q, bNum, cNum, bCoef);
183 sout <<
"The boundary matrices created in " << constrTime <<
".\n";
186 sout <<
"Computing the SNF of the boundary operator...\n";
189 matrix. computeSNF (maxDim);
192 sout <<
"The SNF computed in " << snfTime <<
".\n";
199 sout <<
"Composing a chain contraction from the SNF...\n";
200 timeused composingTime;
205 multitable<AlgMapType> psi;
208 multitable<tCombLinMap<AlgCellType,CellT> > representants;
215 for (
int q = 0; q < maxDim; ++ q)
221 int_t nCols = cells [q]. size ();
222 for (int_t cell = 0; cell < nCols; ++ cell)
225 int_t bcell = matrix. getColCell (q, cell);
226 bool torsionCell =
false;
232 const CoefT e (matrix. getColCoef (q, cell));
233 const int delta (e. delta ());
236 const AlgCellType dom (bcell);
237 const AlgCellType img (cell);
239 psi [q - 1]. add (dom, img, e);
244 const AlgCellType c (bcell);
245 B. push_back (representants [q - 1].
246 getImage (c). getCell (0));
255 bool torsionImage =
false;
258 CoefT e (matrix. getRowCoef (q + 1, cell));
261 if (e. delta () == 1)
265 else if (e. delta () > 1)
276 const CellT &repr = cells [q] [genNumber];
277 representants [q]. add (AlgCellType (cell), repr);
281 else if (!torsionImage)
285 const AlgChainType genChain
286 (matrix. getOldChain (q, cell));
289 int_t genSize = genChain. size ();
290 for (int_t j = 0; j < genSize; ++ j)
292 int_t n = genChain. getCell (j). getId ();
293 CoefT e = genChain. getCoef (j);
294 const CellT &genCell = cells [q] [n];
295 incl. add (repr, genCell, e);
301 const AlgChainType piRow
302 (matrix. getNewChainRow (q, cell));
303 int_t piRowSize = piRow. size ();
304 for (int_t j = 0; j < piRowSize; ++ j)
306 int_t n = piRow. getCell (j). getId ();
307 CoefT e = piRow. getCoef (j);
308 const CellT &cell = cells [q] [n];
309 pi. add (cell, repr, e);
316 sout <<
"Transferring the computed chain contraction " 317 "to the original basis...\n";
318 for (
int q = 1; q < maxDim; ++ q)
321 int_t nCells (cells [q - 1]. size ());
322 for (int_t cell = 0; cell < nCells; ++ cell)
325 AlgChainType ch (matrix. getNewChain (q - 1, cell));
328 AlgChainType psich (psi [q - 1] (ch));
331 AlgChainType algImage;
332 int_t size (psich. size ());
333 for (int_t i = 0; i < size; ++ i)
336 int_t n (psich. getCell (i). getId ());
337 const CoefT &e (psich. getCoef (i));
338 AlgChainType a (matrix. getOldChain (q, n));
345 int_t algSize (algImage. size ());
346 for (int_t i = 0; i < algSize; ++ i)
348 const CoefT &coef (algImage. getCoef (i));
349 int_t n (algImage. getCell (i). getId ());
350 const CellT &cell (cells [q] [n]);
351 image. add (cell, coef);
355 phi. getImage (cells [q - 1] [cell]). swap (image);
360 sout <<
"Chain contraction composed in " << composingTime <<
".\n";
363 sout <<
"AM model computed in " << compTime <<
".\n";
369 #endif // _CHAINCON_AMMODEL_H_ A linear map for coefficients in an arbitrary commutative ring.
This file includes a specific interface to an SNF computation algorithm.
A chain with coefficients in an arbitrary ring.
A combinatorial linear map (for coefficients in Z_2).
An abstract algebraic cell.
A chain with coefficients in an arbitrary commutative ring.
void verifyChangeOfBasisSNF(const MatrixT &matrix, int maxDim)
Verifies if the change of basis matrices match each other.
void algMinModel(const tFilteredComplex< CellT > &K, CellArray1 &H, CellArray2 &A, CellArray3 &B, CoefArray &Q, tLinMap< CellT, CellT, CoefT > &pi, tLinMap< CellT, CellT, CoefT > &incl, tLinMap< CellT, CellT, CoefT > &phi)
Computes a minimal model for a given filtered finite cell complex "K".
An abstract algebraic cell, characterized by a unique identifier, dimension, and a formula for its bo...
An interface for the computation of the Smith Normal Form of a series of a few rectangular matrices w...