Frobby 0.9.5
StatisticsStrategy.cpp
Go to the documentation of this file.
1/* Frobby: Software for monomial ideal computations.
2 Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see http://www.gnu.org/licenses/.
16*/
17#include "stdinc.h"
18#include "StatisticsStrategy.h"
19
20#include "Slice.h"
21
22#include <cmath>
23
25 _strategy(strategy),
26 _out(out),
27 _internalTracker("internal nodes"),
28 _leafTracker("leaf nodes") {
29 ASSERT(strategy != 0);
30}
31
34
35void StatisticsStrategy::run(const Ideal& ideal) {
36 _strategy->run(ideal);
37
38 fputs("**** Slice Algorithm Statistics ****\n", _out);
39 _internalTracker.printReport(_out);
40 _leafTracker.printReport(_out);
41}
42
44(TaskEngine& tasks, auto_ptr<Slice> slice) {
45 _internalTracker.preliminaryRecord(*slice);
46 _leafTracker.preliminaryRecord(*slice);
47
48 bool wasBaseCase = _strategy->processSlice(tasks, slice);
49
50 if (wasBaseCase)
51 _leafTracker.commitRecord();
52 else
53 _internalTracker.commitRecord();
54
55 return wasBaseCase;
56}
57
59 _strategy->setUseIndependence(use);
60}
61
63 _strategy->setUseSimplification(use);
64}
65
67 return _strategy->getUseSimplification();
68}
69
70void StatisticsStrategy::freeSlice(auto_ptr<Slice> slice) {
71 _strategy->freeSlice(slice);
72}
73
75 _title(title) {
76}
77
79 _prelimIdealGenCount = slice.getIdeal().getGeneratorCount();
80 _prelimSubGenCount = slice.getSubtract().getGeneratorCount();
81 _prelimVarCount = slice.getVarCount();
82}
83
85 ++_nodeCount;
86
87 _idealGenSum += _prelimIdealGenCount;
88 _subGenSum += _prelimSubGenCount;
89 _varSum += _prelimVarCount;
90
91 size_t genCountLog2 = 0;
92 if (_prelimIdealGenCount > 0)
93 genCountLog2 = (size_t)(log((double)_prelimIdealGenCount) / log((double)2));
94 _nodesByGenCount[genCountLog2] += 1;
95}
96
98 fprintf(out, "|-%s:\n", _title.c_str());
99
100 gmp_fprintf(out, " | %Zd nodes\n", getNodeCount().get_mpz_t());
101 fprintf(out, " | %f generators of ideal on avg.\n", getAvgIdealGenCount());
102 fprintf(out, " | %f generators of subtract on avg.\n", getAvgSubGenCount());
103 fprintf(out, " | %f variables of ambient ring on avg.\n", getAvgVarCount());
104
105 if (!_nodesByGenCount.empty()) {
106 fputs(" |- nodes by log base 2 of ideal generator count:\n", out);
107 size_t genCountLog2 = _nodesByGenCount.rbegin()->first;
108 while (true) {
109 mpz_class nodeCount = 0;
110 map<size_t, mpz_class>::const_iterator it =
111 _nodesByGenCount.find(genCountLog2);
112 if (it != _nodesByGenCount.end())
113 nodeCount = it->second;
114
115 gmp_fprintf(out, " | %Zd nodes has log2(#gens) = %Zd.\n",
116 nodeCount.get_mpz_t(),
117 mpz_class(genCountLog2).get_mpz_t());
118
119 if (genCountLog2 == 0)
120 break;
121 --genCountLog2;
122 }
123 }
124}
125
127 return _nodeCount;
128}
129
131 if (_nodeCount == 0)
132 return 0.0;
133 else {
134 mpq_class q = mpq_class(_idealGenSum) / _nodeCount;
135 return q.get_d();
136 }
137}
138
140 if (_nodeCount == 0)
141 return 0.0;
142 else {
143 mpq_class q = mpq_class(_subGenSum) / _nodeCount;
144 return q.get_d();
145 }
146}
147
149 if (_nodeCount == 0)
150 return 0.0;
151 else {
152 mpq_class q = mpq_class(_varSum) / _nodeCount;
153 return q.get_d();
154 }
155}
Represents a monomial ideal with int exponents.
Definition Ideal.h:27
size_t getGeneratorCount() const
Definition Ideal.h:57
This class describes the interface of a strategy object for the Slice Algorithm.
This class represents a slice, which is the central data structure of the Slice Algorithm.
Definition Slice.h:77
const Ideal & getIdeal() const
Returns for a slice .
Definition Slice.h:104
size_t getVarCount() const
Returns the number of variables in the ambient ring.
Definition Slice.h:96
Ideal & getSubtract()
Returns for a slice .
Definition Slice.h:107
virtual void setUseSimplification(bool use)
This method should only be called before calling run().
virtual void run(const Ideal &ideal)
Run the Slice algorithm.
StatisticsStrategy(SliceStrategy *strategy, FILE *out)
Statistics are written to out, and every call is delegated to strategy.
virtual bool processSlice(TaskEngine &tasks, auto_ptr< Slice > slice)
Process the parameter slice.
virtual bool getUseSimplification() const
virtual void freeSlice(auto_ptr< Slice > slice)
It is allowed to delete returned slices directly, but it is better to use freeSlice.
virtual void setUseIndependence(bool use)
This method should only be called before calling run().
TaskEngine handles a list of tasks that are to be carried out.
Definition TaskEngine.h:40
This header file includes common definitions and is included as the first line of code in every imple...
#define ASSERT(X)
Definition stdinc.h:86
void printReport(FILE *out) const
Print a report on statistics of the recorded slices to the file out.
StatTracker(const string &title)
The title parameter indicates what is to be printed when calling printReport().
const mpz_class & getNodeCount() const
void commitRecord()
Commit the most recent argument to preliminaryTrack permanently to the record.
void preliminaryRecord(const Slice &slice)
Record information about slice, but store it only until this method is next called on this object.