Frobby  0.9.5
GenerateFrobeniusAction.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"
19 
20 #include "BigIdeal.h"
21 #include "GenerateDataFacade.h"
22 #include "IOFacade.h"
23 #include "error.h"
24 
26  Action
27 (staticGetName(),
28  "Generate a random Frobenius problem instance.",
29  "Generate a random Frobenius problem instance.",
30  false),
31 
32  _entryCount
33  ("entryCount",
34  "The number of entries in the random instance.",
35  4),
36 
37  _maxEntryDigits
38  ("maxEntryDigits",
39  "The largest allowed number of decimal digits for entries in the\n"
40  "random instance.",
41  2) {
42 }
43 
45 obtainParameters(vector<Parameter*>& parameters) {
46  Action::obtainParameters(parameters);
47  parameters.push_back(&_entryCount);
48  parameters.push_back(&_maxEntryDigits);
49 }
50 
52  vector<mpz_class> instance;
53 
54  if (_entryCount < 1)
55  reportError("There must be at least one entry.");
56  if (_maxEntryDigits < 1)
57  reportError("The largest allowed number of digits must be at least 1.");
58 
59  mpz_class maxEntry;
60  mpz_ui_pow_ui(maxEntry.get_mpz_t(), 10, _maxEntryDigits.getValue());
61 
64  (instance, _entryCount.getValue(), maxEntry);
65 
66  IOFacade ioFacade(_printActions);
67  ioFacade.writeFrobeniusInstance(stdout, instance);
68 }
69 
71  return "genfrob";
72 }
Definition: Action.h:25
BoolParameter _printActions
Definition: Action.h:68
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
A facade for random and other kinds of data.
void generateFrobeniusInstance(vector< mpz_class > &instance, size_t entryCount, const mpz_class &maxEntry)
static const char * staticGetName()
virtual void obtainParameters(vector< Parameter * > &parameters)
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39
void writeFrobeniusInstance(FILE *out, vector< mpz_class > &instance)
Definition: IOFacade.cpp:305
unsigned int getValue() const
void reportError(const string &errorMsg)
Definition: error.cpp:23