HilbertIndependenceConsumer.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include "stdinc.h"
#include "HilbertIndependenceConsumer.h"
#include "IndependenceSplitter.h"
#include "HilbertStrategy.h"
HilbertIndependenceConsumer::
HilbertIndependenceConsumer(HilbertStrategy* strategy):
_rightConsumer(this),
_strategy(strategy) {
ASSERT(strategy != 0);
clear();
}
void HilbertIndependenceConsumer::reset(CoefTermConsumer* parent,
IndependenceSplitter& splitter,
size_t varCount) {
ASSERT(parent != 0);
_tmpTerm.reset(varCount);
_parent = parent;
splitter.getBigProjection(_leftProjection);
splitter.getRestProjection(_rightProjection);
_rightTerms.clearAndSetVarCount(_rightProjection.getRangeVarCount());
}
void HilbertIndependenceConsumer::clear() {
_parent = 0;
_rightTerms.clear();
_rightCoefs.clear();
}
void HilbertIndependenceConsumer::dispose() {
ASSERT(_strategy != 0);
_strategy->freeConsumer(unique_ptr<HilbertIndependenceConsumer>(this));
}
void HilbertIndependenceConsumer::run(TaskEngine&) {
dispose();
}
CoefTermConsumer* HilbertIndependenceConsumer::getLeftConsumer() {
ASSERT(_parent != 0);
return this;
}
void HilbertIndependenceConsumer::consumeRing(const VarNames& names) {
}
void HilbertIndependenceConsumer::beginConsuming() {
}
void HilbertIndependenceConsumer::doneConsuming() {
}
void HilbertIndependenceConsumer::consume(const mpz_class& coef,
const Term& term) {
ASSERT(_parent != 0);
ASSERT(coef != 0);
consumeLeft(coef, term);
}
CoefTermConsumer* HilbertIndependenceConsumer::getRightConsumer() {
ASSERT(_parent != 0);
return &_rightConsumer;
}
const Projection& HilbertIndependenceConsumer::getLeftProjection() const {
ASSERT(_parent != 0);
return _leftProjection;
}
const Projection& HilbertIndependenceConsumer::getRightProjection() const {
ASSERT(_parent != 0);
return _rightProjection;
}
HilbertIndependenceConsumer::RightConsumer::
RightConsumer(HilbertIndependenceConsumer* parent):
_parent(parent) {
}
void HilbertIndependenceConsumer::RightConsumer::consumeRing
(const VarNames& names) {
}
void HilbertIndependenceConsumer::RightConsumer::beginConsuming() {
}
void HilbertIndependenceConsumer::RightConsumer::
consume(const mpz_class& coef, const Term& term) {
_parent->consumeRight(coef, term);
}
void HilbertIndependenceConsumer::RightConsumer::doneConsuming() {
}
void HilbertIndependenceConsumer::consumeLeft(const mpz_class& leftCoef,
const Term& leftTerm) {
ASSERT(_tmpTerm.getVarCount() ==
_leftProjection.getRangeVarCount() +
_rightProjection.getRangeVarCount());
_leftProjection.inverseProject(_tmpTerm, leftTerm);
size_t rightSize = _rightTerms.getGeneratorCount();
ASSERT(rightSize == _rightCoefs.size());
for (size_t right = 0; right < rightSize; ++right) {
_rightProjection.inverseProject(_tmpTerm,
*(_rightTerms.begin() + right));
ASSERT(leftCoef != 0);
ASSERT(_rightCoefs[right] != 0);
_tmpCoef = leftCoef * _rightCoefs[right];
ASSERT(_tmpCoef != 0);
_parent->consume(_tmpCoef, _tmpTerm);
}
}
void HilbertIndependenceConsumer::consumeRight(const mpz_class& coef,
const Term& term) {
ASSERT(term.getVarCount() == _rightProjection.getRangeVarCount());
ASSERT(_rightTerms.getVarCount() == term.getVarCount());
ASSERT(coef != 0);
_rightTerms.insert(term);
_rightCoefs.push_back(coef);
}
HilbertIndependenceConsumer.h
HilbertStrategy.h
IndependenceSplitter.h
CoefTermConsumer
Definition CoefTermConsumer.h:24
HilbertIndependenceConsumer::RightConsumer::doneConsuming
virtual void doneConsuming()
Definition HilbertIndependenceConsumer.cpp:113
HilbertIndependenceConsumer::RightConsumer::_parent
HilbertIndependenceConsumer * _parent
Definition HilbertIndependenceConsumer.h:68
HilbertIndependenceConsumer::RightConsumer::beginConsuming
virtual void beginConsuming()
Definition HilbertIndependenceConsumer.cpp:105
HilbertIndependenceConsumer::RightConsumer::RightConsumer
RightConsumer(HilbertIndependenceConsumer *parent)
Definition HilbertIndependenceConsumer.cpp:97
HilbertIndependenceConsumer::RightConsumer::consumeRing
virtual void consumeRing(const VarNames &names)
Definition HilbertIndependenceConsumer.cpp:102
HilbertIndependenceConsumer::RightConsumer::consume
virtual void consume(const mpz_class &coef, const Term &term)
Definition HilbertIndependenceConsumer.cpp:109
HilbertIndependenceConsumer::consumeRing
virtual void consumeRing(const VarNames &names)
Definition HilbertIndependenceConsumer.cpp:65
HilbertIndependenceConsumer::_rightTerms
Ideal _rightTerms
Definition HilbertIndependenceConsumer.h:82
HilbertIndependenceConsumer::getRightConsumer
CoefTermConsumer * getRightConsumer()
Definition HilbertIndependenceConsumer.cpp:81
HilbertIndependenceConsumer::getRightProjection
const Projection & getRightProjection() const
Definition HilbertIndependenceConsumer.cpp:91
HilbertIndependenceConsumer::_strategy
HilbertStrategy * _strategy
Definition HilbertIndependenceConsumer.h:87
HilbertIndependenceConsumer::_tmpTerm
Term _tmpTerm
Definition HilbertIndependenceConsumer.h:75
HilbertIndependenceConsumer::_rightConsumer
RightConsumer _rightConsumer
Definition HilbertIndependenceConsumer.h:85
HilbertIndependenceConsumer::consumeRight
virtual void consumeRight(const mpz_class &coef, const Term &term)
Definition HilbertIndependenceConsumer.cpp:138
HilbertIndependenceConsumer::run
virtual void run(TaskEngine &engine)
Does whatever work this task represents.
Definition HilbertIndependenceConsumer.cpp:56
HilbertIndependenceConsumer::reset
void reset(CoefTermConsumer *parent, IndependenceSplitter &splitter, size_t varCount)
Definition HilbertIndependenceConsumer.cpp:31
HilbertIndependenceConsumer::_rightCoefs
vector< mpz_class > _rightCoefs
Definition HilbertIndependenceConsumer.h:83
HilbertIndependenceConsumer::_leftProjection
Projection _leftProjection
Definition HilbertIndependenceConsumer.h:79
HilbertIndependenceConsumer::doneConsuming
virtual void doneConsuming()
Definition HilbertIndependenceConsumer.cpp:71
HilbertIndependenceConsumer::beginConsuming
virtual void beginConsuming()
Definition HilbertIndependenceConsumer.cpp:68
HilbertIndependenceConsumer::getLeftProjection
const Projection & getLeftProjection() const
Definition HilbertIndependenceConsumer.cpp:86
HilbertIndependenceConsumer::consumeLeft
virtual void consumeLeft(const mpz_class &leftCoef, const Term &leftTerm)
Definition HilbertIndependenceConsumer.cpp:116
HilbertIndependenceConsumer::dispose
virtual void dispose()
Called when the task is no longer used but run has not and will not be called.
Definition HilbertIndependenceConsumer.cpp:51
HilbertIndependenceConsumer::getLeftConsumer
CoefTermConsumer * getLeftConsumer()
Definition HilbertIndependenceConsumer.cpp:60
HilbertIndependenceConsumer::_parent
CoefTermConsumer * _parent
Definition HilbertIndependenceConsumer.h:78
HilbertIndependenceConsumer::HilbertIndependenceConsumer
HilbertIndependenceConsumer(HilbertStrategy *strategy)
Definition HilbertIndependenceConsumer.cpp:24
HilbertIndependenceConsumer::consume
virtual void consume(const mpz_class &coef, const Term &term)
Definition HilbertIndependenceConsumer.cpp:74
HilbertIndependenceConsumer::_tmpCoef
mpz_class _tmpCoef
Definition HilbertIndependenceConsumer.h:76
HilbertIndependenceConsumer::_rightProjection
Projection _rightProjection
Definition HilbertIndependenceConsumer.h:80
HilbertIndependenceConsumer::clear
void clear()
Definition HilbertIndependenceConsumer.cpp:45
HilbertStrategy
Definition HilbertStrategy.h:33
IndependenceSplitter
Definition IndependenceSplitter.h:29
IndependenceSplitter::getRestProjection
void getRestProjection(Projection &projection) const
Definition IndependenceSplitter.cpp:28
IndependenceSplitter::getBigProjection
void getBigProjection(Projection &projection) const
Definition IndependenceSplitter.cpp:24
Projection
Definition Projection.h:29
TaskEngine
TaskEngine handles a list of tasks that are to be carried out.
Definition TaskEngine.h:40
Term
Term represents a product of variables which does not include a coefficient.
Definition Term.h:49
Term::getVarCount
size_t getVarCount() const
Definition Term.h:85
VarNames
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...
ASSERT
#define ASSERT(X)
Definition stdinc.h:86