Frobby  0.9.5
IntersectionAction.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 "IntersectionAction.h"
19 
20 #include "BigIdeal.h"
21 #include "IOFacade.h"
22 #include "IntersectFacade.h"
23 #include "Scanner.h"
24 #include "IdealFacade.h"
25 #include "VarSorter.h"
26 #include "ElementDeleter.h"
27 #include "DataType.h"
28 
30  Action
31 (staticGetName(),
32  "Intersect the input ideals.",
33  "Computes the intersection of the input ideals. Simply concatenate "
34  "the textual\n"
35  "representations of the ideals in order to intersect them.\n\n"
36  "Note that this operation is currently implemented in a rather slow way.",
37  false),
38 
39  _io(DataType::getMonomialIdealListType(), DataType::getMonomialIdealType()),
40 
41  _canonical
42  ("canon",
43  "Sort the generators and variables to get a canonical output.",
44  false) {
45 }
46 
47 void IntersectionAction::obtainParameters(vector<Parameter*>& parameters) {
48  _io.obtainParameters(parameters);
49  parameters.push_back(&_canonical);
50  Action::obtainParameters(parameters);
51 }
52 
54  Scanner in(_io.getInputFormat(), stdin);
57 
58  vector<BigIdeal*> ideals;
59  ElementDeleter<vector<BigIdeal*> > idealsDeleter(ideals);
60 
61  IOFacade ioFacade(_printActions);
62  VarNames names;
63  ioFacade.readIdeals(in, ideals, names);
64  in.expectEOF();
65 
67  auto_ptr<BigIdeal> intersection(facade.intersect(ideals, names));
68  idealsDeleter.deleteElements();
69 
70  if (_canonical) {
71  IdealFacade idealFacade(_printActions);
72  idealFacade.sortVariables(*intersection);
73  idealFacade.sortGenerators(*intersection);
74  }
75 
76  auto_ptr<IOHandler> output = _io.createOutputHandler();
77  ioFacade.writeIdeal(*intersection, output.get(), stdout);
78 }
79 
81  return "intersection";
82 }
Definition: Action.h:25
BoolParameter _printActions
Definition: Action.h:68
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition: DataType.h:29
void deleteElements()
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39
void writeIdeal(const BigIdeal &ideal, IOHandler *handler, FILE *out)
Definition: IOFacade.cpp:156
void readIdeals(Scanner &in, vector< BigIdeal * > &ideals, VarNames &names)
Insert the ideals that are read into the parameter ideals.
Definition: IOFacade.cpp:132
void autoDetectInputFormat(Scanner &in)
If using the input format, this must be called before validating the ideals, since the auto detect fo...
auto_ptr< IOHandler > createOutputHandler() const
const string & getInputFormat() const
void validateFormats() const
A facade for performing operations on BigIdeal.
Definition: IdealFacade.h:34
void sortGenerators(BigIdeal &ideal)
Sorts the generators of ideal.
void sortVariables(BigIdeal &ideal)
Sorts the variables of ideal.
A facade for intersecting monomial ideals.
auto_ptr< BigIdeal > intersect(const vector< BigIdeal * > &ideals, const VarNames &names)
Returns the intersection of ideals.
BoolParameter _canonical
virtual void obtainParameters(vector< Parameter * > &parameters)
static const char * staticGetName()
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
Defines the variables of a polynomial ring and facilities IO involving them.
Definition: VarNames.h:40