Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _COMPHOM_H_
00032 #define _COMPHOM_H_
00033
00034
00035
00036 #include <istream>
00037 #include <ostream>
00038
00039
00040 #include "chomp/system/config.h"
00041 #include "chomp/system/timeused.h"
00042 #include "chomp/system/textfile.h"
00043 #include "chomp/struct/hashsets.h"
00044
00045
00046 #include "chaincon/comblinmap.h"
00047 #include "chaincon/filtcomplex.h"
00048 #include "chaincon/homgvf.h"
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 template <class CellT>
00061 void computeHomology (const char *filename,
00062 chomp::homology::hashedset<CellT> &H,
00063 tCombLinMap<CellT, CellT> &pi,
00064 tCombLinMap<CellT, CellT> &incl,
00065 tCombLinMap<CellT, CellT> &phi,
00066 bool displayPi, bool displayIncl, bool displayPhi,
00067 bool verify, int algorithmVersion)
00068 {
00069 using chomp::homology::sout;
00070
00071
00072 tFilteredComplex<CellT> K;
00073 {
00074 sout << "Reading '" << filename << "'... ";
00075 std::ifstream in (filename);
00076 if (!in)
00077 chomp::homology::fileerror (filename);
00078 in >> K;
00079 in. close ();
00080 sout << K. size () << " cells read.\n";
00081 }
00082
00083
00084
00085 sout << "Adding boundaries... ";
00086 addBoundaries (K);
00087 sout << K. size () << " cells total.\n";
00088
00089
00090
00091 homologyGVF (K, H, pi, incl, phi, algorithmVersion);
00092
00093
00094 if (displayPi)
00095 sout << "The projection map pi:\n" << pi;
00096 if (displayIncl)
00097 sout << "The inclusion map incl:\n" << incl;
00098 if (displayPhi)
00099 sout << "The homology gradient vector field phi:\n" << phi;
00100
00101
00102 sout << "Homology representants (ordered by dimension):\n";
00103 int_t Hsize = H. size ();
00104 int_t displayed = 0;
00105 for (int dim = 0; displayed < Hsize; ++ dim)
00106 {
00107 for (int_t i = 0; i < Hsize; ++ i)
00108 {
00109 if (H [i]. dim () != dim)
00110 continue;
00111 sout << "gen_" << (displayed ++) << ": " <<
00112 H [i] << "\n";
00113 }
00114 }
00115
00116
00117 tCombLinMap<CellT, CellT> boundaryMap;
00118
00119
00120 if (verify)
00121 {
00122 computeBoundaryMap (K, boundaryMap);
00123 if (phi * boundaryMap * phi == phi)
00124 sout << "Verified: 'phi bd phi = phi'.\n";
00125 else
00126 sout << "Failed to verify that "
00127 "'phi pd phi = phi'.\n";
00128
00129 if (boundaryMap * phi * boundaryMap == boundaryMap)
00130 sout << "Verified: 'bd phi bd = bd'.\n";
00131 else
00132 sout << "Failed to verify that 'bd phi pd = bd'.\n";
00133
00134 tCombLinMap<CellT, CellT> zeroMap;
00135 if (phi * phi == zeroMap)
00136 sout << "Verified: 'phi phi = 0'.\n";
00137 else
00138 sout << "Failed to verify that 'phi phi = 0'.\n";
00139
00140 tCombLinMap<CellT, CellT> composition (boundaryMap * phi);
00141 composition. add (phi * boundaryMap);
00142 addIdentity (K, composition);
00143 if (incl * pi == composition)
00144 sout << "Verified: 'i pi = id - bd phi - phi bd'.\n";
00145 else
00146 sout << "Failed to verify that "
00147 "'i pi = id - bd phi - phi bd'.\n";
00148
00149 tCombLinMap<CellT, CellT> idH;
00150 addIdentity (H, idH);
00151 if (pi * incl == idH)
00152 sout << "Verified: 'pi i = id_H'.\n";
00153 else
00154 sout << "Failed to verify that 'pi i = id_H'.\n";
00155
00156 if (pi * phi == zeroMap)
00157 sout << "Verified: 'pi phi = 0'.\n";
00158 else
00159 sout << "Failed to verify that 'pi phi = 0'.\n";
00160
00161 if (phi * incl == zeroMap)
00162 sout << "Verified: 'phi i = 0'.\n";
00163 else
00164 sout << "Failed to verify that 'phi i = 0'.\n";
00165 }
00166
00167 return;
00168 }
00169
00170
00171 #endif // _COMPHOM_H_
00172