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 
17 namespace flopc {
18 
19 class MP_set_base;
20 class MP_set;
21 class MP_index;
22 
23 template<int nbr> class MP_subset;
24 
30 class 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);
34 private:
35  int count;
36 public:
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 ;
45  const Functor* donext;
46 };
47 
61 class 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;
66 public:
70  MP_domain();
71  ~MP_domain();
76 
83  MP_domain such_that(const MP_boolean& b);
84 
89  void Forall(const Functor* op) const;
91  size_t size() const;
93  static const MP_domain& getEmpty();
94 private:
95  std::vector<MP_boolean> condition;
97  static const MP_domain* Empty;
98 };
99 
111 public:
113  MP_domain_set(const MP_set* s, MP_index* i);
115  void operator()() const;
119  int evaluate() const;
121  const MP_set_base* getSet() const;
123  MP_index* getIndex() const;
127  MP_domain getDomain(MP_set* s) const ;
128  ~MP_domain_set();
129 private:
130  const MP_set* S;
132 };
133 
134 template<int nbr> class MP_domain_subset;
135 
141  template<int nbr> class insertFunctor : public Functor {
142 public:
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  }
152 private:
154 };
155 
166 template<int nbr> class MP_domain_subset : public MP_domain_base {
167  friend class insertFunctor<nbr>;
168 public:
170  const std::vector<MP_index*> &i) : S(s), I(i){}
171 
175  int evaluate() const {
176  return S->evaluate(I);
177  }
179  MP_set_base* getSet() const {
180  return S;
181  }
183  MP_index* getIndex() const {
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  }
244 private:
246  std::vector<MP_index*> I;
247 };
248 
252 MP_domain operator*(const MP_domain& a, const MP_domain& b);
253 
254 } // End of namespace flopc
255 #endif
friend class MP_domain
Definition: MP_domain.hpp:31
Representation of an index.
Definition: MP_index.hpp:53
insertFunctor(MP_domain_subset< nbr > *d)
Definition: MP_domain.hpp:143
size_t size() const
returns number of elements in the domain.
MP_index * getIndex() const
getter for obtaining the index used in construction
Definition: MP_domain.hpp:183
std::vector< MP_boolean > condition
Definition: MP_domain.hpp:95
Constant operator*(const Constant &a, const Constant &b)
Returns the product of two constants.
MP_domain_subset< nbr > * D
Definition: MP_domain.hpp:153
MP_domain such_that(const MP_boolean &b)
Special conditional creation of a subset.
MP_domain getDomain(MP_set *s) const
Definition: MP_domain.hpp:189
std::vector< MP_index * > I
Definition: MP_domain.hpp:246
static MP_index & getEmpty()
returns a reference to the distinct &quot;empty&quot; index.
const MP_set_base * getSet() const
Getter for the set used in construction.
Internal representation of a &quot;set&quot;.
Definition: MP_domain.hpp:23
static const MP_domain * Empty
Definition: MP_domain.hpp:97
Functor * makeInsertFunctor() const
Definition: MP_domain.hpp:240
Semantic representation of a linear constraint.
Handle< MP_domain_base * > last
Definition: MP_domain.hpp:96
void operator()() const
Definition: MP_domain.hpp:193
Reference counted class for all &quot;boolean&quot; types of data.
Definition: MP_boolean.hpp:45
virtual size_t size() const
Utility for doing reference counted pointers.
int evaluate() const
Evaluates the index within the domain.
void operator()() const
int evaluate() const
Evaluates the index within the domain.
Definition: MP_domain.hpp:175
const Functor * donext
Definition: MP_domain.hpp:45
Range over which some other constuct is defined.
Definition: MP_domain.hpp:134
Internal representation of a index.
Definition: MP_index.hpp:26
MP_index * getIndex() const
Getter for the index used in construction.
Function object.
void display() const
Representation of a set for indexing into some other construct.
Definition: MP_set.hpp:78
void Forall(const Functor *op) const
Special conditional operation on the domain.
Representation of an expression involving an index.
Definition: MP_index.hpp:145
static const MP_domain & getEmpty()
returns a reference to the &quot;empty&quot; set.
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.
MP_domain getDomain(MP_set *s) const
virtual MP_index * getIndex() const =0
const MP_set * S
Definition: MP_domain.hpp:130
void operator()() const
Definition: MP_domain.hpp:145
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.
Inserter for construction of a subset.
Definition: MP_domain.hpp:141
MP_domain_set(const MP_set *s, MP_index *i)
Constructor taking a set pointer and an index pointer.
Range over which some other constuct is defined.
Definition: MP_domain.hpp:61
Reference to a set of index values.
Definition: MP_domain.hpp:30
MP_domain()
a set which points to nothing.
MP_subset< nbr > * S
Definition: MP_domain.hpp:245
virtual const MP_set_base * getSet() const =0
virtual Functor * makeInsertFunctor() const
Internal representation of a &quot;set&quot;.
Definition: MP_set.hpp:28
Range over which some other constuct is defined.
Definition: MP_domain.hpp:110
MP_set_base * getSet() const
getter for obtaining the set used in construction
Definition: MP_domain.hpp:179