Frobby  0.9.1
GenerateIdealAction.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 "GenerateIdealAction.h"
19 
20 #include "BigIdeal.h"
21 #include "GenerateDataFacade.h"
22 #include "IOFacade.h"
23 #include "error.h"
24 #include "DataType.h"
25 
27  Action
28 (staticGetName(),
29  "Generate a random monomial ideal.",
30  "Generate a monomial ideal. The default is to generate a random one,\n"
31  "and in certain rare cases the generated ideal may have less than the "
32  "requested\n"
33  "number of minimial generators. This can be alleviated by increasing the\n"
34  "exponent range or the number of variables.\n\n"
35  "The other types of ideals are not random, and they use the number of "
36  "variables\n"
37  "as a parameter and may thus have more generators, depending on the type.",
38  false),
39 
40  _type
41 ("type",
42  "The supported types of ideals are random, edge, list, king, knight, rook, matching and tree.",
43  "random"),
44  _variableCount("varCount", "The number of variables.", 3),
45  _generatorCount("genCount", "The number of minimal generators.", 5),
46  _exponentRange
47  ("expRange",
48  "Exponents are chosen uniformly in the range [0,INTEGER].", 9),
49 
50  _io(DataType::getNullType(), DataType::getMonomialIdealType()) {
51 }
52 
53 void GenerateIdealAction::obtainParameters(vector<Parameter*>& parameters) {
54  Action::obtainParameters(parameters);
55  _io.obtainParameters(parameters);
56 
57  parameters.push_back(&_exponentRange);
58  parameters.push_back(&_variableCount);
59  parameters.push_back(&_generatorCount);
60  parameters.push_back(&_type);
61 }
62 
65 
66  BigIdeal ideal;
67 
69  const string& type = _type;
70  if (type == "random")
71  generator.generateIdeal(ideal,
75  else if (type == "list")
76  generator.generateListIdeal(ideal, _variableCount);
77  else if (type == "edge")
79  else if (type == "king")
80  generator.generateKingChessIdeal(ideal, _variableCount);
81  else if (type == "knight")
82  generator.generateKnightChessIdeal(ideal, _variableCount);
83  else if (type == "rook")
85  else if (type == "matching")
86  generator.generateMatchingIdeal(ideal, _variableCount);
87  else if (type == "tree")
88  generator.generateTreeIdeal(ideal, _variableCount);
89  else
90  reportError("Unknown ideal type \"" + type + "\".");
91 
92  IOFacade ioFacade(_printActions);
93  auto_ptr<IOHandler> output = _io.createOutputHandler();
94 
95  ioFacade.writeIdeal(ideal, output.get(), stdout);
96 }
97 
99  return "genideal";
100 }
BigIdeal
Definition: BigIdeal.h:27
DataType.h
IOFacade::writeIdeal
void writeIdeal(const BigIdeal &ideal, IOHandler *handler, FILE *out)
Definition: IOFacade.cpp:156
GenerateIdealAction::_io
IOParameters _io
Definition: GenerateIdealAction.h:42
GenerateIdealAction::_generatorCount
IntegerParameter _generatorCount
Definition: GenerateIdealAction.h:39
stdinc.h
GenerateDataFacade::generateTreeIdeal
void generateTreeIdeal(BigIdeal &ideal, unsigned int varCount)
Definition: GenerateDataFacade.cpp:73
GenerateDataFacade::generateListIdeal
void generateListIdeal(BigIdeal &ideal, size_t varCount)
Definition: GenerateDataFacade.cpp:27
GenerateDataFacade
A facade for random and other kinds of data.
Definition: GenerateDataFacade.h:29
GenerateDataFacade.h
IOParameters::validateFormats
void validateFormats() const
Definition: IOParameters.cpp:154
GenerateIdealAction::GenerateIdealAction
GenerateIdealAction()
Definition: GenerateIdealAction.cpp:26
GenerateDataFacade::generateIdeal
void generateIdeal(BigIdeal &ideal, size_t exponentRange, size_t varCount, size_t generatorCount)
Definition: GenerateDataFacade.cpp:96
Action::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
Action
Definition: Action.h:25
GenerateIdealAction::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: GenerateIdealAction.cpp:53
GenerateDataFacade::generateRookChessIdeal
void generateRookChessIdeal(BigIdeal &ideal, unsigned int n, unsigned int k)
Definition: GenerateDataFacade.cpp:55
GenerateDataFacade::generateEdgeIdeal
void generateEdgeIdeal(BigIdeal &ideal, size_t varCount, size_t generatorCount)
Definition: GenerateDataFacade.cpp:83
GenerateIdealAction::staticGetName
static const char * staticGetName()
Definition: GenerateIdealAction.cpp:98
GenerateDataFacade::generateKnightChessIdeal
void generateKnightChessIdeal(BigIdeal &ideal, unsigned int rowsAndColumns)
Definition: GenerateDataFacade.cpp:46
error.h
GenerateDataFacade::generateKingChessIdeal
void generateKingChessIdeal(BigIdeal &ideal, unsigned int rowsAndColumns)
Definition: GenerateDataFacade.cpp:36
GenerateIdealAction::_variableCount
IntegerParameter _variableCount
Definition: GenerateIdealAction.h:38
GenerateDataFacade::generateMatchingIdeal
void generateMatchingIdeal(BigIdeal &ideal, unsigned int n)
Definition: GenerateDataFacade.cpp:64
IOFacade.h
GenerateIdealAction::_exponentRange
IntegerParameter _exponentRange
Definition: GenerateIdealAction.h:40
reportError
void reportError(const string &errorMsg)
Definition: error.cpp:23
GenerateIdealAction::_type
StringParameter _type
Definition: GenerateIdealAction.h:36
Action::_printActions
BoolParameter _printActions
Definition: Action.h:68
DataType
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition: DataType.h:29
IOParameters::createOutputHandler
auto_ptr< IOHandler > createOutputHandler() const
Definition: IOParameters.cpp:135
GenerateIdealAction::perform
virtual void perform()
Definition: GenerateIdealAction.cpp:63
GenerateIdealAction.h
BigIdeal.h
ParameterGroup::obtainParameters
void obtainParameters(vector< Parameter * > &parameters)
Definition: ParameterGroup.cpp:37
IOFacade
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39