source: git/kernel/linear_algebra/Minor.h @ 266ae3

spielwiese
Last change on this file since 266ae3 was 266ae3, checked in by Hans Schoenemann <hannes@…>, 6 years ago
chg: only one definition for poly/ideal/map/matrix
  • Property mode set to 100644
File size: 34.3 KB
Line 
1#ifndef MINOR_H
2#define MINOR_H
3
4#include "polys/monomials/ring.h"
5#include "kernel/polys.h"
6
7// #include <assert.h>
8#include <string>
9
10
11// using namespace std;
12
13/*! \class MinorKey
14    \brief Class MinorKey can be used for representing keys in a cache for
15    sub-determinantes; see class Cache.
16
17    As such, it is a realization of the template class KeyClass which is used
18    in the declaration of class Cache. Following the documentation of class
19    Cache, we need to implement at least the methods:<br>
20    <c>bool MinorKey::operator< (const MinorKey& key),</c><br>
21    <c>bool MinorKey::operator== (const MinorKey& key),</c><br>
22    MinorKey uses two private arrays of ints \c _rowKey and \c _columnKey to
23    encode rows and columns of a pre-defined matrix. Semantically, the row
24    indices and column indices form the key for caching the value of the
25    corresponding minor.<br>
26    More concretely, let us assume that the pre-defined matrix has
27    <em>32*R+r, r<32,</em> rows and <em>32*C+c, c<32,</em> columns. All row
28    indices can then be captured using R+1 ints, since an int is a
29    32-bit-number (regardless of the platform). The analog holds for the
30    columns. Consequently, each instance of MinorKey encodes the sets of rows
31    and columns which shall belong to the minor of interest (and which shall
32    not).<br>
33    Example: The \c _rowKey with \c _rowKey[1] = 0...011 and
34    \c _rowKey[0] = 0...01101 encodes the rows with indices 33, 32, 3, 2,
35    and 0.
36    \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch
37*/
38class MinorKey
39{
40  private:
41     /**
42     * a pointer to an array[0..k-1] of ints, capturing k*32 bits for
43     * determining which rows of a pre-defined matrix shall belong to the
44     * minor of interest;
45     * for i < j, _rowKey[i] holds lower bits than _rowKey[j]
46     */
47     unsigned int* _rowKey;
48
49     /**
50     * a pointer to an array[0..k-1] of ints, capturing k*32 bits for
51     * determining which columns of a pre-defined matrix shall belong to the
52     * minor of interest;
53     * for i < j, _columnKey[i] holds lower bits than _columnKey[j]
54     */
55     unsigned int* _columnKey;
56
57     /**
58     * the number of ints (i.e. 32-bit-numbers) we need to encode the set of
59     * rows;
60     * If the higest row index is 70, we need 3 blocks of 32 bits to also
61     * encode the 70th bit.
62     */
63     int _numberOfRowBlocks;
64
65     /**
66     * the number of ints (i.e. 32-bit-numbers) we need to encode the set of
67     * columns;
68     * If the higest column index is 70, we need 3 blocks of 32 bits to also
69     * encode the 70th bit.
70     */
71     int _numberOfColumnBlocks;
72
73     /**
74     * Inlined accessor of blockIndex-th element of _rowKey.
75     * @param blockIndex the index of the int to be retrieved
76     * @return an entry of _rowKey
77     */
78     unsigned int getRowKey (const int blockIndex) const;
79
80     /**
81     * Accessor of blockIndex-th element of _columnKey.
82     * @param blockIndex the index of the int to be retrieved
83     * @return an entry of _columnKey
84     */
85     unsigned int getColumnKey (const int blockIndex) const;
86
87     /**
88     * A method for setting the blockIndex-th element of _rowKey.
89     * @param blockIndex the index of the int to be retrieved
90     * @param rowKey the row key to be set
91     */
92     void setRowKey (const int blockIndex, const unsigned int rowKey);
93
94     /**
95     * A method for setting the blockIndex-th element of _columnKey.
96     * @param blockIndex the index of the int to be retrieved
97     * @param columnKey the column key to be set
98     */
99     void setColumnKey (const int blockIndex, const unsigned int columnKey);
100
101     /**
102     * Accessor of _numberOfRowBlocks.
103     * @return the number of 32-bit-blocks needed to encode all rows of the
104     *         minor as a sequence of bits
105     */
106     int getNumberOfRowBlocks () const;
107
108     /**
109     * Accessor of _numberOfColumnBlocks.
110     * @return the number of 32-bit-blocks needed to encode all columns of
111     *         the minor as a sequence of bits
112     */
113     int getNumberOfColumnBlocks () const;
114
115     /**
116     * A method for deleting all entries of _rowKey and _columnKey.
117     */
118     void reset();
119
120     #ifndef SING_NDEBUG
121     /**
122     * A method for counting the number of set bits.
123     * For a == 1, the number of set bits in _rowKey will be counted;
124     * for a == 2 in _columnKey.
125     * This method will only be called in the debug version.
126     * @param a for controlling whether to count in _rowKey or _columnKey
127     * @return the number of set bits either in _rowKey or _columnKey
128     */
129     int getSetBits (const int a) const;
130     #endif
131
132     /**
133     * For letting MinorProcessor see the private methods of this class.
134     */
135     friend class MinorProcessor;
136  public:
137     /**
138     * A constructor for class MinorKey.
139     * The ints given in the array rowKey encode all rows which shall belong
140     * to the minor. Each array entry encodes 32 rows, e.g. the i-th array
141     * entry 0...01101 encodes the rows with absolute matrix row indices
142     * 3+i*32, 2+i*32, and 0+i*32. Analog for columns.
143     * @param lengthOfRowArray the length of the array rowKey
144     * @param rowKey a pointer to an array of ints encoding the set of rows of
145     *        the minor
146     * @param lengthOfColumnArray the length of the array columnKey
147     * @param columnKey a pointer to an array of ints encoding the set of
148     +        columns of the minor
149     */
150     MinorKey (const int lengthOfRowArray = 0,
151               const unsigned int* const rowKey = NULL,
152               const int lengthOfColumnArray = 0,
153               const unsigned int* const columnKey = NULL);
154
155     /**
156     * A setter method for class MinorKey.
157     * Just like the constructor of this class, this method will set all
158     * private fields according to the given parameters. Note that this method
159     * will change the given instance of MinorKey.
160     * @param lengthOfRowArray the length of the array rowKey
161     * @param rowKey a pointer to an array of ints encoding the set of rows of
162     * the minor
163     * @param lengthOfColumnArray the length of the array columnKey
164     * @param columnKey a pointer to an array of ints encoding the set of
165     *        columns of the minor
166     * @see MinorKey::MinorKey (const int lengthOfRowArray, const int* rowKey,
167                                const int lengthOfColumnArray,
168                                const int* columnKey)
169     */
170     void set(const int lengthOfRowArray, const unsigned int* rowKey,
171              const int lengthOfColumnArray, const unsigned int* columnKey);
172
173     /**
174     * A copy constructor.
175     * This method overrides the shallow copy constructor by a self-written
176     * deep copy version.
177     * @param mk the MinorKey to be deep copied
178     */
179     MinorKey (const MinorKey& mk);
180
181     /**
182     * A destructor for deleting an instance.
183     */
184     ~MinorKey ();
185
186     /**
187     * just to make the compiler happy
188     */
189     MinorKey& operator=(const MinorKey&);
190
191     /**
192     * just to make the compiler happy
193     */
194     bool operator==(const MinorKey&) const;
195
196     /**
197     * just to make the compiler happy
198     */
199     bool operator<(const MinorKey&) const;
200
201     /**
202     * A method for retrieving the (0-based) index of the i-th row in the set
203     * of rows encoded in \a this.
204     * Lower values for \c i result in lower absolute row indices.
205     * \par Example:
206     * Applied to the row pattern 10010001101 and i = 3, we get the 0-based
207     * index of the 3-rd set bit counted from the right, i.e. 7.
208     * \par Assertion
209     * The method assumes that there are at least \c i rows encoded in the
210     * given MinorKey.
211     * @param i the relative index of the row, as encoded in \a this
212     * @return (0-based) absolute row index of the i-th row in \a this
213     */
214     int getAbsoluteRowIndex (const int i) const;
215
216     /**
217     * A method for retrieving the (0-based) index of the i-th column in the
218     * set of columns encoded in \a this.
219     * Lower values for \c i result in lower absolute column indices.
220     * \par Example:
221     * Applied to the column pattern 10010001101 and i = 3, we get the 0-based
222     * index of the 3-rd set bit counted from the right, i.e. 7.
223     * \par Assertion
224     * The method assumes that there are at least \c i columns encoded in the
225     * given MinorKey.
226     * @param i the relative index of the column, as encoded in \a this
227     * @return (0-based) absolute column index of the i-th row in \a this
228     */
229     int getAbsoluteColumnIndex (const int i) const;
230
231     /**
232     * A method for retrieving the (0-based) relative index of the i-th row
233     * in \a this MinorKey.
234     * Lower values for \c i result in lower relative row indices. Note that
235     * the absolute index \c i is 0-based, too.
236     * \par Example:
237     * Applied to the row pattern 10010001101 and i = 7, we get the relative
238     * 0-based position of the bit representing the absolute index 7, i.e. 3.
239     * \par Assertion
240     * The method assumes that the bit which corresponds to the absolute index
241     * i is actually set.
242     * @param i the absolute 0-based index of a row encoded in \a this
243     * @return (0-based) relative row index corresponding to \c i
244     */
245     int getRelativeRowIndex (const int i) const;
246
247     /**
248     * A method for retrieving the (0-based) relative index of the i-th column
249     * in \a this MinorKey.
250     * Lower values for \c i result in lower relative column indices. Note that
251     * the absolute index \c i is 0-based, too.
252     * \par Example:
253     * Applied to the column pattern 10010001101 and i = 7, we get the
254     * relative 0-based position of the bit representing the absolute index 7,
255     * i.e. 3.
256     * \par Assertion
257     * The method assumes that the bit which corresponds to the absolute index
258     * i is actually set.
259     * @param i the absolute 0-based index of a column encoded in \a this
260     * @return (0-based) relative column index corresponding to \c i
261     */
262     int getRelativeColumnIndex (const int i) const;
263
264     /**
265     * A method for retrieving the 0-based indices of all rows encoded in \a
266     * this MinorKey.
267     * The user of this method needs to know the number of rows in \a this,
268     * in order to know which indices in \c target[k] will be valid.
269     * \par Example:
270     * The bit pattern <c>0...01101</c> will give rise to the settings
271     * <c>target[0] = 0, target[1] = 2, target[2] = 3</c>, and the user needs
272     * to know in advance that there are three rows in \a this MinorKey.
273     * \par Assertion
274     * The method assumes that target has enough positions for all rows
275     * encoded in \a this MinorKey.
276     * @param target a pointer to some array of ints that is to be filled with
277     *        the requested indices
278     */
279     void getAbsoluteRowIndices(int* const target) const;
280
281     /**
282     * A method for retrieving the 0-based indices of all columns encoded in
283     * \a this MinorKey.
284     * The user of this method needs to know the number of columns in \a this,
285     * in order to know which indices in \c target[k] will be valid.
286     * \par Example:
287     * The bit pattern <c>0...01101</c> will give rise to the settings
288     * <c>target[0] = 0, target[1] = 2, target[2] = 3</c>, and the user needs
289     * to know in advance that there are three columns in \a this MinorKey.
290     * \par Assertion
291     * The method assumes that target has enough positions for all columns
292     * encoded in \a this MinorKey.
293     * @param target a pointer to some array of ints that is to be filled
294     *        with the requested indices
295     */
296     void getAbsoluteColumnIndices(int* const target) const;
297
298     /**
299     * A method for retrieving a sub-MinorKey resulting from omitting one row
300     * and one column of \a this MinorKey.
301     * \par Assertion
302     * The method assumes that the row with absolute index
303     * \c absoluteEraseRowIndex (counted from lower bits to higher bits) and
304     * the column with absolute index \c absoluteEraseColumnIndex are actually
305     * set in \c mk.
306     * @param absoluteEraseRowIndex the 0-based absolute index of a row in
307     *        \a mk
308     * @param absoluteEraseColumnIndex the 0-based absolute index of a column
309     *        in \a mk
310     * @return the MinorKey when omitting the specified row and column
311     */
312     MinorKey getSubMinorKey (const int absoluteEraseRowIndex,
313                              const int absoluteEraseColumnIndex) const;
314
315     /**
316     * A comparator for two instances of MinorKey.
317     * The ordering induced by this implementation determines the ordering of
318     * all (key --> value) pairs in a cache that uses MinorKey as KeyClass.
319     * @param mk a second MinorKey to be compared with \a this instance
320     * @return -1 iff \a this instance is smaller than \a mk; 0 for equality;
321     *         +1 otherwise
322     * @see MinorKey::operator== (const MinorKey&) const
323     */
324     int compare (const MinorKey& mk) const;
325
326     /**
327     * This method redefines the set of rows represented by \a this MinorKey.
328     * After the method, the defined set of rows coincides with the lowest
329     * \c k rows of \c mk. (Here, lowest means w.r.t. indices.)<br>
330     * Note that the method modifies the given instance of MinorKey.
331     * \par Assertion
332     * It is assumed that \c mk represents at least \c k rows.
333     * @param k the number of rows
334     * @param mk the MinorKey from which to choose the lowest \c k rows
335     * @see MinorKey::selectNextRows (const int k, const MinorKey& mk)
336     */
337     void selectFirstRows (const int k, const MinorKey& mk);
338
339     /**
340     * This method redefines the set of rows represented by \a this MinorKey.
341     * Both the old and the new set of \c k rows are subsets of the rows
342     * represented by \c mk. After the method, the defined set of rows is
343     * the next sensible choice of \c k rows of \c mk. (Here, next means
344     * the next w.r.t. the increasing index ordering on multi-indices of
345     * natural numbers.)<br>
346     * Note that the method modifies the given instance of MinorKey.
347     * \par Assertion
348     * It is assumed that \c mk represents at least \c k rows. Furthermore,
349     * the method assumes that the old set of rows represented by \a this
350     * is also a subset of the rows given by \c mk.
351     * @param k the number of rows
352     * @param mk the MinorKey from which to choose the lowest \c k rows
353     * @return true iff there is a next choice of \c k rows
354     * @see MinorKey::selectFirstRows (const int k, const MinorKey& mk)
355     */
356     bool selectNextRows (const int k, const MinorKey& mk);
357
358     /**
359     * This method redefines the set of columns represented by \a this
360     * MinorKey.
361     * After the method, the defined set of columns coincides with the lowest
362     * \c k columns of \c mk. (Here, lowest means w.r.t. indices.)<br>
363     * Note that the method modifies the given instance of MinorKey.
364     * \par Assertion
365     * It is assumed that \c mk represents at least \c k columns.
366     * @param k the number of columns
367     * @param mk the MinorKey from which to choose the lowest \c k columns
368     * @see MinorKey::selectNextColumns (const int k, const MinorKey& mk)
369     */
370     void selectFirstColumns (const int k, const MinorKey& mk);
371
372     /**
373     * This method redefines the set of columns represented by \a this
374     * MinorKey.
375     * Both the old and the new set of \c k columns are subsets of the columns
376     * represented by \c mk. After the method, the defined set of columns is
377     * the next sensible choice of \c k columns of \c mk. (Here, next means
378     * the next w.r.t. the increasing index ordering on multi-indices of
379     * natural numbers.)<br>
380     * Note that the method modifies the given instance of MinorKey.
381     * \par Assertion
382     * It is assumed that \c mk represents at least \c k columns. Furthermore,
383     * the method assumes that the old set of columns represented by \a this
384     * is also a subset of the columns given by \c mk.
385     * @param k the number of columns
386     * @param mk the MinorKey from which to choose the lowest \c k columns
387     * @return true iff there is a next choice of \c k columns
388     * @see MinorKey::selectFirstColumns (const int k, const MinorKey& mk)
389     */
390     bool selectNextColumns (const int k, const MinorKey& mk);
391
392     /**
393     * A method for providing a printable version of the represented MinorKey.
394     * @return a printable version of the given instance as instance of class
395     * string
396     */
397     std::string toString () const;
398
399     /**
400     * A method for printing a string representation of the given MinorKey to
401     * std::cout.
402     */
403     //void print () const;
404};
405
406class MinorValue
407{
408  protected:
409    /**
410    * -1 iff cache is not used, otherwise the number of retrievals so far of
411    * the current minor
412    */
413    int _retrievals;
414
415    /**
416    * -1 iff cache is not used, otherwise the maximum number of potential
417    * retrievals of this minor (e.g. when the minor would be kept in cache
418    * forever)
419    */
420    int _potentialRetrievals;
421
422    /**
423    * a store for the actual number of multiplications to compute the current
424    * minor
425    */
426    int _multiplications;
427
428    /**
429    * a store for the actual number of additions to compute the current minor
430    */
431    int _additions;
432
433    /**
434    * a store for the accumulated number of multiplications to compute the
435    * current minor;
436    * This also includes all multiplications nested in sub-minors which may be
437    * retrieved from a cache. (Thus, these nested operations do not need to be
438    * performed again.)
439    */
440    int _accumulatedMult;
441
442    /**
443    * a store for the accumulated number of additions to compute the current
444    * minor;
445    * This also includes all additions nested in sub-minors which may be
446    * retrieved from a cache. (Thus, these nested operations do not need to be
447    * performed again.)
448    */
449    int _accumulatedSum;
450
451    /**
452    * A method for obtaining a rank measure for the given MinorValue.<br>
453    * Rank measures are used to compare any two instances of MinorValue. The
454    * induced ordering
455    * on MinorValues has an impact on the caching behaviour in a given cache:
456    * Greater MinorValues will be cached longer than lower ones.<br>
457    * More explicitely, this means: Make the return value of this method
458    * greater, and the given MinorValue will be cached longer when caching
459    * strategy 1 is deployed.<br>
460    * Rank measure 1 is equal to the number of actually performed
461    * multiplications to compute \a mv.
462    * @return an integer rank measure of \c this
463    * @see MinorValue::operator< (const MinorValue& mv)
464    */
465    int rankMeasure1 () const;
466
467    /**
468    * A method for obtaining a rank measure for the given MinorValue.<br>
469    * Rank measures are used to compare any two instances of MinorValue. The
470    * induced ordering on MinorValues has an impact on the caching behaviour
471    * in a given cache: Greater MinorValues will be cached longer than lower
472    * ones.<br>
473    * More explicitely, this means: Make the return value of this method
474    * greater, and the given MinorValue will be cached longer when caching
475    * strategy 1 is deployed.<br>
476    * Rank measure 2 is equal to the number of accumulated multiplications to
477    * compute the given MinorValue. This also includes all nested
478    * multiplications which were performed to compute all sub-minors which
479    * could be reused from cache.
480    * @return an integer rank measure of \c this
481    * @see MinorValue::operator< (const MinorValue& mv)
482    */
483    int rankMeasure2 () const;
484
485    /**
486    * A method for obtaining a rank measure for the given MinorValue.<br>
487    * Rank measures are used to compare any two instances of MinorValue. The
488    * induced ordering on MinorValues has an impact on the caching behaviour
489    * in a given cache: Greater MinorValues will be cached longer than lower
490    * ones.<br>
491    * More explicitely, this means: Make the return value of this method
492    * greater, and the given MinorValue will be cached longer when caching
493    * strategy 1 is deployed.<br>
494    * Rank measure 3 is equal to the number of actually performed
495    * multiplications, weighted with the ratio of not yet performed retrievals
496    * over the maximum number of retrievals.
497    * @return an integer rank measure of \c this
498    * @see MinorValue::operator< (const MinorValue& mv)
499    */
500    int rankMeasure3 () const;
501
502    /**
503    * A method for obtaining a rank measure for the given MinorValue.<br>
504    * Rank measures are used to compare any two instances of MinorValue. The
505    * induced ordering on MinorValues has an impact on the caching behaviour
506    * in a given cache: Greater MinorValues will be cached longer than lower
507    * ones.<br>
508    * More explicitely, this means: Make the return value of this method
509    * greater, and the given MinorValue will be cached longer when caching
510    * strategy 1 is deployed.<br>
511    * Rank measure 4 is equal to the number of actually performed
512    * multiplications, multiplied with the number of not yet performed
513    * retrievals.
514    * @return an integer rank measure of \c this
515    * @see MinorValue::operator< (const MinorValue& mv)
516    */
517    int rankMeasure4 () const;
518
519    /**
520    * A method for obtaining a rank measure for the given MinorValue.<br>
521    * Rank measures are used to compare any two instances of MinorValue. The
522    * induced ordering on MinorValues has an impact on the caching behaviour
523    * in a given cache: Greater MinorValues will be cached longer than lower
524    * ones.<br>
525    * More explicitely, this means: Make the return value of this method
526    * greater, and the given MinorValue will be cached longer when caching
527    * strategy 1 is deployed.<br>
528    * Rank measure 5 is equal to the number of not yet performed retrievals.
529    * This strategy tends to cache MinorValues longer which have a high
530    * maximum number of potential retrievals.
531    * @return an integer rank measure of \c this
532    * @see MinorValue::operator< (const MinorValue& mv)
533    */
534    int rankMeasure5 () const;
535
536    /**
537    * private store for the current value ranking strategy;
538    * This member can be set using MinorValue::SetRankingStrategy (const int).
539    */
540    static int g_rankingStrategy;
541
542    /**
543    * Accessor for the static private field g_rankingStrategy.
544    */
545    static int GetRankingStrategy();
546  public:
547    /**
548    * just to make the compiler happy
549    */
550    bool operator== (const MinorValue& mv) const;
551
552    /**
553    * just to make the compiler happy
554    */
555    bool operator< (const MinorValue& mv) const;
556
557    /**
558    * A method for retrieving the weight of a given MinorValue.
559    * The implementation of Cache uses this function to determine the total
560    * weight of an entire cache. As the user can instantiate Cache by
561    * determining its maximum total weight
562    * (see Cache::Cache(const int, const int)),
563    * the definition of weight of a MinorValue
564    * may have an impact on the behaviour of the cache.
565    * @return the weight of a given instance of MinorValue
566    * @see Cache::getWeight () const
567    */
568    virtual int getWeight () const;
569
570    /**
571    * A method for accessing the number of retrievals of this minor. Multiple
572    * retrievals will occur when computing large minors by means of cached
573    * sub-minors. (Then, the latter ones may be retrieved multiple times.)
574    * @return the number of retrievals of this minor
575    * @see MinorValue::getPotentialRetrievals () const
576    */
577    int getRetrievals () const;
578
579    /**
580    * A method for accessing the maximum number of potential retrievals of
581    * this minor. Multiple retrievals will occur when computing large minors
582    * by means of cached sub-minors. (Then, the latter ones may be retrieved
583    * multiple times.)
584    * @return the maximum number of potential retrievals of this minor
585    * @see MinorValue::getRetrievals () const
586    */
587    int getPotentialRetrievals () const;
588
589    /**
590    * A method for accessing the multiplications performed while computing
591    * this minor.
592    * Due to multiplication with zero entries of the underlying matrix, some
593    * sub-minors may be irrelevant. In this case, the multiplications needed
594    * to compute these sub-minors will not be counted (, as they need not be
595    * performed).
596    * Moreover, multiplications that were needed to compute cached sub-minors
597    * will not be counted either, as the value of those sub-minors can be
598    * directly retrieved from the cache.
599    * @return the number of multiplications performed
600    * @see MinorValue::getAccumulatedMultiplications () const
601    */
602    int getMultiplications () const;
603
604    /**
605    * A method for accessing the multiplications performed while computing
606    * this minor, including all nested multiplications.
607    * Contrary to MinorValue::getMultiplications () const, this method will
608    * also count multiplications needed to compute all cached sub-minors
609    * (, although they need not be performed again in order to compute the
610    * given instance of MinorValue).
611    * @return the number of multiplications performed, including nested
612    *         multiplications
613    * @see MinorValue::getMultiplications () const
614    */
615    int getAccumulatedMultiplications () const;
616
617    /**
618    * A method for accessing the additions performed while computing this
619    * minor.
620    * Additions that were needed to compute cached sub-minors will not be
621    * counted, as the value of those sub-minors can be directly retrieved
622    * from the cache.
623    * @return the number of additions performed
624    * @see MinorValue::getAccumulatedAdditions () const
625    */
626    int getAdditions () const;
627
628    /**
629    * A method for accessing the additions performed while computing this
630    * minor, including all nested additions.
631    * Contrary to MinorValue::getAdditions () const, this method will also
632    * count additions needed to compute all cached sub-minors (, although
633    * they need not be performed again in order to compute the given instance
634    * of MinorValue).
635    * @return the number of additions performed, including nested additions
636    * @see MinorValue::getAdditions () const
637    */
638    int getAccumulatedAdditions () const;
639
640    /**
641    * A method for incrementing the number of performed retrievals of \a this
642    * instance of MinorValue.<br>
643    * Note that, when calling MinorValue::incrementRetrievals () for some
644    * instance \a mv of MinorValue which has been cached in a Cache under
645    * MinorKey \a mk, the user should be careful: After incrementing the
646    * number of retrievals for \a mv, the user should always put the value
647    * again into cache, i.e. should perform
648    * Cache::put (const KeyClass&, const ValueClass&)
649    * with \a mk and the modified \a mv as arguments. This is due to the fact
650    * that changing the number of performed retrievals of a MinorValue may
651    * have an impact on its ranking in Cache. Only by calling
652    * Cache::put (const KeyClass&, const ValueClass&) can the user ensure
653    * that the pair (\a mk --> \a mv) will be correctly re-positioned within
654    * the Cache.
655    */
656    void incrementRetrievals ();
657
658    /**
659    * A method for obtaining a rank measure for theiven MinorValue.<br>
660    * Rank measures are used to compare any two instances of MinorValue. The
661    * induced ordering on MinorValues has an impact on the caching behaviour
662    * of the underlying cache: Greater MinorValues will be cached longer than
663    * lower ones.<br>
664    * More explicitely, this means: Make the return value of this method
665    * greater, and the given MinorValue will be cached longer.<br>
666    * Internally, this method will call one of several implementations,
667    * depending on the pre-defined caching strategy; see
668    * MinorProcessor::SetCacheStrategy (const int).
669    * @return an integer rank measure of \c this
670    * @see MinorValue::operator< (const MinorValue& mv)
671    * @see MinorProcessor::SetCacheStrategy (const int)
672    */
673    int getUtility () const;
674
675    /**
676    * A method for determining the value ranking strategy.<br>
677    * This setting has a direct effect on how long the given MinorValue
678    * will be cached in any cache that uses MinorValue to represent its
679    * cached values.
680    * @param rankingStrategy an int, so far one of 1, 2, ..., 5
681    */
682    static void SetRankingStrategy (const int rankingStrategy);
683
684    /**
685    * A method for providing a printable version of the represented MinorValue.
686    * @return a printable version of the given instance as instance of class
687    *         string
688    */
689   virtual std::string toString () const;
690
691    /**
692    * A method for printing a string representation of the given MinorValue
693    * to std::cout.
694    */
695    void print () const;
696};
697
698/*! \class IntMinorValue
699    \brief Class IntMinorValue is derived from MinorValue and can be used for
700    representing values in a cache for sub-determinantes; see class Cache.
701
702    As such, it is a realization of the template class ValueClass which is
703    used in the declaration of class Cache. Following the documentation of
704    class Cache, we need to implement at least the methods:<br>
705    <c>bool IntMinorValue::operator< (const IntMinorValue& key),</c><br>
706    <c>bool IntMinorValue::operator== (const IntMinorValue& key),</c><br>
707    <c>int IntMinorValue::getWeight ().</c><br><br>
708    The main purpose of IntMinorValue is to represent values of
709    sub-determinantes of a pre-defined matrix. Class MinorKey is used to
710    determine which rows and columns of this pre-defined matrix ought to
711    belong to the respective sub-determinante of interest. So far,
712    IntMinorValue is just an example implementation which assumes matrices
713    with int entries, such that the result of any minor is again an int.
714    \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch
715*/
716class IntMinorValue : public MinorValue
717{
718  private:
719    /**
720    * a store for the actual value of the minor
721    */
722    int _result;
723  public:
724    /**
725    * A constructor for class MinorValue.
726    * @param result the actual value of the represented minor
727    * @param multiplications number of multiplications to compute \a this
728             minor
729    * @param additions number of additions to compute \a this minor
730    * @param accumulatedMultiplications number of multiplications to compute
731             \a this minor, including nested operations
732    * @param accumulatedAdditions number of additions to compute \a this minor,
733             including nested operations
734    * @param retrievals number of times this minor has been retrieved from
735             cache
736    * @param potentialRetrievals maximum number of times this minor may be
737             retrieved from cache
738    */
739    IntMinorValue (const int result, const int multiplications,
740                   const int additions,
741                   const int accumulatedMultiplications,
742                   const int accumulatedAdditions, const int retrievals,
743                   const int potentialRetrievals);
744
745    /**
746    * Copy constructor
747    */
748    IntMinorValue (const IntMinorValue& mv);
749
750    /**
751    * just to make the compiler happy
752    */
753    IntMinorValue ();
754
755    /**
756    * Destructor
757    */
758    virtual ~IntMinorValue ();
759
760    /**
761    * Accessor for the private field _result.
762    * @result the result encoded in this class instance
763    */
764    int getResult() const;
765
766    /**
767    * Accessor for the current weight of this class instance.
768    * @result the current weight of this class instance
769    */
770    int getWeight () const;
771
772    /**
773    * A method for providing a printable version of the represented MinorValue.
774    * @return a printable version of the given instance as instance of class
775    * string
776    */
777   std::string toString () const;
778};
779
780/*! \class PolyMinorValue
781    \brief Class PolyMinorValue is derived from MinorValue and can be used for
782    representing values in a cache for sub-determinantes; see class Cache.
783
784    As such, it is a realization of the template class ValueClass which is
785    used in the declaration of class Cache. Following the documentation of
786    class Cache, we need to implement at least the methods:<br>
787    <c>bool IntMinorValue::operator< (const IntMinorValue& key),</c><br>
788    <c>bool IntMinorValue::operator== (const IntMinorValue& key),</c><br>
789    <c>int IntMinorValue::getWeight ().</c><br><br>
790    The main purpose of PolyMinorValue is to represent values of
791    sub-determinantes of a pre-defined matrix. Class MinorKey is used to
792    determine which rows and columns of this pre-defined matrix ought to
793    belong to the respective sub-determinante of interest. PolyMinorValue is
794    a special implementation which assumes matrices with polynomial entries,
795    such that the result of any minor is again a polynomial.
796    \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch
797*/
798class PolyMinorValue : public MinorValue
799{
800  private:
801    /**
802    * a store for the actual value of the minor
803    */
804    poly _result;
805  public:
806    /**
807    * A constructor for class MinorValue.
808    * @param result the actual value of the represented minor
809    * @param multiplications number of multiplications to compute \a this
810             minor
811    * @param additions number of additions to compute \a this minor
812    * @param accumulatedMultiplications number of multiplications to compute
813             \a this minor, including nested operations
814    * @param accumulatedAdditions number of additions to compute \a this
815             minor, including nested operations
816    * @param retrievals number of times this minor has been retrieved from
817             cache
818    * @param potentialRetrievals maximum number of times this minor may be
819             retrieved from cache
820    */
821    PolyMinorValue (const poly result, const int multiplications,
822                    const int additions,
823                    const int accumulatedMultiplications,
824                    const int accumulatedAdditions, const int retrievals,
825                    const int potentialRetrievals);
826
827    /**
828    * Copy constructor for creating a deep copy.
829    */
830    PolyMinorValue (const PolyMinorValue& mv);
831
832    /**
833    * Assignment operator which creates a deep copy.
834    */
835    void operator= (const PolyMinorValue& mv);
836
837    /**
838    * just to make the compiler happy
839    */
840    PolyMinorValue ();
841
842    /**
843    * Destructor
844    */
845    virtual ~PolyMinorValue ();
846
847    /**
848    * Accessor for the private field _result.
849    * @result the result encoded in this class instance
850    */
851    poly getResult() const;
852
853    /**
854    * Accessor for the current weight of this class instance.
855    * @result the current weight of this class instance
856    */
857    int getWeight () const;
858
859    /**
860    * A method for providing a printable version of the represented MinorValue.
861    * @return a printable version of the given instance as instance of class
862    * string
863    */
864   std::string toString () const;
865};
866
867#endif
868/* MINOR_H */
Note: See TracBrowser for help on using the repository browser.