Frobby  0.9.5
CommonParamsHelper.cpp
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2010 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"
19 #include "CommonParamsHelper.h"
20 
21 #include "CommonParams.h"
22 #include "IOFacade.h"
23 #include "BigIdeal.h"
24 #include "Ideal.h"
25 #include "TermTranslator.h"
26 #include "VarSorter.h"
27 #include "Scanner.h"
28 #include "IOHandler.h"
29 #include "DataType.h"
30 #include "error.h"
31 #include "BigTermConsumer.h"
32 #include "CoefBigTermConsumer.h"
33 #include "ActionPrinter.h"
34 #include "NullTermConsumer.h"
35 #include "NullCoefTermConsumer.h"
39 #include "CanonicalTermConsumer.h"
42 
44  _idealConsumer(0),
45  _polyConsumer(0),
46  _produceCanonicalOutput(false) {
47 }
48 
50  // Constructor defined so auto_ptr<T> in the header does not need
51  // definition of T.
52 }
53 
55  const DataType& output) {
57 
58  Scanner in(params.getInputFormat(), stdin);
59  auto_ptr<IOHandler> outputHandler =
61  if (output == DataType::getPolynomialType()) {
62  _polyConsumerDeleter = outputHandler->createPolynomialWriter(stdout);
64  } else if (output == DataType::getMonomialIdealType()) {
65  _idealConsumerDeleter = outputHandler->createIdealWriter(stdout);
67  } else if (output == DataType::getMonomialIdealListType()) {
68  _idealConsumerDeleter = outputHandler->createIdealListWriter(stdout);
70  } else if (output == DataType::getNullType()) {
75  } else {
76  string msg = "Unsupported output type of ";
77  msg += output.getName();
78  msg += '.';
79  INTERNAL_ERROR(msg);
80  }
81 
82  readIdeal(params, in);
83 }
84 
87 
88  Scanner in(params.getInputFormat(), stdin);
89  auto_ptr<IOHandler> outputHandler =
91  _polyConsumerDeleter = outputHandler->createPolynomialWriter(stdout);
93 
94  readIdeal(params, in);
95 }
96 
98 (const CommonParams& params) {
100 
101  Scanner in(params.getInputFormat(), stdin);
102  auto_ptr<IOHandler> outputHandler =
103  createOHandler(in.getFormat(), params.getOutputFormat());
104  _idealConsumerDeleter = outputHandler->createIdealWriter(stdout);
106 
107  readIdeal(params, in);
108 }
109 
111  const BigIdeal& input,
112  BigTermConsumer& output) {
114 
115  _idealConsumer = &output;
116  setIdeal(params, input);
117 }
118 
120  const BigIdeal& input,
121  CoefBigTermConsumer& output) {
123 
124  _polyConsumer = &output;
125  setIdeal(params, input);
126 }
127 
128 auto_ptr<TermConsumer> CommonParamsHelper::
129 makeTranslatedIdealConsumer(bool split) {
130  auto_ptr<TermConsumer> translated;
131  if (split) {
132  auto_ptr<BigTermConsumer> splitter
134  translated.reset
135  (new TranslatingTermConsumer(splitter, getTranslator()));
136  } else
137  translated.reset
139 
141  return auto_ptr<TermConsumer>
142  (new CanonicalTermConsumer(translated,
143  getIdeal().getVarCount(),
144  &getTranslator()));
145  } else
146  return translated;
147 }
148 
150  auto_ptr<CoefTermConsumer> translated
153  return auto_ptr<CoefTermConsumer>
154  (new CanonicalCoefTermConsumer(translated));
155  else
156  return translated;
157 }
158 
160  return auto_ptr<CoefTermConsumer>
162 }
163 
165  _translator->addPurePowersAtInfinity(*_ideal);
166 }
167 
169  BigIdeal bigIdeal;
170  IOFacade facade(params.getPrintActions());
171  facade.readIdeal(in, bigIdeal);
172  in.expectEOF();
173  setIdeal(params, bigIdeal);
174 }
175 
177  const BigIdeal& bigIdeal) {
178  ActionPrinter printer(params.getPrintActions());
179 
180  printer.beginAction("Translating ideal to internal data structure.");
181  _ideal.reset(new Ideal());
182  _translator.reset(new TermTranslator(bigIdeal, *_ideal, false));
183  printer.endAction();
184 
185  if (!params.getIdealIsMinimal()) {
186  printer.beginAction("Minimizing ideal.");
187  _ideal->minimize();
188  printer.endAction();
189  }
190 
191  if (params.getProduceCanonicalOutput()) {
192  printer.beginAction("Sorting variables for canonical representation.");
193 
194  VarSorter sorter(_translator->getNames());
195  sorter.permute(_translator.get());
196 
197  Ideal::iterator stop = _ideal->end();
198  for (Ideal::iterator it = _ideal->begin(); it != stop; ++it)
199  sorter.permute(*it);
200 
201  printer.endAction();
202  }
203 }
auto_ptr< IOHandler > createOHandler(const string &input, const string &output)
Returns an IOHandler for the output format.
Definition: IOHandler.cpp:149
void beginAction(const char *message)
Passes consumed items on in a canonical order.
void setIdeal(const CommonParams &params, const BigIdeal &ideal)
TermTranslator & getTranslator()
void readIdeal(const CommonParams &params, Scanner &in)
auto_ptr< TermConsumer > makeTranslatedIdealConsumer(bool split=false)
void setIdealAndIdealOutput(const CommonParams &params, const BigIdeal &input, BigTermConsumer &output)
Use given ideal and support ideal output.
auto_ptr< CoefTermConsumer > makeToUnivariatePolyConsumer()
void readIdealAndSetOutput(const CommonParams &params, const DataType &output)
Read input ideal and support specified kind of output.
void readIdealAndSetIdealOutput(const CommonParams &params)
Read input and support ideal output.
void readIdealAndSetPolyOutput(const CommonParams &params)
Read input and support polynomial output.
auto_ptr< BigTermConsumer > _idealConsumerDeleter
BigTermConsumer * _idealConsumer
auto_ptr< CoefBigTermConsumer > _polyConsumerDeleter
void setIdealAndPolyOutput(const CommonParams &params, const BigIdeal &input, CoefBigTermConsumer &output)
Use given ideal and support polynomial output.
CoefBigTermConsumer * _polyConsumer
auto_ptr< TermTranslator > _translator
auto_ptr< Ideal > _ideal
auto_ptr< CoefTermConsumer > makeTranslatedPolyConsumer()
const string & getOutputFormat() const
Returns the format in which output is produced.
Definition: CommonParams.h:51
const string & getInputFormat() const
Returns the format used for parsing input.
Definition: CommonParams.h:47
bool getPrintActions() const
Returns whether to print and time the large-scale actions that Frobby performs.
Definition: CommonParams.h:43
bool getIdealIsMinimal() const
Returns whether the input ideal is known to be minimally generated.
Definition: CommonParams.h:38
bool getProduceCanonicalOutput() const
Returns whether to produce output in a canonical representation.
Definition: CommonParams.h:56
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition: DataType.h:29
const char * getName() const
Returns the name of the structure.
Definition: DataType.cpp:24
static const DataType & getNullType()
Returns the one and only instance for null.
Definition: DataType.cpp:40
static const DataType & getMonomialIdealListType()
Returns the one and only instance for monomial ideal lists.
Definition: DataType.cpp:54
static const DataType & getMonomialIdealType()
Returns the one and only instance for monomial ideals.
Definition: DataType.cpp:45
static const DataType & getPolynomialType()
Returns the one and only instance for polynomials.
Definition: DataType.cpp:50
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39
void readIdeal(Scanner &in, BigTermConsumer &consumer)
Read an ideal from in and feed it to consumer.
Definition: IOFacade.cpp:81
Represents a monomial ideal with int exponents.
Definition: Ideal.h:27
Cont::iterator iterator
Definition: Ideal.h:44
This follows the null object pattern.
This follows the null object pattern.
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition: Scanner.h:50
const string & getFormat() const
Definition: Scanner.h:61
void expectEOF()
Require that there is no more input.
Definition: Scanner.cpp:77
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
#define INTERNAL_ERROR(msg)
Definition: error.h:42
void permute(vector< mpz_class > &term)
Definition: VarSorter.cpp:56