forked from broune/frobby
-
Notifications
You must be signed in to change notification settings - Fork 3
/
IntersectFacade.cpp
69 lines (54 loc) · 2.1 KB
/
IntersectFacade.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* 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 "IntersectFacade.h"
#include "Term.h"
#include "BigIdeal.h"
#include "Ideal.h"
#include "intersect.h"
#include "Ideal.h"
#include "TermTranslator.h"
#include "ElementDeleter.h"
IntersectFacade::IntersectFacade(bool printActions):
Facade(printActions) {
}
auto_ptr<BigIdeal> IntersectFacade::intersect(const vector<BigIdeal*>& ideals,
const VarNames& emptyNames) {
beginAction("Intersecting ideals.");
if (ideals.empty()) {
auto_ptr<BigIdeal> entireRing(new BigIdeal(emptyNames));
entireRing->newLastTerm();
return entireRing;
}
vector<Ideal*> ideals2;
ElementDeleter<vector<Ideal*> > ideals2Deleter(ideals2);
TermTranslator translator(ideals, ideals2);
const VarNames& names = translator.getNames();
size_t variableCount = names.getVarCount();
auto_ptr<Ideal> intersection(new Ideal(variableCount));
Term identity(variableCount);
intersection->insert(identity);
for (size_t i = 0; i < ideals2.size(); ++i) {
ideals2[i]->minimize();
// Compute intersection
auto_ptr<Ideal> tmp(new Ideal(variableCount));
::intersect(tmp.get(), intersection.get(), ideals2[i]);
// Handle bookkeeping
intersection = tmp;
}
auto_ptr<BigIdeal> bigIdeal(new BigIdeal(names));
bigIdeal->insert(*intersection, translator);
endAction();
return bigIdeal;
}