CommonParamsHelper.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2010 University of Aarhus
Contact Bjarke Hammersholt Roune for license information (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 "CommonParamsHelper.h"
#include "CommonParams.h"
#include "IOFacade.h"
#include "BigIdeal.h"
#include "Ideal.h"
#include "TermTranslator.h"
#include "VarSorter.h"
#include "Scanner.h"
#include "IOHandler.h"
#include "DataType.h"
#include "error.h"
#include "BigTermConsumer.h"
#include "CoefBigTermConsumer.h"
#include "ActionPrinter.h"
#include "NullTermConsumer.h"
#include "NullCoefTermConsumer.h"
#include "IrreducibleIdealSplitter.h"
#include "TranslatingTermConsumer.h"
#include "TranslatingCoefTermConsumer.h"
#include "CanonicalTermConsumer.h"
#include "CanonicalCoefTermConsumer.h"
#include "TotalDegreeCoefTermConsumer.h"
CommonParamsHelper::CommonParamsHelper():
_idealConsumer(0),
_polyConsumer(0),
_produceCanonicalOutput(false) {
}
CommonParamsHelper::~CommonParamsHelper() {
// Constructor defined so unique_ptr<T> in the header does not need
// definition of T.
}
void CommonParamsHelper::readIdealAndSetOutput(const CommonParams& params,
const DataType& output) {
_produceCanonicalOutput = params.getProduceCanonicalOutput();
Scanner in(params.getInputFormat(), stdin);
unique_ptr<IOHandler> outputHandler =
createOHandler(in.getFormat(), params.getOutputFormat());
if (output == DataType::getPolynomialType()) {
_polyConsumerDeleter = outputHandler->createPolynomialWriter(stdout);
_polyConsumer = _polyConsumerDeleter.get();
} else if (output == DataType::getMonomialIdealType()) {
_idealConsumerDeleter = outputHandler->createIdealWriter(stdout);
_idealConsumer = _idealConsumerDeleter.get();
} else if (output == DataType::getMonomialIdealListType()) {
_idealConsumerDeleter = outputHandler->createIdealListWriter(stdout);
_idealConsumer = _idealConsumerDeleter.get();
} else if (output == DataType::getNullType()) {
_idealConsumerDeleter.reset(new NullTermConsumer());
_idealConsumer = _idealConsumerDeleter.get();
_polyConsumerDeleter.reset(new NullCoefTermConsumer());
_polyConsumer = _polyConsumerDeleter.get();
} else {
string msg = "Unsupported output type of ";
msg += output.getName();
msg += '.';
INTERNAL_ERROR(msg);
}
readIdeal(params, in);
}
void CommonParamsHelper::readIdealAndSetPolyOutput(const CommonParams& params) {
_produceCanonicalOutput = params.getProduceCanonicalOutput();
Scanner in(params.getInputFormat(), stdin);
unique_ptr<IOHandler> outputHandler =
createOHandler(in.getFormat(), params.getOutputFormat());
_polyConsumerDeleter = outputHandler->createPolynomialWriter(stdout);
_polyConsumer = _polyConsumerDeleter.get();
readIdeal(params, in);
}
void CommonParamsHelper::readIdealAndSetIdealOutput
(const CommonParams& params) {
_produceCanonicalOutput = params.getProduceCanonicalOutput();
Scanner in(params.getInputFormat(), stdin);
unique_ptr<IOHandler> outputHandler =
createOHandler(in.getFormat(), params.getOutputFormat());
_idealConsumerDeleter = outputHandler->createIdealWriter(stdout);
_idealConsumer = _idealConsumerDeleter.get();
readIdeal(params, in);
}
void CommonParamsHelper::setIdealAndIdealOutput(const CommonParams& params,
const BigIdeal& input,
BigTermConsumer& output) {
_produceCanonicalOutput = params.getProduceCanonicalOutput();
_idealConsumer = &output;
setIdeal(params, input);
}
void CommonParamsHelper::setIdealAndPolyOutput(const CommonParams& params,
const BigIdeal& input,
CoefBigTermConsumer& output) {
_produceCanonicalOutput = params.getProduceCanonicalOutput();
_polyConsumer = &output;
setIdeal(params, input);
}
unique_ptr<TermConsumer> CommonParamsHelper::
makeTranslatedIdealConsumer(bool split) {
unique_ptr<TermConsumer> translated;
if (split) {
unique_ptr<BigTermConsumer> splitter
(new IrreducibleIdealSplitter(*_idealConsumer));
translated.reset
(new TranslatingTermConsumer(std::move(splitter), getTranslator()));
} else
translated.reset
(new TranslatingTermConsumer(*_idealConsumer, getTranslator()));
if (_produceCanonicalOutput) {
return unique_ptr<TermConsumer>
(new CanonicalTermConsumer(std::move(translated),
getIdeal().getVarCount(),
&getTranslator()));
} else
return translated;
}
unique_ptr<CoefTermConsumer> CommonParamsHelper::makeTranslatedPolyConsumer() {
unique_ptr<CoefTermConsumer> translated
(new TranslatingCoefTermConsumer(*_polyConsumer, getTranslator()));
if (_produceCanonicalOutput)
return unique_ptr<CoefTermConsumer>
(new CanonicalCoefTermConsumer(std::move(translated)));
else
return translated;
}
unique_ptr<CoefTermConsumer> CommonParamsHelper::makeToUnivariatePolyConsumer() {
return unique_ptr<CoefTermConsumer>
(new TotalDegreeCoefTermConsumer(*_polyConsumer, getTranslator()));
}
void CommonParamsHelper::addPurePowersAtInfinity() {
_translator->addPurePowersAtInfinity(*_ideal);
}
void CommonParamsHelper::readIdeal(const CommonParams& params, Scanner& in) {
BigIdeal bigIdeal;
IOFacade facade(params.getPrintActions());
facade.readIdeal(in, bigIdeal);
in.expectEOF();
setIdeal(params, bigIdeal);
}
void CommonParamsHelper::setIdeal(const CommonParams& params,
const BigIdeal& bigIdeal) {
ActionPrinter printer(params.getPrintActions());
printer.beginAction("Translating ideal to internal data structure.");
_ideal.reset(new Ideal());
_translator.reset(new TermTranslator(bigIdeal, *_ideal, false));
printer.endAction();
if (!params.getIdealIsMinimal()) {
printer.beginAction("Minimizing ideal.");
_ideal->minimize();
printer.endAction();
}
if (params.getProduceCanonicalOutput()) {
printer.beginAction("Sorting variables for canonical representation.");
VarSorter sorter(_translator->getNames());
sorter.permute(_translator.get());
Ideal::iterator stop = _ideal->end();
for (Ideal::iterator it = _ideal->begin(); it != stop; ++it)
sorter.permute(*it);
printer.endAction();
}
}
ActionPrinter.h
BigIdeal.h
BigTermConsumer.h
CanonicalCoefTermConsumer.h
CanonicalTermConsumer.h
CoefBigTermConsumer.h
CommonParamsHelper.h
CommonParams.h
DataType.h
IOFacade.h
createOHandler
unique_ptr< IOHandler > createOHandler(const string &input, const string &output)
Returns an IOHandler for the output format.
Definition IOHandler.cpp:149
IOHandler.h
Ideal.h
IrreducibleIdealSplitter.h
NullCoefTermConsumer.h
NullTermConsumer.h
Scanner.h
TermTranslator.h
TotalDegreeCoefTermConsumer.h
TranslatingCoefTermConsumer.h
TranslatingTermConsumer.h
VarSorter.h
ActionPrinter
Definition ActionPrinter.h:23
ActionPrinter::endAction
void endAction()
Definition ActionPrinter.cpp:51
ActionPrinter::beginAction
void beginAction(const char *message)
Definition ActionPrinter.cpp:44
BigIdeal
Definition BigIdeal.h:27
BigTermConsumer
Definition BigTermConsumer.h:29
CanonicalCoefTermConsumer
Definition CanonicalCoefTermConsumer.h:28
CanonicalTermConsumer
Passes consumed items on in a canonical order.
Definition CanonicalTermConsumer.h:32
CoefBigTermConsumer
Definition CoefBigTermConsumer.h:29
CommonParamsHelper::getTranslator
TermTranslator & getTranslator()
Definition CommonParamsHelper.h:70
CommonParamsHelper::setIdeal
void setIdeal(const CommonParams &params, const BigIdeal &ideal)
Definition CommonParamsHelper.cpp:176
CommonParamsHelper::makeTranslatedIdealConsumer
unique_ptr< TermConsumer > makeTranslatedIdealConsumer(bool split=false)
Definition CommonParamsHelper.cpp:129
CommonParamsHelper::_produceCanonicalOutput
bool _produceCanonicalOutput
Definition CommonParamsHelper.h:101
CommonParamsHelper::readIdeal
void readIdeal(const CommonParams &params, Scanner &in)
Definition CommonParamsHelper.cpp:168
CommonParamsHelper::CommonParamsHelper
CommonParamsHelper()
Definition CommonParamsHelper.cpp:43
CommonParamsHelper::addPurePowersAtInfinity
void addPurePowersAtInfinity()
Definition CommonParamsHelper.cpp:164
CommonParamsHelper::_polyConsumerDeleter
unique_ptr< CoefBigTermConsumer > _polyConsumerDeleter
Definition CommonParamsHelper.h:99
CommonParamsHelper::setIdealAndIdealOutput
void setIdealAndIdealOutput(const CommonParams &params, const BigIdeal &input, BigTermConsumer &output)
Use given ideal and support ideal output.
Definition CommonParamsHelper.cpp:110
CommonParamsHelper::_ideal
unique_ptr< Ideal > _ideal
Definition CommonParamsHelper.h:92
CommonParamsHelper::_idealConsumerDeleter
unique_ptr< BigTermConsumer > _idealConsumerDeleter
Definition CommonParamsHelper.h:96
CommonParamsHelper::readIdealAndSetOutput
void readIdealAndSetOutput(const CommonParams &params, const DataType &output)
Read input ideal and support specified kind of output.
Definition CommonParamsHelper.cpp:54
CommonParamsHelper::readIdealAndSetIdealOutput
void readIdealAndSetIdealOutput(const CommonParams &params)
Read input and support ideal output.
Definition CommonParamsHelper.cpp:98
CommonParamsHelper::getIdeal
Ideal & getIdeal()
Definition CommonParamsHelper.h:65
CommonParamsHelper::readIdealAndSetPolyOutput
void readIdealAndSetPolyOutput(const CommonParams &params)
Read input and support polynomial output.
Definition CommonParamsHelper.cpp:85
CommonParamsHelper::_idealConsumer
BigTermConsumer * _idealConsumer
Definition CommonParamsHelper.h:95
CommonParamsHelper::makeTranslatedPolyConsumer
unique_ptr< CoefTermConsumer > makeTranslatedPolyConsumer()
Definition CommonParamsHelper.cpp:149
CommonParamsHelper::makeToUnivariatePolyConsumer
unique_ptr< CoefTermConsumer > makeToUnivariatePolyConsumer()
Definition CommonParamsHelper.cpp:159
CommonParamsHelper::setIdealAndPolyOutput
void setIdealAndPolyOutput(const CommonParams &params, const BigIdeal &input, CoefBigTermConsumer &output)
Use given ideal and support polynomial output.
Definition CommonParamsHelper.cpp:119
CommonParamsHelper::_polyConsumer
CoefBigTermConsumer * _polyConsumer
Definition CommonParamsHelper.h:98
CommonParamsHelper::~CommonParamsHelper
~CommonParamsHelper()
Definition CommonParamsHelper.cpp:49
CommonParamsHelper::_translator
unique_ptr< TermTranslator > _translator
Definition CommonParamsHelper.h:93
CommonParams
Definition CommonParams.h:25
CommonParams::getInputFormat
const string & getInputFormat() const
Returns the format used for parsing input.
Definition CommonParams.h:47
CommonParams::getOutputFormat
const string & getOutputFormat() const
Returns the format in which output is produced.
Definition CommonParams.h:51
CommonParams::getPrintActions
bool getPrintActions() const
Returns whether to print and time the large-scale actions that Frobby performs.
Definition CommonParams.h:43
CommonParams::getIdealIsMinimal
bool getIdealIsMinimal() const
Returns whether the input ideal is known to be minimally generated.
Definition CommonParams.h:38
CommonParams::getProduceCanonicalOutput
bool getProduceCanonicalOutput() const
Returns whether to produce output in a canonical representation.
Definition CommonParams.h:56
DataType
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition DataType.h:29
DataType::getName
const char * getName() const
Returns the name of the structure.
Definition DataType.cpp:24
DataType::getNullType
static const DataType & getNullType()
Returns the one and only instance for null.
Definition DataType.cpp:40
DataType::getMonomialIdealListType
static const DataType & getMonomialIdealListType()
Returns the one and only instance for monomial ideal lists.
Definition DataType.cpp:54
DataType::getMonomialIdealType
static const DataType & getMonomialIdealType()
Returns the one and only instance for monomial ideals.
Definition DataType.cpp:45
DataType::getPolynomialType
static const DataType & getPolynomialType()
Returns the one and only instance for polynomials.
Definition DataType.cpp:50
IOFacade
A facade for input and output of mathematical objects.
Definition IOFacade.h:39
IOFacade::readIdeal
void readIdeal(Scanner &in, BigTermConsumer &consumer)
Read an ideal from in and feed it to consumer.
Definition IOFacade.cpp:81
Ideal
Represents a monomial ideal with int exponents.
Definition Ideal.h:27
Ideal::iterator
Cont::iterator iterator
Definition Ideal.h:44
IrreducibleIdealSplitter
Definition IrreducibleIdealSplitter.h:25
NullCoefTermConsumer
This follows the null object pattern.
Definition NullCoefTermConsumer.h:31
NullTermConsumer
This follows the null object pattern.
Definition NullTermConsumer.h:25
Scanner
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition Scanner.h:50
Scanner::expectEOF
void expectEOF()
Require that there is no more input.
Definition Scanner.cpp:77
Scanner::getFormat
const string & getFormat() const
Definition Scanner.h:61
TermTranslator
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
Definition TermTranslator.h:41
TotalDegreeCoefTermConsumer
Definition TotalDegreeCoefTermConsumer.h:35
TranslatingCoefTermConsumer
Definition TranslatingCoefTermConsumer.h:26
TranslatingTermConsumer
Definition TranslatingTermConsumer.h:30
error.h
INTERNAL_ERROR
#define INTERNAL_ERROR(msg)
Definition error.h:42
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...
VarSorter
Definition VarSorter.h:27
VarSorter::permute
void permute(vector< mpz_class > &term)
Definition VarSorter.cpp:56