Frobby  0.9.0
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 }
void generateMatchingIdeal(BigIdeal &ideal, unsigned int n)
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
void generateKingChessIdeal(BigIdeal &ideal, unsigned int rowsAndColumns)
void generateTreeIdeal(BigIdeal &ideal, unsigned int varCount)
BoolParameter _printActions
Definition: Action.h:68
void generateEdgeIdeal(BigIdeal &ideal, size_t varCount, size_t generatorCount)
void generateRookChessIdeal(BigIdeal &ideal, unsigned int n, unsigned int k)
void writeIdeal(const BigIdeal &ideal, IOHandler *handler, FILE *out)
Definition: IOFacade.cpp:156
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition: DataType.h:29
Definition: Action.h:25
void generateKnightChessIdeal(BigIdeal &ideal, unsigned int rowsAndColumns)
void validateFormats() const
void generateIdeal(BigIdeal &ideal, size_t exponentRange, size_t varCount, size_t generatorCount)
auto_ptr< IOHandler > createOutputHandler() const
void obtainParameters(vector< Parameter * > &parameters)
IntegerParameter _variableCount
static const char * staticGetName()
void generateListIdeal(BigIdeal &ideal, size_t varCount)
virtual void obtainParameters(vector< Parameter * > &parameters)
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39
IntegerParameter _exponentRange
IntegerParameter _generatorCount
void reportError(const string &errorMsg)
Definition: error.cpp:23
A facade for random and other kinds of data.