Frobby 0.9.7
BigattiHilbertAlgorithm.cpp
Go to the documentation of this file.
1/* Frobby: Software for monomial ideal computations.
2 Copyright (C) 2009 University of Aarhus
3 Contact Bjarke Hammersholt Roune for license information (www.broune.com)
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see http://www.gnu.org/licenses/.
17*/
18#include "stdinc.h"
20
21#include "Ideal.h"
22#include "CoefBigTermConsumer.h"
23#include "BigattiState.h"
24
27(unique_ptr<Ideal> ideal,
28 const TermTranslator& translator,
29 const BigattiParams& params,
30 unique_ptr<BigattiPivotStrategy> pivot,
31 CoefBigTermConsumer& consumer):
32 _translator(translator),
33 _consumer(&consumer),
34 _baseCase(translator),
35 _pivot(std::move(pivot)),
36 _computeUnivariate(false),
37 _params(params) {
38
39 ASSERT(ideal.get() != 0);
40 ASSERT(ideal->isMinimallyGenerated());
41 _varCount = ideal->getVarCount();
43
44 _baseCase.setPrintDebug(_params.getPrintDebug());
45
46 // TODO: use swap to avoid copy of ideal.
47 _tasks.addTask(new BigattiState(this, *ideal, Term(_varCount)));
48}
49
53
55 if (_pivot.get() == 0)
56 _pivot = BigattiPivotStrategy::createStrategy("median", true);
57
58 _baseCase.setComputeUnivariate(_computeUnivariate);
59 _tasks.runTasks();
60 _baseCase.feedOutputTo(*_consumer, _params.getProduceCanonicalOutput());
61
62 if (_params.getPrintStatistics()) {
63 fputs("*** Statistics for run of Bigatti algorithm ***\n", stderr);
64 fprintf(stderr, " %u states processed.\n",
65 (unsigned int)_tasks.getTotalTasksEver());
66 fprintf(stderr, " %u base cases.\n",
67 (unsigned int)_baseCase.getTotalBaseCasesEver());
68 fprintf(stderr, " %u terms output.\n",
69 (unsigned int)_baseCase.getTotalTermsOutputEver());
70 fprintf(stderr, " %u terms in final output.\n",
71 (unsigned int)_baseCase.getTotalTermsInOutput());
72 }
73}
74
75void BigattiHilbertAlgorithm::processState(unique_ptr<BigattiState> state) {
76 if (_params.getUseSimplification())
77 simplify(*state);
78
79 if (_params.getPrintDebug()) {
80 fputs("Debug: Processing state.\n", stderr);
81 state->print(stderr);
82 }
83
84 bool isBaseCase = _params.getUseGenericBaseCase() ?
85 _baseCase.genericBaseCase(*state) :
86 _baseCase.baseCase(*state);
87 if (isBaseCase) {
88 freeState(std::move(state));
89 return;
90 }
91
92 const Term& pivot = _pivot->getPivot(*state);
93 if (_params.getPrintDebug()) {
94 fputs("Debug: Performing pivot split on ", stderr);
95 pivot.print(stderr);
96 fputs(".\n", stderr);
97 }
98 ASSERT(!pivot.isIdentity());
99 ASSERT(!state->getIdeal().contains(pivot));
100
101 unique_ptr<BigattiState> colonState(_stateCache.newObjectCopy(*state));
102 colonState->colonStep(pivot);
103 _tasks.addTask(colonState.release());
104
105 state->addStep(pivot);
106 _tasks.addTask(state.release());
107}
108
110 Term& gcd = _tmp_simplify_gcd;
111 ASSERT(gcd.getVarCount() == _varCount);
112
113 state.getIdeal().getGcd(gcd);
114 if (!gcd.isIdentity()) {
115 // Do colon and output multiply-gcd*multiply.
116 _baseCase.output(true, state.getMultiply());
117 state.colonStep(gcd);
118 _baseCase.output(false, state.getMultiply());
119 }
120
121 IF_DEBUG(state.getIdeal().getGcd(gcd));
122 ASSERT(gcd.isIdentity());
123}
124
125void BigattiHilbertAlgorithm::freeState(unique_ptr<BigattiState> state) {
126 state->getIdeal().clear(); // To preserve memory
127 _stateCache.freeObject(std::move(state));
128}
void freeState(unique_ptr< BigattiState > state)
unique_ptr< BigattiPivotStrategy > _pivot
BigattiHilbertAlgorithm(unique_ptr< Ideal > ideal, const TermTranslator &translator, const BigattiParams &params, unique_ptr< BigattiPivotStrategy > pivot, CoefBigTermConsumer &consumer)
Construct an object for running the Bigatti et.al.
CoefBigTermConsumer * _consumer
void simplify(BigattiState &state)
ObjectCache< BigattiState > _stateCache
void processState(unique_ptr< BigattiState > state)
const TermTranslator & _translator
void colonStep(const Term &term)
const Term & getMultiply() const
const Ideal & getIdeal() const
void getGcd(Exponent *gcd) const
Sets gcd to the greatest common divisor of all generators.
Definition Ideal.cpp:164
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
Term represents a product of variables which does not include a coefficient.
Definition Term.h:49
static void print(FILE *file, const Exponent *e, size_t varCount)
Writes e to file in a format suitable for debug output.
Definition Term.cpp:110
static bool isIdentity(const Exponent *a, size_t varCount)
Returns whether a is 1, i.e. whether all entries of a are 0.
Definition Term.h:316
This header file includes common definitions and is included as the first line of code in every imple...
#define IF_DEBUG(X)
Definition stdinc.h:85
#define ASSERT(X)
Definition stdinc.h:86