Frobby  0.9.5
IdealConsolidator.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 "IdealConsolidator.h"
19 
20 #include "Term.h"
21 #include "TermTranslator.h"
22 
23 IdealConsolidator::IdealConsolidator(auto_ptr<BigTermConsumer> consumer):
24  _consumer(consumer),
25  _inList(false),
26  _inIdeal(false) {
27 }
28 
30  ASSERT(!_inIdeal);
31 
32  _consumer->consumeRing(names);
33 
34  _names = names;
35  _ideal.clearAndSetNames(names);
36  _tmp.resize(names.getVarCount());
37 }
38 
40  ASSERT(!_inList);
41  ASSERT(!_inIdeal);
42 
43  _consumer->beginConsumingList();
44  _inList = true;
45 }
46 
48  ASSERT(!_inIdeal);
49  _inIdeal = true;
50 }
51 
52 void IdealConsolidator::consume(const Term& term) {
53  ASSERT(term.getVarCount() == _tmp.size());
54 
55  for (size_t var = 0; var < term.getVarCount(); ++var)
56  _tmp[var] = term[var];
57  consume(_tmp);
58 }
59 
61 (const Term& term, const TermTranslator& translator) {
62  ASSERT(term.getVarCount() == _tmp.size());
63 
64  for (size_t var = 0; var < term.getVarCount(); ++var)
65  _tmp[var] = translator.getExponent(var, term);
66  consume(_tmp);
67 }
68 
69 void IdealConsolidator::consume(const vector<mpz_class>& term) {
70  ASSERT(term.size() == _ideal.getVarCount());
71  // TODO: Add a method to BigIdeal that does this in one step.
73  _ideal.getLastTermRef() = term;
74 }
75 
78 
79  _inIdeal = false;
80  _consumer->consume(_ideal);
81  _ideal.clear();
82 }
83 
85  ASSERT(_inList);
86  _inList = false;
87  _consumer->doneConsumingList();
88 }
89 
91  _consumer->consume(ideal);
92 }
void clearAndSetNames(const VarNames &names)
Definition: BigIdeal.cpp:222
void newLastTerm()
Definition: BigIdeal.cpp:104
size_t getVarCount() const
Definition: BigIdeal.h:148
void clear()
Definition: BigIdeal.cpp:218
vector< mpz_class > & getLastTermRef()
Definition: BigIdeal.h:133
virtual void consumeRing(const VarNames &names)
Tell the consumer which ring is being used.
IdealConsolidator(auto_ptr< BigTermConsumer > consumer)
virtual void consume(const Term &term)
Consume a term.
virtual void doneConsumingList()
Must be called once after each time beginConsumingList has been called.
virtual void beginConsuming()
Tell the consumer to begin consuming an ideal.
vector< mpz_class > _tmp
const auto_ptr< BigTermConsumer > _consumer
virtual void beginConsumingList()
Tell the consumer that the ideals that are consumed until the next call to doneConsumingList are to b...
virtual void doneConsuming()
Must be called once after each time beginConsuming has been called.
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
const mpz_class & getExponent(size_t variable, Exponent exponent) const
This method translates from IDs to arbitrary precision integers.
Term represents a product of variables which does not include a coefficient.
Definition: Term.h:49
size_t getVarCount() const
Definition: Term.h:85
Defines the variables of a polynomial ring and facilities IO involving them.
Definition: VarNames.h:40
size_t getVarCount() const
Returns the current number of variables.
Definition: VarNames.h:113
#define ASSERT(X)
Definition: stdinc.h:86