DiaDes  0.1
DIAgnosis of Discrete-Event System
Vdd.hh
Go to the documentation of this file.
1 /*
2  * Vdd.hh
3  *
4  * Created on: 28 août 2008
5  * Author: ypencole
6  */
7 
8 #ifndef __DIADES__PETRI__VDD__HH__
9 #define __DIADES__PETRI__VDD__HH__
10 
11 #include <vector>
13 #include <diades/petri/Net.hh>
14 
15 
16 namespace Diades
17 {
18  namespace Petri
19  {
23  class VddInvalid : public runtime_error, public domain_error {
24  public:
28  VddInvalid(const string& whatArg) : runtime_error(whatArg), domain_error(whatArg){
29  cerr << "EXCEPTION Vdd -> " << whatArg << endl;
30  }
31  };
32 
33  class VddFactory;
34 
35 
44  class Vdd
45  {
46  private:
47 
49  int _tokens;
50  const Vdd * _eq;
51  const Vdd * _sup;
52  unsigned _id;
54 
55 
56  public:
60  Vdd():_place(),_tokens(0),_eq(0),_sup(0),_id(0),_factory(0){}
61 
65  Vdd(VddFactory * factory):_place(),_tokens(0),_eq(0),_sup(0),_id(0),_factory(factory){}
66 
67  private:
77  Vdd(Place p, int tokens, const Vdd * eq, const Vdd * sup, unsigned id, VddFactory * factory):
78  _place(p), _tokens(tokens), _eq(eq), _sup(sup), _id(id), _factory(factory){
79  require(VddInvalid,p.valid(),"Vdd: invalid place");
80  require(VddInvalid,id > 0, "Vdd: null id");
81  require(VddInvalid,tokens >= 0, "Vdd: negative number of tokens");
82  }
83 
84  public:
85 
89  virtual ~Vdd(){}
90 
95  unsigned id() const { return _id; }
96 
101  int tokens() const { return _tokens; }
102 
107  Place place() const { return _place; }
108 
113  const Vdd * eq() const { return _eq; }
114 
115 
116 
121  const Vdd * sup() const { return _sup; }
122 
127  int getCardinality() const;
128 
133  bool isEmpty() const;
134 
141  bool holds(Place p, int tokens) const;
142 
143 
148  bool isNull() const;
149 
150 
151 
156  bool valid() const
157  {
158  return (tokens() >= 0) && (id() > 0) && (place().valid()) && ( (eq()->isEmpty()) || (eq()->isNull()) || ( eq()->valid() && (eq()->place() > place()) ))
159  && ( (sup()->isEmpty()) || (sup()->isNull()) || ( sup()->valid() && (sup()->place() == place()) && (sup()->tokens() > tokens()) ));
160  }
161 
162  friend class VddFactory;
163 
164  };
165 
170  {
171 
172  private:
173  const Net * _net;
174  vector< vector< unordered_map<unsigned, unordered_map <unsigned, Vdd *> > > > _vdd;
175  vector<Vdd *> _table;
176  vector<int> _card;
179 
180  public:
185  VddFactory(const Net & net):
186  _net(&net),
187  _vdd(net.numberOfPlaces()+1),
188  _table(2),_card(2),
189  _empty(0),_null(0){
190  _table[0] = new Vdd(this);
191  _table[1] = new Vdd(this);
192  _empty = _table[1];
193  _null = _table[0];
194  _empty->_id = 1;
195  _null->_id = 0;
196  _card[0] = 1; // null vector represents the marking 0 0 0 0
197  _card[1] = 0; // empty vector represents "empty set"
198  }
199 
203  virtual ~VddFactory();
204 
215  const Vdd * getVdd(Place place, int tokens, const Vdd * eq, const Vdd * sup);
216 
217 
223  int getCardinality(const Vdd * vdd);
224 
225 
233  bool holds(const Vdd * vdd, Place p, int tokens) const;
234 
235 
242  const Vdd * getVdd(const Vdd * vdd, const Zsl * zsl);
243 
244 
245 
246 
252  const Vdd * getVdd(const set<Place> & marking);
253 
259  bool isEmpty(const Vdd * vdd) const { return vdd == _empty; }
260 
261 
267  bool isNull(const Vdd * vdd) const { return vdd == _null; }
268 
269 
276  const Vdd * getVdd(unsigned id) { if(id >= _table.size()) { return 0; } return _table[id]; }
277 
285  const Vdd * addZslToVdd(const Vdd * vdd, const Zsl * zsl);
286 
293  const Vdd * getFirable(const Vdd * vdd, const Zsl * zsl);
294 
295 
302  const Vdd * getUnion(const Vdd * vdd1, const Vdd * vdd2);
303 
310  const Vdd * getIntersection(const Vdd * vdd1, const Vdd * vdd2);
311 
316  const Net * owner() const { return _net; }
317 
318 
323  void printDot(const string & fileName) const;
324 
329  void printDot(const Vdd * vdd, const string & fileName) const;
330 
331 
336  const Vdd * empty() const { return _empty; }
337 
342  const Vdd * null() const { return _null; }
343  };
344  };
345 };
346 
347 #endif /* VDD_HH_ */
const Vdd * _eq
Definition: Vdd.hh:50
VddFactory * _factory
Definition: Vdd.hh:53
bool isNull(const Vdd *vdd) const
Definition: Vdd.hh:267
VddFactory(const Net &net)
Definition: Vdd.hh:185
const Net * owner() const
Definition: Vdd.hh:316
unsigned _id
Definition: Vdd.hh:52
VddInvalid(const string &whatArg)
Definition: Vdd.hh:28
bool valid() const
Definition: Vdd.hh:156
const Vdd * eq() const
Definition: Vdd.hh:113
bool isEmpty(const Vdd *vdd) const
Definition: Vdd.hh:259
Diades::Graph::Node Place
Definition: BoundedNet.hh:24
const Vdd * empty() const
Definition: Vdd.hh:336
const Vdd * _sup
Definition: Vdd.hh:51
const Vdd * getVdd(unsigned id)
Definition: Vdd.hh:276
vector< vector< unordered_map< unsigned, unordered_map< unsigned, Vdd * > > > > _vdd
Definition: Vdd.hh:174
vector< int > _card
Definition: Vdd.hh:176
Place place() const
Definition: Vdd.hh:107
#define require(Exception, expr, message)
Definition: Assertion.hh:90
Namespace of the Diades project.
const Vdd * null() const
Definition: Vdd.hh:342
Vdd(Place p, int tokens, const Vdd *eq, const Vdd *sup, unsigned id, VddFactory *factory)
Definition: Vdd.hh:77
void printDot(ostream &os, const T &value)
Definition: NodeMap.hh:433
Vdd(VddFactory *factory)
Definition: Vdd.hh:65
const Vdd * sup() const
Definition: Vdd.hh:121
1-bounded Petri nets
Definition: Net.hh:62
vector< Vdd * > _table
Definition: Vdd.hh:175
Place _place
Definition: Vdd.hh:48
unsigned id() const
Definition: Vdd.hh:95
const Net * _net
Definition: Vdd.hh:173
virtual ~Vdd()
Definition: Vdd.hh:89
int tokens() const
Definition: Vdd.hh:101