FLOPC++
MP_domain.cpp
Go to the documentation of this file.
1 // ******************** FlopCpp **********************************************
2 // File: MP_domain.cpp
3 // $Id$
4 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 // Copyright (C) 2003 Tim Helge Hultberg
6 // All Rights Reserved.
7 //****************************************************************************
8 
9 #include "MP_domain.hpp"
10 #include "MP_set.hpp"
11 #include "MP_boolean.hpp"
12 #include "MP_model.hpp"
13 
14 namespace flopc {
16  : S(s), I(i) {}
19  return MP_domain(const_cast<MP_domain_set*>(this));
20  }
21 
22  class Functor_conditional : public Functor {
23  public:
24  Functor_conditional(const Functor* f, const std::vector<MP_boolean> & condition)
25  : F(f), Condition(condition) {}
26  virtual ~Functor_conditional() {}
27  void operator()() const {
28  bool goOn = true;
29  for (size_t i = 0; i<Condition.size(); i++) {
30  if (Condition[i]->evaluate()==false) {
31  goOn = false;
32  break;
33  }
34  }
35  if (goOn == true) {
36  F->operator()();
37  }
38  }
39  const Functor* F;
40  std::vector<MP_boolean> Condition;
41  };
42 }
43 
44 using namespace flopc;
45 
46 const MP_domain* MP_domain::Empty = 0;
47 
49  if(Empty == 0) {
51  }
52  return *Empty;
53 }
54 
55 
56 MP_domain_base::MP_domain_base() : count(0), donext(0) {}
58 
60  return 0;
61 }
62 
63 size_t MP_domain_base::size() const {
64  return count;
65 }
66 
67 
69  std::stringstream ss;
70  ss<<"domain_base::display() size="<<size()<<std::ends;
71  MP_model::getCurrentModel()->getMessenger()->logMessage(5,ss.str().c_str());
72 }
73 
77 
79  if (b.operator ->() != 0) {
80  condition.push_back(b);
81  }
82  return *this;
83 }
84 
85 void MP_domain::forall(const Functor& op) const {
86  forall(&op);
87 }
88 void MP_domain::forall(const Functor* op) const {
89  if (condition.size()>0) {
91  } else {
92  last->donext = op;
93  }
94  operator->()->operator()();
95 }
96 
98  return S;
99 }
100 
101 size_t MP_domain::size() const {
102  return operator->()->getSet()->size();
103 }
104 
106  return I->evaluate();
107 }
108 
110  if (I->isInstantiated() == true) {
111  (*donext)();
112  } else {
113  I->instantiate();
114  for (int k=0; k<S->size(); k++) {
115  I->assign(k);
116  (*donext)();
117  }
118  I->assign(0);
119  I->unInstantiate();
120  }
121 }
122 
124  return I;
125 }
126 
127 
129  if (a.operator->() == MP_domain::getEmpty().operator->()) {
130  return b;
131  } else if (b.operator->() == MP_domain::getEmpty().operator->()) {
132  return a;
133  } else {
134  MP_domain retval = a;
135  retval.last->donext = b.operator->();
136  const_cast<MP_domain&>(b).increment();
137  const_cast<MP_domain&>(a).increment();
138  retval.last = b.last;
139  retval.condition.insert(retval.condition.end(),b.condition.begin(),
140  b.condition.end());
141  return retval;
142  }
143 
144 }
static MP_set & getEmpty()
gets the distinct 'empty' MP_set.
Definition: MP_set.cpp:17
MP_domain such_that(const MP_boolean &b)
Special conditional creation of a subset.
Definition: MP_domain.cpp:78
virtual Functor * makeInsertFunctor() const
Definition: MP_domain.cpp:59
const MP_set * S
Definition: MP_domain.hpp:131
Handle< MP_domain_base * > last
Definition: MP_domain.hpp:97
std::vector< MP_boolean > Condition
Definition: MP_domain.cpp:40
static const MP_domain * Empty
Definition: MP_domain.hpp:98
Functor_conditional(const Functor *f, const std::vector< MP_boolean > &condition)
Definition: MP_domain.cpp:24
static MP_model * getCurrentModel()
Definition: MP_model.cpp:27
MP_domain_set(const MP_set *s, MP_index *i)
Constructor taking a set pointer and an index pointer.
Definition: MP_domain.cpp:15
Messenger * getMessenger()
Definition: MP_model.hpp:230
Representation of an index.This is one of the main public interface classes. It is used to iterate th...
Definition: MP_index.hpp:53
int evaluate() const
Definition: MP_index.hpp:59
const Functor * donext
Definition: MP_domain.hpp:45
Utility for doing reference counted pointers.
virtual size_t size() const
Definition: MP_domain.cpp:63
void operator()() const
Definition: MP_domain.cpp:27
virtual int size() const
getter for the cardinality of this MP_set.
Definition: MP_set.hpp:107
Range over which some other constuct is defined.This is one of the main public interface classes...
Definition: MP_domain.hpp:111
Reference to a set of index values.
Definition: MP_domain.hpp:30
MP_domain getDomain(MP_set *s) const
Definition: MP_domain.cpp:18
void operator()() const
Definition: MP_domain.cpp:109
std::vector< MP_boolean > condition
Definition: MP_domain.hpp:96
bool isInstantiated() const
Definition: MP_index.hpp:69
size_t size() const
returns number of elements in the domain.
Definition: MP_domain.cpp:101
All flopc++ code is contained within the flopc namespace.
Definition: flopc.cpp:11
const T & operator->() const
const MP_set_base * getSet() const
Getter for the set used in construction.
Definition: MP_domain.cpp:97
Reference counted class for all "boolean" types of data.This contains counters to ConstantBase pointe...
Definition: MP_boolean.hpp:40
Range over which some other constuct is defined.This is one of the main public interface classes...
Definition: MP_domain.hpp:61
friend class MP_domain
Definition: MP_domain.hpp:31
static const MP_domain & getEmpty()
returns a reference to the "empty" set.
Definition: MP_domain.cpp:48
void unInstantiate()
Definition: MP_index.hpp:80
Function object. Often used.
Representation of a set for indexing into some other construct.This is one of the main public interfa...
Definition: MP_set.hpp:79
int evaluate() const
Definition: MP_domain.cpp:105
void forall(const Functor *op) const
Special conditional operation on the domain.
Definition: MP_domain.cpp:88
Constant operator*(const Constant &a, const Constant &b)
Returns the product of two constants.This is used in the formation of an expression.
Internal representation of a "set".
Definition: MP_set.hpp:30
MP_index * getIndex() const
Getter for the index used in construction.
Definition: MP_domain.cpp:123
virtual void logMessage(int level, const char *const msg)
Definition: MP_model.hpp:38
void display() const
Definition: MP_domain.cpp:68
void instantiate()
Definition: MP_index.hpp:85
virtual ~MP_domain_base()
Definition: MP_domain.cpp:57
void assign(int i)
Definition: MP_index.hpp:75