The Original CHomP Software
engines.h
Go to the documentation of this file.
1
3
14
15// This file copyright (C) 1997-2016 by Pawel Pilarczyk.
16//
17// This file is part of the "chomp" program. It is free software;
18// you can redistribute it and/or modify it under the terms of the GNU
19// General Public License as published by the Free Software Foundation,
20// either version 3 of the License, or (at your option) any later version.
21//
22// This software is distributed in the hope that it will be useful,
23// but WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25// GNU General Public License for more details.
26//
27// You should have received a copy of the GNU General Public License
28// along with this software; see the file "license.txt". If not,
29// please, see <https://www.gnu.org/licenses/>.
30
31// Started in March 2006. Last revision: April 14, 2006.
32
33
34#ifndef _CAPD_HOMENGIN_ENGINES_H_
35#define _CAPD_HOMENGIN_ENGINES_H_
36
37#include "chomp/system/config.h"
40#include "chomp/system/arg.h"
43
44#include "capd/homologicalAlgebra/embeddingDim.h"
45#include "capd/chom/dim.hpp"
46#include "capd/auxil/ofstreamcout.h"
48extern ofstreamcout fcout;
49
52
53#include <cstdlib>
54#include <ctime>
55#include <cstring>
56#include <new>
57#include <exception>
58#include <iostream>
59#include <fstream>
60#include <iomanip>
61#include <vector>
62#include <sstream>
63
64
65namespace chomp {
66
71namespace homengin {
72
73// --------------------------------------------------
74// ---------------- ABSTRACT ENGINE -----------------
75// --------------------------------------------------
76
78class engine
79{
80public:
82 typedef std::vector<const engine *> enginelist;
83
86
87protected:
90 {
91 engines. push_back (this);
92 return;
93 }
94
96 virtual ~engine ()
97 {
98 enginelist::iterator it = std::find (engines. begin (),
99 engines. end (), this);
100 if (it != engines. end ())
101 engines. erase (it);
102 return;
103 }
104
105public:
107 virtual int speed () const
108 {
109 return 0;
110 }
111
113 virtual bool dimsupported (int dim) const
114 {
115 return false;
116 }
117
120 virtual int memory (const cubfile &X) const
121 {
122 return 0;
123 }
124
126 virtual bool relative () const
127 {
128 return false;
129 }
130
132 virtual bool elementary () const
133 {
134 return false;
135 }
136
138 virtual bool spacewrapping () const
139 {
140 return false;
141 }
142
144 virtual void homology (const cubfile &x,
146 {
147 throw "Homology computation not supported.";
148 }
149
151 virtual void homology (const cubfile &x, const cubfile &y,
153 {
154 throw "Relative homology computation not supported.";
155 }
156
158 virtual const char *name () const
159 {
160 return "";
161 }
162
164 virtual std::ostream &describe (std::ostream &out) const
165 {
166 out << "This is an unknown homology engine.\n";
167 return out;
168 }
169
171 static std::ostream &showlist (std::ostream &out,
172 const engine::enginelist &elist = engine::engines);
173
176 static const engine *find (const cubfile *X, const cubfile *Y,
177 const engine::enginelist &elist = engine::engines);
178
181 static const engine *find (const cubfile *X,
182 const engine::enginelist &elist = engine::engines)
183 {
184 return find (X, 0, elist);
185 }
186
189 static const engine *find (const char *name,
190 const engine::enginelist &elist = engine::engines);
191
192private:
193}; /* class engine */
194
195
196// --------------------------------------------------
197// ------------------- PP ENGINE --------------------
198// --------------------------------------------------
199
201class PPengine: public engine
202{
203protected:
206 {
207 return;
208 }
209
212 {
213 return;
214 }
215
216public:
218 int speed () const
219 {
220 return 100;
221 }
222
224 bool dimsupported (int dim) const
225 {
226 return (dim > 0) && (dim <= chomp::homology::Cube::MaxDim);
227 }
228
231 int memory (const cubfile &X) const;
232
234 bool relative () const
235 {
236 return true;
237 }
238
240 bool elementary () const
241 {
242 return true;
243 }
244
246 bool spacewrapping () const
247 {
248 return true;
249 }
250
252 void homology (const cubfile &x,
254
256 void homology (const cubfile &x, const cubfile &y,
258
260 const char *name () const
261 {
262 return "PP";
263 }
264
266 std::ostream &describe (std::ostream &out) const;
267
269 static PPengine eng;
270
271}; /* class PPengine */
272
273
274// --------------------------------------------------
275// ------------------- BK ENGINE --------------------
276// --------------------------------------------------
277
279class BKengine: public engine
280{
281protected:
284 {
285 return;
286 }
287
290 {
291 return;
292 }
293
294public:
296 int speed () const
297 {
298 return 250;
299 }
300
302 bool dimsupported (int dim) const
303 {
304 return (dim == DIM);
305 }
306
309 int memory (const cubfile &X) const;
310
312 bool relative () const
313 {
314 return false;
315 }
316
318 bool elementary () const
319 {
320 return false;
321 }
322
324 bool spacewrapping () const
325 {
326 return false;
327 }
328
330 void homology (const cubfile &x,
332
334 void homology (const cubfile &x, const cubfile &y,
336 {
337 throw "The BK engine cannot compute relative homology.";
338 }
339
341 const char *name () const
342 {
343 return "BK";
344 }
345
347 std::ostream &describe (std::ostream &out) const;
348
350 static BKengine eng;
351
352protected:
355
356}; /* class BKengine */
357
358
359// --------------------------------------------------
360// ------------------ BK_LT ENGINE ------------------
361// --------------------------------------------------
362
366{
367protected:
370 {
371 useLookupTable = true;
372 return;
373 }
374
377 {
378 return;
379 }
380
381public:
383 int speed () const
384 {
385 return 260;
386 }
387
389 const char *name () const
390 {
391 return "BK_LT";
392 }
393
395 std::ostream &describe (std::ostream &out) const;
396
399
400}; /* class BK_LTengine */
401
402
403// --------------------------------------------------
404// -------------- A GENERAL MM ENGINE ---------------
405// --------------------------------------------------
406
408class MMengine: public engine
409{
410protected:
413 {
414 return;
415 }
416
419 {
420 return;
421 }
422
423public:
425 virtual int speed () const = 0;
426
428 bool dimsupported (int dim) const
429 {
430 return (dim == embeddingDim);
431 }
432
435 int memory (const cubfile &X) const;
436
438 bool relative () const
439 {
440 return false;
441 }
442
444 bool elementary () const
445 {
446 return false;
447 }
448
450 bool spacewrapping () const
451 {
452 return false;
453 }
454
456 virtual void homology (const cubfile &x,
458
460 void homology (const cubfile &x, const cubfile &y,
462 {
463 throw "The MM* engines do not support relative homology.";
464 }
465
467 virtual const char *name () const = 0;
468
470 virtual std::ostream &describe (std::ostream &out) const = 0;
471
472protected:
473}; /* class MMengine */
474
475
476// --------------------------------------------------
477// ------------------ MM_CR ENGINE ------------------
478// --------------------------------------------------
479
482{
483protected:
486 {
487 return;
488 }
489
492 {
493 return;
494 }
495
496public:
498 int speed () const
499 {
500 return 5000;
501 }
502
504 bool dimsupported (int dim) const
505 {
506 return ((dim == embeddingDim) || ((dim >= 2) && (dim <= 4)));
507 }
508
510 void homology (const cubfile &x,
512
514 const char *name () const
515 {
516 return "MM_CR";
517 }
518
520 std::ostream &describe (std::ostream &out) const;
521
524
525}; /* class MM_CRengine */
526
527
528// --------------------------------------------------
529// ------------------ MM_AR ENGINE ------------------
530// --------------------------------------------------
531
534{
535protected:
538 {
539 return;
540 }
541
544 {
545 return;
546 }
547
548public:
550 int speed () const
551 {
552 return 70;
553 }
554
556 bool dimsupported (int dim) const
557 {
558 return ((dim == embeddingDim) || ((dim >= 2) && (dim <= 4)));
559 }
560
562 void homology (const cubfile &x,
564
566 const char *name () const
567 {
568 return "MM_AR";
569 }
570
572 std::ostream &describe (std::ostream &out) const;
573
576
577}; /* class MM_ARengine */
578
579
580// --------------------------------------------------
581// ----------------- MM_ASLT ENGINE -----------------
582// --------------------------------------------------
583
586{
587protected:
590 {
591 return;
592 }
593
596 {
597 return;
598 }
599
600public:
602 int speed () const
603 {
604 return 1000;
605 }
606
608 void homology (const cubfile &x,
610
612 const char *name () const
613 {
614 return "MM_ASLT";
615 }
616
618 std::ostream &describe (std::ostream &out) const;
619
622
623}; /* class MM_ASLTengine */
624
625
626} // namespace homengin
627} // namespace chomp
628
629#endif // _CAPD_HOMENGIN_ENGINES_H_
630
632
This file defines an algebraic data structure which is used to store the information about computed h...
This file contains the definition of a class which can be used to parse the command line of a program...
This file contains various procedures for the homology computation.
The homology engine that uses the Bill Kalies' engine: the version which uses the lookup table for re...
Definition: engines.h:366
BK_LTengine()
The default constructor.
Definition: engines.h:369
static BK_LTengine eng
One instance of this engine.
Definition: engines.h:398
std::ostream & describe(std::ostream &out) const
Describes this particular engine.
int speed() const
The speed of the engine: The higher the number, the better.
Definition: engines.h:383
const char * name() const
The name of the engine to be used in the command line.
Definition: engines.h:389
~BK_LTengine()
The destructor.
Definition: engines.h:376
The homology engine that uses the Bill Kalies' engine.
Definition: engines.h:280
void homology(const cubfile &x, const cubfile &y, algstruct< chomp::homology::integer > &h) const
Compute the relative homology of the given pair of sets of cubes.
Definition: engines.h:334
int memory(const cubfile &X) const
Rough memory usage estimate for a single set of cubes.
bool dimsupported(int dim) const
Is this dimension supported by this engine?
Definition: engines.h:302
const char * name() const
The name of the engine to be used in the command line.
Definition: engines.h:341
int speed() const
The speed of the engine: The higher the number, the better.
Definition: engines.h:296
bool elementary() const
Is this engine capable of processing elementary cubes?
Definition: engines.h:318
std::ostream & describe(std::ostream &out) const
Describes this particular engine.
~BKengine()
The destructor.
Definition: engines.h:289
void homology(const cubfile &x, algstruct< chomp::homology::integer > &h) const
Compute the homology of the given set of cubes.
static BKengine eng
One instance of this engine.
Definition: engines.h:350
bool spacewrapping() const
Does this engine support space wrapping?
Definition: engines.h:324
bool relative() const
Does this engine compute relative homology?
Definition: engines.h:312
bool useLookupTable
Should the lookup table be used prior to the homology computation?
Definition: engines.h:354
BKengine()
The default constructor.
Definition: engines.h:283
The MM_AR engine.
Definition: engines.h:534
std::ostream & describe(std::ostream &out) const
Describes this particular engine.
const char * name() const
The name of the engine to be used in the command line.
Definition: engines.h:566
~MM_ARengine()
The destructor.
Definition: engines.h:543
int speed() const
The speed of the engine: The higher the number, the better.
Definition: engines.h:550
bool dimsupported(int dim) const
Is this dimension supported by this engine?
Definition: engines.h:556
MM_ARengine()
The default constructor.
Definition: engines.h:537
void homology(const cubfile &x, algstruct< chomp::homology::integer > &h) const
Compute the homology of the given set of cubes.
static MM_ARengine eng
One instance of this engine.
Definition: engines.h:575
The MM_ASLT engine.
Definition: engines.h:586
MM_ASLTengine()
The default constructor.
Definition: engines.h:589
static MM_ASLTengine eng
One instance of this engine.
Definition: engines.h:621
void homology(const cubfile &x, algstruct< chomp::homology::integer > &h) const
Compute the homology of the given set of cubes.
int speed() const
The speed of the engine: The higher the number, the better.
Definition: engines.h:602
const char * name() const
The name of the engine to be used in the command line.
Definition: engines.h:612
~MM_ASLTengine()
The destructor.
Definition: engines.h:595
std::ostream & describe(std::ostream &out) const
Describes this particular engine.
The MM_CR engine.
Definition: engines.h:482
const char * name() const
The name of the engine to be used in the command line.
Definition: engines.h:514
void homology(const cubfile &x, algstruct< chomp::homology::integer > &h) const
Compute the homology of the given set of cubes.
int speed() const
The speed of the engine: The higher the number, the better.
Definition: engines.h:498
static MM_CRengine eng
One instance of this engine.
Definition: engines.h:523
MM_CRengine()
The default constructor.
Definition: engines.h:485
bool dimsupported(int dim) const
Is this dimension supported by this engine?
Definition: engines.h:504
~MM_CRengine()
The destructor.
Definition: engines.h:491
std::ostream & describe(std::ostream &out) const
Describes this particular engine.
A general class for the MM* bitmap-based engines.
Definition: engines.h:409
virtual const char * name() const =0
The name of the engine to be used in the command line.
virtual std::ostream & describe(std::ostream &out) const =0
Describes this particular engine.
bool spacewrapping() const
Does this engine support space wrapping?
Definition: engines.h:450
~MMengine()
The destructor.
Definition: engines.h:418
bool elementary() const
Is this engine capable of processing elementary cubes?
Definition: engines.h:444
virtual void homology(const cubfile &x, algstruct< chomp::homology::integer > &h) const =0
Compute the homology of the given set of cubes.
bool relative() const
Does this engine compute relative homology?
Definition: engines.h:438
virtual int speed() const =0
The speed of the engine: The higher the number, the better.
bool dimsupported(int dim) const
Is this dimension supported by this engine?
Definition: engines.h:428
int memory(const cubfile &X) const
Rough memory usage estimate for a single set of cubes.
MMengine()
The default constructor.
Definition: engines.h:412
void homology(const cubfile &x, const cubfile &y, algstruct< chomp::homology::integer > &h) const
Compute the relative homology of the given pair of sets of cubes.
Definition: engines.h:460
The homology engine that uses lists of cubes (Pawel Pilarczyk).
Definition: engines.h:202
bool elementary() const
Is this engine capable of processing elementary cubes?
Definition: engines.h:240
void homology(const cubfile &x, const cubfile &y, algstruct< chomp::homology::integer > &h) const
Compute the relative homology of the given pair of sets of cubes.
~PPengine()
The destructor.
Definition: engines.h:211
int memory(const cubfile &X) const
Rough memory usage estimate for a single set of cubes.
bool relative() const
Does this engine compute relative homology?
Definition: engines.h:234
const char * name() const
The name of the engine to be used in the command line.
Definition: engines.h:260
std::ostream & describe(std::ostream &out) const
Describes this particular engine.
bool spacewrapping() const
Does this engine support space wrapping?
Definition: engines.h:246
bool dimsupported(int dim) const
Is this dimension supported by this engine?
Definition: engines.h:224
void homology(const cubfile &x, algstruct< chomp::homology::integer > &h) const
Compute the homology of the given set of cubes.
static PPengine eng
One instance of this engine.
Definition: engines.h:269
int speed() const
The speed of the engine: The higher the number, the better.
Definition: engines.h:218
PPengine()
The default constructor.
Definition: engines.h:205
An algebraic structure that represents a finitely generated Abelian group with gradation.
Definition: algstruct.h:68
An abstract class that is inherited by all the cubical sets.
Definition: cubfiles.h:63
An abstract class that is inherited by all the homology engines.
Definition: engines.h:79
std::vector< const engine * > enginelist
The type of a list of engines.
Definition: engines.h:82
virtual std::ostream & describe(std::ostream &out) const
Describes this particular engine.
Definition: engines.h:164
static const engine * find(const cubfile *X, const cubfile *Y, const engine::enginelist &elist=engine::engines)
Finds the most appropriate homology engine.
static std::ostream & showlist(std::ostream &out, const engine::enginelist &elist=engine::engines)
Shows a list of available homology engines with descriptions.
virtual bool relative() const
Does this engine compute relative homology?
Definition: engines.h:126
static const engine * find(const cubfile *X, const engine::enginelist &elist=engine::engines)
Finds the most appropriate homology engine for just one set.
Definition: engines.h:181
virtual int speed() const
The speed of the engine: The higher the number, the better.
Definition: engines.h:107
virtual bool dimsupported(int dim) const
Is this dimension supported by this engine?
Definition: engines.h:113
virtual int memory(const cubfile &X) const
Rough memory usage estimate for a single set of cubes.
Definition: engines.h:120
virtual bool elementary() const
Is this engine capable of processing elementary cubes?
Definition: engines.h:132
static enginelist engines
A list of all the engines that have been defined so far.
Definition: engines.h:85
virtual const char * name() const
The name of the engine to be used in the command line.
Definition: engines.h:158
virtual void homology(const cubfile &x, const cubfile &y, algstruct< chomp::homology::integer > &h) const
Compute the relative homology of the given pair of sets of cubes.
Definition: engines.h:151
engine()
The default constructor: Add the engine to the list.
Definition: engines.h:89
virtual void homology(const cubfile &x, algstruct< chomp::homology::integer > &h) const
Compute the homology of the given set of cubes.
Definition: engines.h:144
virtual ~engine()
The destructor: Remove the engine from the list.
Definition: engines.h:96
virtual bool spacewrapping() const
Does this engine support space wrapping?
Definition: engines.h:138
static const engine * find(const char *name, const engine::enginelist &elist=engine::engines)
Finds a homology engine with the given name.
static const int MaxDim
The maximal dimension of a cube.
Definition: cubebase.h:81
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
This file defines various types of cubical sets whose homology can be computed by homology engines.
ofstreamcout fcout
An output stream defined by M. Mrozek in the CAPD library.
This file contains various small procedures that might be useful in programs which compute homology.
This namespace contains the entire CHomP library interface.
Definition: bitmaps.h:51
This file contains some useful functions related to the text input/output procedures.
This file defines a simple data structure which can be used to measure time used by the program (or s...