FlopCpp trunk
Loading...
Searching...
No Matches
MP_domain.hpp
Go to the documentation of this file.
1// ******************** FlopCpp **********************************************
2// File: MP_domain.hpp
3// $Id$
4// Author: Tim Helge Hultberg (thh@mat.ua.pt)
5// Copyright (C) 2003 Tim Helge Hultberg
6// All Rights Reserved.
7// ****************************************************************************
8#ifndef _MP_domain_hpp_
9#define _MP_domain_hpp_
10
11#include <vector>
12#include <map>
13#include "MP_utilities.hpp"
14#include "MP_boolean.hpp"
15#include "MP_index.hpp"
16
17namespace flopc {
18
19class MP_set_base;
20class MP_set;
21class MP_index;
22
23template<int nbr> class MP_subset;
24
30class MP_domain_base : public Functor, public MP_index_base {
31 friend class MP_domain;
32 friend class Handle<MP_domain_base*>;
33 friend MP_domain operator*(const MP_domain& a, const MP_domain& b);
34private:
35 int count;
36public:
38 virtual ~MP_domain_base();
39
40 virtual Functor* makeInsertFunctor() const;
41 virtual MP_index* getIndex() const = 0;
42 virtual const MP_set_base* getSet() const = 0;
43 void display()const;
44 virtual size_t size() const ;
46};
47
61class MP_domain : public Handle<MP_domain_base*> {
62 friend MP_domain operator*(const MP_domain& a, const MP_domain& b);
63
64 friend class MP_constraint;
65 friend class MP_index_exp;
66public:
76
84
89 void Forall(const Functor* op) const;
91 size_t size() const;
93 static const MP_domain& getEmpty();
94private:
95 std::vector<MP_boolean> condition;
97 static const MP_domain* Empty;
98};
99
111public:
115 void operator()() const;
119 int evaluate() const;
121 const MP_set_base* getSet() const;
129private:
130 const MP_set* S;
131 MP_index* I;
132};
133
134template<int nbr> class MP_domain_subset;
135
141 template<int nbr> class insertFunctor : public Functor {
142public:
145 void operator()() const {
146 std::vector<int> elm(nbr);
147 for (int i=0; i<nbr; i++) {
148 elm[i] = D->I[i]->evaluate();
149 }
150 D->S->insert(elm);
151 }
152private:
154};
155
166template<int nbr> class MP_domain_subset : public MP_domain_base {
167 friend class insertFunctor<nbr>;
168public:
170 const std::vector<MP_index*> &i) : S(s), I(i){}
171
175 int evaluate() const {
176 return S->evaluate(I);
177 }
180 return S;
181 }
184 return S;
185 }
190 return MP_domain(const_cast<MP_domain_subset<nbr>*>(this));
191 }
193 void operator()() const {
194 bool isBound[nbr];
195 bool allBound = true;
196 for (int j=0; j<nbr; j++) {
197 if (I[j]->isInstantiated() == true) {
198 isBound[j] = true;
199 } else {
200 isBound[j] = false;
201 allBound = false;
202 if (I[j]!=&MP_index::getEmpty()) {
203 I[j]->instantiate();
204 }
205 }
206 }
207 if (allBound == true) {
208 (*donext)();
209 } else {
210 std::map<std::vector<int>, int>::const_iterator i;
211 int counter = 0;
212 for (i = S->elements.begin(); i != S->elements.end(); i++) {
213 S->assign(counter);
214 counter++;
215 bool goOn = true;
216 for (int j=0; j<nbr; j++) {
217 if (isBound[j] == true) {
218 if (I[j]->evaluate() != i->first[j]) {
219 goOn = false;
220 break;
221 }
222 } else {
223 I[j]->assign(i->first[j]);
224 }
225 }
226 if (goOn == true) {
227 (*donext)();
228 }
229 }
230 }
231 for (int j=0; j<nbr; j++) {
232 if (isBound[j] == false) {
233 I[j]->assign(0);
234 I[j]->unInstantiate();
235 }
236 }
237 }
238
241 return new insertFunctor<nbr>(
242 const_cast<MP_domain_subset<nbr>*>(this));
243 }
244private:
246 std::vector<MP_index*> I;
247};
248
253
254} // End of namespace flopc
255#endif
Function object.
Utility for doing reference counted pointers.
Reference counted class for all "boolean" types of data.
Semantic representation of a linear constraint.
Reference to a set of index values.
Definition MP_domain.hpp:30
virtual const MP_set_base * getSet() const =0
virtual size_t size() const
virtual MP_index * getIndex() const =0
void display() const
friend class MP_domain
Definition MP_domain.hpp:31
const Functor * donext
Definition MP_domain.hpp:45
friend MP_domain operator*(const MP_domain &a, const MP_domain &b)
operator which creates a new domain as the pairwise combinations of two input domains.
virtual Functor * makeInsertFunctor() const
Range over which some other constuct is defined.
MP_index * getIndex() const
Getter for the index used in construction.
const MP_set_base * getSet() const
Getter for the set used in construction.
MP_domain getDomain(MP_set *s) const
void operator()() const
MP_domain_set(const MP_set *s, MP_index *i)
Constructor taking a set pointer and an index pointer.
int evaluate() const
Evaluates the index within the domain.
Range over which some other constuct is defined.
MP_domain getDomain(MP_set *s) const
friend class insertFunctor< nbr >
Functor * makeInsertFunctor() const
MP_index * getIndex() const
getter for obtaining the index used in construction
MP_set_base * getSet() const
getter for obtaining the set used in construction
int evaluate() const
Evaluates the index within the domain.
Range over which some other constuct is defined.
Definition MP_domain.hpp:61
MP_domain()
@briefConstructs a set which points to nothing.
size_t size() const
returns number of elements in the domain.
MP_domain such_that(const MP_boolean &b)
Special conditional creation of a subset.
void Forall(const Functor *op) const
Special conditional operation on the domain.
MP_domain(MP_domain_base *r)
For internal use.
friend MP_domain operator*(const MP_domain &a, const MP_domain &b)
operator which creates a new domain as the pairwise combinations of two input domains.
static const MP_domain & getEmpty()
returns a reference to the "empty" set.
Internal representation of a index.
Definition MP_index.hpp:26
Representation of an expression involving an index.
Definition MP_index.hpp:145
Representation of an index.
Definition MP_index.hpp:53
static MP_index & getEmpty()
returns a reference to the distinct "empty" index.
Internal representation of a "set".
Definition MP_set.hpp:28
Representation of a set for indexing into some other construct.
Definition MP_set.hpp:78
Internal representation of a "set".
Definition MP_set.hpp:161
Inserter for construction of a subset.
insertFunctor(MP_domain_subset< nbr > *d)
void operator()() const
Constant operator*(const Constant &a, const Constant &b)
Returns the product of two constants.
All flopc++ code is contained within the flopc namespace.
Definition flopc.hpp:49