The ChainCon Software (Release 0.03)
snf.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// This file includes a specific interface to an SNF computation algorithm.
6 /// In the default setting it uses the algorithm from the CHomP package,
7 /// but you are welcome to use another, hopefully more efficient algorithm.
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: June 26, 2012.
28 
29 
30 #ifndef _CHAINCON_SNF_H_
31 #define _CHAINCON_SNF_H_
32 
33 
34 // include some standard C++ header files
35 #include <algorithm>
36 
37 // include selected header files from the CHomP library
38 #include "chomp/system/config.h"
39 
40 // include relevant local header files
41 #include "chaincon/filtcomplex.h"
42 #include "chaincon/chain.h"
43 
44 
45 // --------------------------------------------------
46 // --------- the choice of an SNF algorithm ---------
47 // --------------------------------------------------
48 
49 #include "chaincon/snfchomp.h"
50 
51 
52 // --------------------------------------------------
53 // ---------------- SNF verification ----------------
54 // --------------------------------------------------
55 
56 /// Verifies if the change of basis matrices match each other.
57 /// Displays messages and throws an exception in case of a failure.
58 template <class MatrixT>
59 void verifyChangeOfBasisSNF (const MatrixT &matrix, int maxDim)
60 {
61  using chomp::homology::sout;
62  using chomp::homology::timeused;
63 
64  typedef typename MatrixT::ChainType AlgChainType;
65 // typedef typename MatrixT::CoefType CoefType;
66 
67  timeused verifTime;
68  verifTime = 0;
69  sout << "Change of basis check: ";
70 
71  for (int q = 0; q < maxDim; ++ q)
72  {
73  int_t nColumns = matrix. getNumCols (q);
74  for (int_t n = 0; n < nColumns; ++ n)
75  {
76  AlgChainType ch (matrix. getNewChain (q, n));
77  AlgChainType result;
78  int_t size = ch. size ();
79  for (int_t i = 0; i < size; ++ i)
80  {
81  AlgChainType part (matrix. getOldChain
82  (q, ch. getCell (i). getId ()));
83  part *= ch. getCoef (i);
84  result += part;
85  }
86  if (!(result. size () == 1) ||
87  !(result. getCell (0). getId () == n) ||
88  !(result. getCoef (0) == 1))
89  {
90  throw "Wrong change of basis (1).";
91  }
92  }
93  for (int_t n = 0; n < nColumns; ++ n)
94  {
95  AlgChainType ch (matrix. getOldChain (q, n));
96  AlgChainType result;
97  int_t size = ch. size ();
98  for (int_t i = 0; i < size; ++ i)
99  {
100  AlgChainType part (matrix. getNewChain
101  (q, ch. getCell (i). getId ()));
102  part *= ch. getCoef (i);
103  result += part;
104  }
105  if (!(result. size () == 1) ||
106  !(result. getCell (0). getId () == n) ||
107  !(result. getCoef (0) == 1))
108  {
109  throw "Wrong change of basis (2).";
110  }
111  }
112  }
113  sout << "Completed in " << verifTime << ".\n";
114 
115  return;
116 } /* verifyChangeOfBasisSNF */
117 
118 
119 #endif // _CHAINCON_SNF_H_
120 
An interface to the SNF computation using the CHomP software package.
A filtered cell complex.
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.
Definition: snf.h:59