The ChainCon Software (Release 0.03)
atmodel1.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// Algebraic topological model computation: Algorithm 1, new version,
6 /// but still without computing the transpose of the projection;
7 /// combinatorial version - for coefficients in Z_2.
8 ///
9 /////////////////////////////////////////////////////////////////////////////
10 
11 // Copyright (C) 2009-2016 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 <http://www.gnu.org/licenses/>.
26 
27 // Started on March 24, 2009. Last revision: March 24, 2011.
28 
29 
30 #ifndef _CHAINCON_ATMODEL1_H_
31 #define _CHAINCON_ATMODEL1_H_
32 
33 
34 // include some standard C++ header files
35 #include <istream>
36 #include <ostream>
37 
38 // include selected header files from the CHomP library
39 #include "chomp/system/config.h"
40 #include "chomp/system/textfile.h"
41 #include "chomp/system/timeused.h"
42 #include "chomp/struct/hashsets.h"
43 
44 // include relevant local header files
45 #include "chaincon/combchain.h"
46 #include "chaincon/comblinmap.h"
47 
48 
49 // --------------------------------------------------
50 // -------------------- AT model --------------------
51 // --------------------------------------------------
52 
53 /// Computes an algebraic topological model for the given
54 /// filtered finite cell complex "K".
55 /// Cells that represent homology generators are appended to the vector "H".
56 /// The projection map "pi", the inclusion from "H" to the complex "K",
57 /// and the homology gradient vector field "phi"
58 /// are assumed to be initially zero and are constructed.
59 template <class CellT, class CellArray1, class CellArray2, class CellRestrT>
60 void algTopModel1 (const CellArray1 &K, CellArray2 &H,
64  const CellRestrT &restr)
65 {
66  using chomp::homology::sout;
67  using chomp::homology::scon;
68  using chomp::homology::sbug;
69 
70  // don't do anything for an empty complex
71  if (K. empty ())
72  return;
73 
74  // show a message indicating what is being computed
75  sbug << "[AT Model Algorithm 1.]\n";
76  sout << "Computing an algebraic topological model...\n";
77 
78  // start measuring computation time
79  chomp::homology::timeused compTime;
80  compTime = 0;
81 
82  // prepare a set of cells that represent homology generators
83  chomp::homology::hashedset<CellT> homGener;
84 
85  // process all the cells in the filter
86  int_t KSize = K. size ();
87  for (int_t i = 0; i < KSize; ++ i)
88  {
89  // show progress indicator
90  if (!(i % 17))
91  scon << i << " out of " << KSize << ", " <<
92  (i * 100 / KSize) << "% done.\r";
93 
94  // retrieve the i-th cell in the filter
95  const CellT &c = K [i];
96 
97  // compute the modified cell
98  tCombChain<CellT> cChain;
99  cChain. add (c);
100  tCombChain<CellT> ch (phi (boundary (cChain, restr)));
101  ch. add (c);
102 
103  // compute the boundary of the modified cell
104  tCombChain<CellT> bd_ch (boundary (ch, restr));
105 
106  // if the boundary is zero
107  if (bd_ch. empty ())
108  {
109  // add this cell to the set of homology representants
110  homGener. add (c);
111 
112  // define the inclusion for this cell
113  incl. add (c, ch);
114 
115  // define the projection on this cell
116  pi. add (c, c);
117 
118  // skip the rest
119  continue;
120  }
121 
122  // project the boundary onto the homology generators
123  tCombChain<CellT> d (pi (bd_ch));
124 
125  // make sure that this projection is nontrivial
126  if (d. empty ())
127  {
128  sout << "Debug: c = " << c << ".\n";
129  sout << "Debug: bd_c = " <<
130  boundary (cChain, restr) << ".\n";
131  sout << "Debug: ch = " << ch << ".\n";
132  sout << "Debug: bd_ch = " << bd_ch << ".\n";
133  throw "Empty boundary in the homology algorithm.";
134  }
135 
136  // choose any element of this boundary
137  const CellT &u = d. getCell (0);
138 
139  // go through all the previously processed cells
140  for (int_t j = 0; j < i; ++ j)
141  {
142  // retrieve the j-th cell
143  const CellT &cj = K [j];
144 
145  // compute the chain pi (cj)
146  tCombChain<CellT> cjh (pi (cj));
147 
148  // if u does not appear in this chain
149  // then skip the remaining computations for cj
150  int_t pos = cjh. position (u);
151  if (pos < 0)
152  continue;
153 
154  // compute new phi (cj) by adding ch to it
155  phi. add (cj, ch);
156 
157  // compute the new image of cj by the projection
158  pi. add (cj, d);
159  }
160 
161  // remove the cell from the set of homology representants
162  homGener. remove (u);
163  incl. remove (u);
164  }
165 
166  // copy the computed homology generators
167  int_t genSize = homGener. size ();
168  for (int_t i = 0; i < genSize; ++ i)
169  H. push_back (homGener [i]);
170 
171  // show information on the computation time
172  sout << "AT model computed in " << compTime << ".\n";
173 
174  return;
175 } /* algTopModel1 */
176 
177 
178 #endif // _CHAINCON_ATMODEL1_H_
179 
A combinatorial chain, that is, a chain with Z_2 coefficients.
tCombChain< CellT > boundary(const tCombChain< CellT > &c, const CellRestrT &restr)
Returns the boundary of a given chain (takes boundary cells restricted by the given object...
Definition: boundary.h:156
A combinatorial linear map (for coefficients in Z_2).
void algTopModel1(const CellArray1 &K, CellArray2 &H, tCombLinMap< CellT, CellT > &pi, tCombLinMap< CellT, CellT > &incl, tCombLinMap< CellT, CellT > &phi, const CellRestrT &restr)
Computes an algebraic topological model for the given filtered finite cell complex "K"...
Definition: atmodel1.h:60
A combinatorial chain.
Definition: combchain.h:49
A combinatorial linear map.
Definition: comblinmap.h:56