Frobby  0.9.5
FrobeniusAction.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 "FrobeniusAction.h"
19 
20 #include "BigIdeal.h"
21 #include "IOFacade.h"
22 #include "SliceFacade.h"
23 #include "SliceParams.h"
24 #include "BigTermRecorder.h"
25 #include "Scanner.h"
26 #include "display.h"
27 
29  Action
30 (staticGetName(),
31  "Compute Frobenius number using a Grobner basis algorithm.",
32  "Compute the Frobenius number of the passed-in Frobenius instance. This "
33  "instance\n"
34  "must be preceded in the input by a deg-rev-lex lattice ideal Grobner basis "
35  "as\n"
36  "produced by the program 4ti2.\n\n"
37  "The algorithm for this uses irreducible decomposition to compute the "
38  "Frobenius\n"
39  "number, which is why this action accepts parameters related to that. See "
40  "the\n"
41  "paper \"Solving Thousand Digit Frobenius Problems Using Grobner Bases\"\n"
42  "at www.broune.com for more details.",
43  false),
44 
45  _sliceParams(true, false),
46  _displaySolution
47 ("vector",
48  "Display the vector that achieves the optimal value.",
49  false) {
50  _sliceParams.setSplit("frob");
51 }
52 
53 void FrobeniusAction::obtainParameters(vector<Parameter*>& parameters) {
54  Action::obtainParameters(parameters);
55  _sliceParams.obtainParameters(parameters);
56 
57  parameters.push_back(&_displaySolution);
58 }
59 
62  ("The action frobgrob is DEPRECATED, and will be removed in a future "
63  "release of Frobby. Use the action optimize with options "
64  "-chopFirstAndSubtract and -maxStandard instead to get the same effect.");
65 
66  SliceParams params(_params);
67  validateSplit(params, true, true);
68 
69  vector<mpz_class> instance;
70  BigIdeal ideal;
71 
72  IOFacade ioFacade(_printActions);
73  Scanner in("", stdin);
74  ioFacade.readFrobeniusInstanceWithGrobnerBasis(in, ideal, instance);
75  in.expectEOF();
76 
77  vector<mpz_class> shiftedDegrees(instance.begin() + 1, instance.end());
78  vector<mpz_class> bigVector;
79 
80  BigTermRecorder recorder;
81 
82  SliceFacade facade(params, ideal, recorder);
83  mpz_class dummy;
84  facade.solveStandardProgram(shiftedDegrees, dummy, false);
85 
86  BigIdeal maxSolution = *(recorder.releaseIdeal());
87 
88  ASSERT(maxSolution.getGeneratorCount() == 1);
89  bigVector = maxSolution[0];
90 
91  mpz_class frobeniusNumber = -instance[0];
92  for (size_t i = 1; i < instance.size(); ++i)
93  frobeniusNumber += bigVector[i - 1] * instance[i];
94 
95  if (_displaySolution) {
96  fputs("(-1", stdout);
97  for (size_t i = 0; i < bigVector.size(); ++i)
98  gmp_fprintf(stdout, ", %Zd", bigVector[i].get_mpz_t());
99  fputs(")\n", stdout);
100  }
101 
102  gmp_fprintf(stdout, "%Zd\n", frobeniusNumber.get_mpz_t());
103 }
104 
106  return "frobgrob";
107 }
108 
110  return false;
111 }
void validateSplit(const SliceParams &params, bool allowLabel, bool allowDegree)
Definition: SliceParams.cpp:61
Definition: Action.h:25
CliParams _params
Definition: Action.h:59
BoolParameter _printActions
Definition: Action.h:68
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
size_t getGeneratorCount() const
Definition: BigIdeal.h:144
BigTermRecorder records all the terms it consumes into an ideal.
auto_ptr< BigIdeal > releaseIdeal()
virtual bool displayAction() const
Returns whether this action should be shown to the user by the help action.
BoolParameter _displaySolution
virtual void obtainParameters(vector< Parameter * > &parameters)
SliceParameters _sliceParams
static const char * staticGetName()
virtual void perform()
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39
void readFrobeniusInstanceWithGrobnerBasis(Scanner &in, BigIdeal &ideal, vector< mpz_class > &instance)
Definition: IOFacade.cpp:276
void obtainParameters(vector< Parameter * > &parameters)
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition: Scanner.h:50
void expectEOF()
Require that there is no more input.
Definition: Scanner.cpp:77
A facade for operations on monomial ideals using the Slice Algorithm.
Definition: SliceFacade.h:44
bool solveStandardProgram(const vector< mpz_class > &grading, mpz_class &value, bool reportAllSolutions)
Solve an optimization program over maximal standard monomials.
void setSplit(const string &split)
Set the value of the option for choosing the split selection strategy.
void displayNote(const string &msg)
Display msg to standard error in a way that indicates that this is something that the user should tak...
Definition: display.cpp:135
This file contains functions for printing strings to standard error.
#define ASSERT(X)
Definition: stdinc.h:86