Frobby 0.9.5
Projection.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 "Projection.h"
19
20#include "Term.h"
21#include "Partition.h"
22#include <algorithm>
23
25 return _offsets.size();
26}
27
28void Projection::reset(const Partition& partition,
29 int number) {
30 _offsets.clear();
31
32 size_t root = 0xFFFFFFFF;
33 for (size_t i = 0; i < partition.getSize(); ++i) {
34 if (i == partition.getRoot(i)) {
35 if (number == 0) {
36 root = i;
37 break;
38 }
39 --number;
40 }
41 }
42 ASSERT(number == 0 && root != 0xFFFFFFFF);
43
44 for (size_t i = 0; i < partition.getSize(); ++i) {
45 if (partition.getRoot(i) != root)
46 continue;
47
48 _offsets.push_back(i);
49 }
50
52}
53
54void Projection::reset(const vector<size_t>& inverseProjections) {
55 _offsets = inverseProjections;
57}
58
59void Projection::setToIdentity(size_t varCount) {
60 _offsets.clear();
61 for (size_t var = 0; var < varCount; ++var)
62 _offsets.push_back(var);
64}
65
66
67size_t Projection::getDomainVar(size_t rangeVar) {
68 ASSERT(rangeVar < getRangeVarCount());
69 return _offsets[rangeVar];
70}
71
72void Projection::project(Exponent* to, const Exponent* from) const {
73 size_t size = _offsets.size();
74 for (size_t i = 0; i < size; ++i)
75 to[i] = from[_offsets[i]];
76}
77
78void Projection::inverseProject(Term& to, const Exponent* from) const {
79 size_t size = _offsets.size();
80 for (size_t i = 0; i < size; ++i)
81 to[_offsets[i]] = from[i];
82}
83
84size_t Projection::inverseProjectVar(size_t rangeVar) const {
85 ASSERT(rangeVar < _offsets.size());
86 return _offsets[rangeVar];
87}
88
89bool Projection::domainVarHasProjection(size_t var) const {
90 if (var >= _domainVarHasProjection.size())
91 _domainVarHasProjection.resize(var + 1);
92
93#ifdef DEBUG
94 bool has = false;
95 for (size_t rangeVar = 0; rangeVar < _offsets.size(); ++rangeVar)
96 if (var == inverseProjectVar(rangeVar))
97 has = true;
98 ASSERT(has == static_cast<bool>(_domainVarHasProjection[var]));
99#endif
100
101 return _domainVarHasProjection[var];
102}
103
104void Projection::print(FILE* file) const {
105 fputs("Projection:", file);
106 for (size_t var = 0; var < _offsets.size(); ++var)
107 fprintf(file, " %lu", (unsigned long)_offsets[var]);
108 fputc('\n', file);
109}
110
111void Projection::swap(Projection& projection) {
112 _offsets.swap(projection._offsets);
114}
115
118 if (_offsets.empty())
119 return;
120
121 size_t max = *max_element(_offsets.begin(), _offsets.end());
122 _domainVarHasProjection.resize(max + 1);
123
124 for (size_t rangeVar = 0; rangeVar < _offsets.size(); ++rangeVar) {
127 }
128}
size_t getSize() const
size_t getRoot(size_t i) const
void swap(Projection &projection)
void inverseProject(Term &to, const Exponent *from) const
void reset(const Partition &partition, int set)
void updateHasProjections()
size_t getDomainVar(size_t rangeVar)
void setToIdentity(size_t varCount)
vector< int > _domainVarHasProjection
Definition Projection.h:56
bool domainVarHasProjection(size_t var) const
void print(FILE *file) const
void project(Exponent *to, const Exponent *from) const
size_t inverseProjectVar(size_t rangeVar) const
size_t getRangeVarCount() const
vector< size_t > _offsets
Definition Projection.h:55
Term represents a product of variables which does not include a coefficient.
Definition Term.h:49
This header file includes common definitions and is included as the first line of code in every imple...
unsigned int Exponent
Definition stdinc.h:89
#define ASSERT(X)
Definition stdinc.h:86