Frobby 0.9.5
IntersectFacade.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 "IntersectFacade.h"
19
20#include "Term.h"
21#include "BigIdeal.h"
22#include "Ideal.h"
23#include "intersect.h"
24#include "Ideal.h"
25#include "TermTranslator.h"
26#include "ElementDeleter.h"
27
29 Facade(printActions) {
30}
31
32auto_ptr<BigIdeal> IntersectFacade::intersect(const vector<BigIdeal*>& ideals,
33 const VarNames& emptyNames) {
34 beginAction("Intersecting ideals.");
35
36 if (ideals.empty()) {
37 auto_ptr<BigIdeal> entireRing(new BigIdeal(emptyNames));
38 entireRing->newLastTerm();
39 return entireRing;
40 }
41
42 vector<Ideal*> ideals2;
43 ElementDeleter<vector<Ideal*> > ideals2Deleter(ideals2);
44 TermTranslator translator(ideals, ideals2);
45
46 const VarNames& names = translator.getNames();
47 size_t variableCount = names.getVarCount();
48
49 auto_ptr<Ideal> intersection(new Ideal(variableCount));
50 Term identity(variableCount);
51 intersection->insert(identity);
52
53 for (size_t i = 0; i < ideals2.size(); ++i) {
54 ideals2[i]->minimize();
55
56 // Compute intersection
57 auto_ptr<Ideal> tmp(new Ideal(variableCount));
58 ::intersect(tmp.get(), intersection.get(), ideals2[i]);
59
60 // Handle bookkeeping
61 intersection = tmp;
62 }
63
64 auto_ptr<BigIdeal> bigIdeal(new BigIdeal(names));
65 bigIdeal->insert(*intersection, translator);
66
67 endAction();
68 return bigIdeal;
69}
This is the super class of all facades.
Definition Facade.h:32
void beginAction(const char *message)
Prints message to standard error if printing is turned on, and records the time when the action start...
Definition Facade.cpp:38
void endAction()
Prints to standard error the time since the last call to beginAction.
Definition Facade.cpp:51
Represents a monomial ideal with int exponents.
Definition Ideal.h:27
IntersectFacade(bool printActions)
auto_ptr< BigIdeal > intersect(const vector< BigIdeal * > &ideals, const VarNames &names)
Returns the intersection of ideals.
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
const VarNames & getNames() const
Term represents a product of variables which does not include a coefficient.
Definition Term.h:49
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
size_t getVarCount() const
Returns the current number of variables.
Definition VarNames.h:113
This header file includes common definitions and is included as the first line of code in every imple...