The Original CHomP Software
Functions
chomp::homology::reduction0 Namespace Reference

Functions

template<class tCube , class tVerify >
int_t cubreducequiet (const hashedset< tCube > &maincset, hashedset< tCube > &cset, hashedset< tCube > &other, const hashedset< tCube > &keep, const tVerify &verify, bool quiet=true)
 Reduces a pair of sets of cubes for relative homology computation. More...
 
template<class tCube , class tVerify >
int_t cubexpand (hashedset< tCube > &cset, hashedset< tCube > &other, const tVerify &verify, bool quiet=false)
 Expands the set 'other' towards 'cset' without changing the homology of (cset + other, other). More...
 

Function Documentation

◆ cubexpand()

template<class tCube , class tVerify >
int_t chomp::homology::reduction0::cubexpand ( hashedset< tCube > &  cset,
hashedset< tCube > &  other,
const tVerify &  verify,
bool  quiet = false 
)

Expands the set 'other' towards 'cset' without changing the homology of (cset + other, other).

The two sets must be disjoint. Use an externally defined additional criterion for the verification if the cubes that look good for removal are actually allowed to be removed.

Definition at line 239 of file cubired0.h.

241{
242 // if the case is trivial, return the answer
243 if (cset. empty () || other. empty ())
244 return 0;
245
246 // remember the initial number of cubes in the main set
247 int_t prev = cset. size ();
248
249 // determine the space dimension
250 int dim = cset [0]. dim ();
251
252 // compute the maximal number of neighbors of a cube
253 int_t maxneighbors = getmaxneighbors (dim);
254
255 // prepare a bitfield and allocate it if necessary
256 static BitField b;
257 static int_t _maxneighbors = 0;
258 static auto_array<unsigned char> buffer;
259 if (maxneighbors != _maxneighbors)
260 {
261 _maxneighbors = maxneighbors;
262 buffer. reset (new unsigned char [(maxneighbors + 7) >> 3]);
263 b. define (buffer. get (), maxneighbors);
264 }
265
266 // prepare a counter for displaying the progress of computations
267 int_t count = 0;
268
269 // repeat scanning cubes until no change can be made
270 while (1)
271 {
272 // remember if any changes were made in this round
273 bool modified (false);
274
275 // go through the main set, and move cubes to the other set
276 // if this doesn't change the homology
277 for (int_t i = 0; i < cset. size (); ++ i)
278 {
279 // show progress indicator
280 ++ count;
281 if (!quiet && !(count % 373))
282 scon << std::setw (10) << count <<
283 "\b\b\b\b\b\b\b\b\b\b";
284
285 // take a cube from 'cset'
286 const tCube &c = cset [i];
287
288 // clear the neighborbits
289 b. clearall (maxneighbors);
290
291 // if the neighborhood of the cube is not acyclic, skip it
292 if (!acyclic (c, dim, other, &b, maxneighbors))
293 continue;
294
295 // verify if moving this cube to 'other' is allowed
296 if (!verify (c, cset, other))
297 continue;
298
299 // move the cube to the other set
300 modified = true;
301 if (!quiet)
302 sseq << "L\n" << '2' << c << '\n';
303 other. add (c);
304 cset. removenum (i);
305 -- i;
306 }
307
308 // if the sets were not modified then quit the loop
309 if (!modified)
310 break;
311 }
312
313 // return the number of cubes removed from 'cset'
314 return prev - cset. size ();
315} /* cubexpand */
This class defines a bit field that is part of some larger array or that uses an allocated piece of m...
Definition: bitfield.h:73
An auto_array template that mimics selected behaviors of the std::auto_ptr template,...
Definition: autoarray.h:54
int int_t
Index type for indexing arrays, counting cubes, etc.
Definition: config.h:115
outputstream sseq
An auxiliary stream which captures sequences of processed data.
bool acyclic(int dim, BitField &b)
Checks whether this cube's nieghbors form an acyclic set.
Definition: cubacycl.h:70
int_t getmaxneighbors(int dim)
Returns the maximal number of neighbors of a cube: 3^dim - 1.
Definition: neighbor.h:60
outputstream scon
The console output stream to which one should put all the junk that spoils the log file,...

References chomp::homology::acyclic(), chomp::homology::getmaxneighbors(), chomp::homology::scon, and chomp::homology::sseq.

◆ cubreducequiet()

template<class tCube , class tVerify >
int_t chomp::homology::reduction0::cubreducequiet ( const hashedset< tCube > &  maincset,
hashedset< tCube > &  cset,
hashedset< tCube > &  other,
const hashedset< tCube > &  keep,
const tVerify &  verify,
bool  quiet = true 
)

Reduces a pair of sets of cubes for relative homology computation.

The pair is (maincset + cset + other, other), where the cubes in maincset are not to be removed (this is like the "core" of the pair that should be fixed),, the cubes in cset and other are to be considered for removal and could be removed if this is found feasible. The sets maincset + cset and other are disjoint. Does not remove any cubes that are listed in the set keep. Does additional verification, e.g., makes sure that the acyclicity of the given map is preserved. If 'quiet' is set to true then suppresses any messages. Returns the number of cubes removed from both sets.

Definition at line 84 of file cubired0.h.

88{
89 // remember the initial number of cubes in both sets
90 int_t prev = cset. size () + other. size ();
91
92 // if the case is trivial, return the answer
93 if (maincset. empty () && cset. empty ())
94 {
95 if (!other. empty ())
96 {
97 hashedset<tCube> empty;
98 other = empty;
99 }
100 return prev;
101 }
102
103 // determine the space dimension
104 int dim = (cset. empty ()) ? maincset [0]. dim () :
105 cset [0]. dim ();
106
107 // compute the maximal number of neighbors of a cube
108 int_t maxneighbors = getmaxneighbors (dim);
109
110 // prepare a bitfield for storing neighborhood configurations
111 // and allocate the buffer if necessary (this is a static variable)
112 static BitField b;
113 static int_t _maxneighbors = 0;
114 static auto_array<unsigned char> buffer;
115 if (maxneighbors != _maxneighbors)
116 {
117 _maxneighbors = maxneighbors;
118 buffer. reset (new unsigned char [(maxneighbors + 7) >> 3]);
119 b. define (buffer. get (), maxneighbors);
120 }
121
122 // prepare a counter for displaying the progress of computations
123 int_t count = 0;
124
125 // repeat scanning cubes until no change can be made
126 while (1)
127 {
128 // remember if any changes were made in this round
129 bool modified (false);
130
131 // scan all the cubs in both sets
132 for (int_t i = 0; i < cset. size () + other. size (); ++ i)
133 {
134 // show the progress indicator
135 ++ count;
136 if (!quiet && !(count % 373))
137 scon << std::setw (10) << count <<
138 "\b\b\b\b\b\b\b\b\b\b";
139
140 // is this cube from the other set?
141 bool is_other (i >= cset. size ());
142
143 // determine the cube corresponding to the index
144 const tCube &c (is_other ?
145 other [i - cset. size ()] : cset [i]);
146
147 // if this cube is to be kept then skip it
148 if (keep. check (c))
149 continue;
150
151 // clean the neighborbits
152 b. clearall (maxneighbors);
153
154 // if this cube belongs to the other set...
155 if (is_other)
156 {
157 // no neighbors need to be remembered
158 hashedset<tCube> *no_neighbors (0);
159
160 // check if this cube can be removed
161 if (!acyclic_rel (c, dim,
162 makesetunion (maincset, cset),
163 other, &b, maxneighbors,
164 no_neighbors, no_neighbors))
165 {
166 continue;
167 }
168
169 // verify if the removal of the cube from A is OK
170 if (!verify (c, other))
171 continue;
172
173 // verify if the removal of the cube from X is OK
174 if (!verify (c, makesetunion (maincset,
175 makesetunion (other, cset))))
176 {
177 continue;
178 }
179
180 // remove the cube from the other set
181 modified = true;
182 if (!quiet)
183 sseq << '0' << c << '\n';
184 other. removenum (i - cset. size ());
185 -- i;
186 }
187
188 // otherwise, if this cube belongs to 'cset'...
189 else
190 {
191 // no neighbors need to be remembered
192 hashedset<tCube> *no_neighbors (0);
193
194 // if the neighborhood of the cube
195 // is not acyclic then skip the cube
196 if (!acyclic (c, dim, makesetunion (maincset,
197 makesetunion (cset, other)),
198 &b, maxneighbors, no_neighbors))
199 {
200 continue;
201 }
202
203 // verify if the removal of the cube from X is OK
204 if (!verify (c, makesetunion (maincset,
205 makesetunion (cset, other))))
206 {
207 continue;
208 }
209
210 // remove the cube from 'cset'
211 modified = true;
212 if (!quiet)
213 sseq << '0' << c << '\n';
214 cset. removenum (i);
215 -- i;
216 }
217 }
218
219 // if the sets were not modified then quit the loop
220 if (!modified)
221 break;
222 }
223
224 // return the number of cubes removed from both sets
225 return prev - cset. size () - other. size ();
226} /* cubreducequiet */
bool acyclic_rel(const tCube &q, int dim, const tSet1 &cset, const tSet2 &other, BitField *b, int_t maxneighbors, hashedset< tCube > *neighbors_main, hashedset< tCube > *neighbors_other)
Verifies whether a cube from the other set can be removed.
Definition: cubacycl.h:183
setunion< set1type, set2type > makesetunion(const set1type &set1, const set2type &set2)
Creates an object which represents the union of two sets.
Definition: setunion.h:225

References chomp::homology::acyclic(), chomp::homology::acyclic_rel(), chomp::homology::getmaxneighbors(), chomp::homology::makesetunion(), chomp::homology::scon, and chomp::homology::sseq.