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 }