IntersectionAction.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include "stdinc.h"
#include "IntersectionAction.h"
#include "BigIdeal.h"
#include "IOFacade.h"
#include "IntersectFacade.h"
#include "Scanner.h"
#include "IdealFacade.h"
#include "VarSorter.h"
#include "ElementDeleter.h"
#include "DataType.h"
IntersectionAction::IntersectionAction():
Action
(staticGetName(),
"Intersect the input ideals.",
"Computes the intersection of the input ideals. Simply concatenate "
"the textual\n"
"representations of the ideals in order to intersect them.\n\n"
"Note that this operation is currently implemented in a rather slow way.",
false),
_io(DataType::getMonomialIdealListType(), DataType::getMonomialIdealType()),
_canonical
("canon",
"Sort the generators and variables to get a canonical output.",
false) {
}
void IntersectionAction::obtainParameters(vector<Parameter*>& parameters) {
_io.obtainParameters(parameters);
parameters.push_back(&_canonical);
Action::obtainParameters(parameters);
}
void IntersectionAction::perform() {
Scanner in(_io.getInputFormat(), stdin);
_io.autoDetectInputFormat(in);
_io.validateFormats();
vector<BigIdeal*> ideals;
ElementDeleter<vector<BigIdeal*> > idealsDeleter(ideals);
IOFacade ioFacade(_printActions);
VarNames names;
ioFacade.readIdeals(in, ideals, names);
in.expectEOF();
IntersectFacade facade(_printActions);
unique_ptr<BigIdeal> intersection(facade.intersect(ideals, names));
idealsDeleter.deleteElements();
if (_canonical) {
IdealFacade idealFacade(_printActions);
idealFacade.sortVariables(*intersection);
idealFacade.sortGenerators(*intersection);
}
unique_ptr<IOHandler> output = _io.createOutputHandler();
ioFacade.writeIdeal(*intersection, output.get(), stdout);
}
const char* IntersectionAction::staticGetName() {
return "intersection";
}
BigIdeal.h
DataType.h
ElementDeleter.h
IOFacade.h
IdealFacade.h
IntersectFacade.h
IntersectionAction.h
Scanner.h
VarSorter.h
Action::_printActions
BoolParameter _printActions
Definition Action.h:68
Action::Action
Action(const char *name, const char *shortDescription, const char *description, bool acceptsNonParameter)
Definition Action.cpp:46
Action::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition Action.cpp:133
DataType
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition DataType.h:29
ElementDeleter
Definition ElementDeleter.h:50
ElementDeleter::deleteElements
void deleteElements()
Definition ElementDeleter.h:72
IOFacade
A facade for input and output of mathematical objects.
Definition IOFacade.h:39
IOFacade::writeIdeal
void writeIdeal(const BigIdeal &ideal, IOHandler *handler, FILE *out)
Definition IOFacade.cpp:156
IOFacade::readIdeals
void readIdeals(Scanner &in, vector< BigIdeal * > &ideals, VarNames &names)
Insert the ideals that are read into the parameter ideals.
Definition IOFacade.cpp:132
IdealFacade
A facade for performing operations on BigIdeal.
Definition IdealFacade.h:34
IdealFacade::sortGenerators
void sortGenerators(BigIdeal &ideal)
Sorts the generators of ideal.
Definition IdealFacade.cpp:237
IdealFacade::sortVariables
void sortVariables(BigIdeal &ideal)
Sorts the variables of ideal.
Definition IdealFacade.cpp:245
IntersectFacade
A facade for intersecting monomial ideals.
Definition IntersectFacade.h:31
IntersectFacade::intersect
unique_ptr< BigIdeal > intersect(const vector< BigIdeal * > &ideals, const VarNames &names)
Returns the intersection of ideals.
Definition IntersectFacade.cpp:32
IntersectionAction::_canonical
BoolParameter _canonical
Definition IntersectionAction.h:36
IntersectionAction::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition IntersectionAction.cpp:47
IntersectionAction::IntersectionAction
IntersectionAction()
Definition IntersectionAction.cpp:29
IntersectionAction::perform
virtual void perform()
Definition IntersectionAction.cpp:53
IntersectionAction::_io
IOParameters _io
Definition IntersectionAction.h:35
IntersectionAction::staticGetName
static const char * staticGetName()
Definition IntersectionAction.cpp:80
Scanner
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition Scanner.h:50
Scanner::expectEOF
void expectEOF()
Require that there is no more input.
Definition Scanner.cpp:77
VarNames
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...