DiaDes  0.1
DIAgnosis of Discrete-Event System
Zsl.hh
Go to the documentation of this file.
1 /*
2  * Zsl.hh
3  *
4  * Created on: 26 août 2008
5  * Author: ypencole
6  */
7 
8 #ifndef __DIADES__PETRI__ZSL__HH__
9 #define __DIADES__PETRI__ZSL__HH__
10 
11 
12 
13 
14 #include <sstream>
15 #include <vector>
17 #include <diades/petri/Net.hh>
18 
19 namespace Diades
20 {
21 namespace Petri
22 {
23 
27 class ZslInvalid : public runtime_error, public domain_error {
28 public:
32  ZslInvalid(const string& whatArg) : runtime_error(whatArg), domain_error(whatArg){
33  cerr << "EXCEPTION Zsl -> " << whatArg << endl;
34  }
35 };
36 
37 class ZslFactory;
38 
48 class Zsl
49 {
50 private:
51  int _value;
52  unsigned _id;
54  const Zsl * _next;
55 
56 public:
60  Zsl():_value(0),_id(0),_place(),_next(0){}
61 
62 private:
71  Zsl(Place p, int value, const Zsl * zsl, unsigned id ):_value(value), _id(id), _place(p), _next(zsl) {
72  require(ZslInvalid,p.valid(),"Zsl: invalid place");
73  require(ZslInvalid,id > 0, "Zsl: null id");
74  require(ZslInvalid,value != 0, "Zsl: null value");
75  require(ZslInvalid,(zsl == 0) || (zsl->valid()), "invalid next");
76  }
77 
78 
79 
80 public:
81 
85  virtual ~Zsl(){}
86 
91  unsigned id() const { return _id; }
92 
97  int value() const { return _value; }
98 
103  Place place() const { return _place; }
104 
109  const Zsl * next() const { return _next; }
110 
115  bool valid() const
116  {
117  return (id() > 0) && (place().valid()) && (value()!=0) && ( (next() == 0) || (next()->valid()));
118  }
119 
120 
121 
128  friend ostream & operator<<(ostream & os, const Zsl & zsl);
129 
130  friend class ZslFactory;
131 };
132 
133 
138 {
139 
140 private:
141  const Net * _net;
142  vector< vector< unordered_map<unsigned, Zsl *> > > _negTable;
143  vector< vector< unordered_map<unsigned, Zsl *> > > _posTable;
144  vector<Zsl *> _table;
145 
146 public:
151  ZslFactory(const Net & net):
152  _net(&net),
153  _negTable(net.numberOfPlaces()+1),
154  _posTable(net.numberOfPlaces()+1),
155  _table(1) {}
156 
160  virtual ~ZslFactory();
161 
171  const Zsl * getZsl(Place place, int value, const Zsl * zsl);
178  const Zsl * getZsl(unsigned id) { if(id >= _table.size()) { return 0; } return _table[id]; }
179 
185  string printZsl(const Zsl * zsl) const
186  {
187  stringstream str;
188  str << owner()->labelOfPlace(zsl->place()) << "," << zsl->value() << " -> ";
189  if(zsl->next() == 0)
190  {
191  str << "NULL";
192  }
193  else
194  {
195  str << printZsl(zsl->next());
196  }
197  return str.str();
198  }
199 
200 
205  const Net * owner() const { return _net; }
206 
216  const Zsl * addZsl(const Zsl * zsl, Place p, int value);
217 
218 
223  void printDot(const string & fileName) const;
224 
225  void printTable();
226 };
227 
228 
229 
230 
231 };
232 };
233 
234 #endif /* ZSL_HH_ */
bool valid() const
Definition: Zsl.hh:115
const Zsl * next() const
Definition: Zsl.hh:109
Diades::Graph::Node Place
Definition: BoundedNet.hh:24
Zsl(Place p, int value, const Zsl *zsl, unsigned id)
Definition: Zsl.hh:71
Transition & next(const Net &netSystem, Net &completePrefix)
Definition: Unfolding.hh:24
ZslInvalid(const string &whatArg)
Definition: Zsl.hh:32
int value() const
Definition: Zsl.hh:97
const Zsl * getZsl(unsigned id)
Definition: Zsl.hh:178
string printZsl(const Zsl *zsl) const
Definition: Zsl.hh:185
const Net * owner() const
Definition: Zsl.hh:205
ZslFactory(const Net &net)
Definition: Zsl.hh:151
vector< Zsl * > _table
Definition: Zsl.hh:144
#define require(Exception, expr, message)
Definition: Assertion.hh:90
Namespace of the Diades project.
unsigned _id
Definition: Zsl.hh:52
void printDot(ostream &os, const T &value)
Definition: NodeMap.hh:433
unsigned id() const
Definition: Zsl.hh:91
std::ostream & operator<<(std::ostream &os, const Identifier &identifier)
Definition: Identifier.hh:501
virtual ~Zsl()
Definition: Zsl.hh:85
1-bounded Petri nets
Definition: Net.hh:62
const Zsl * _next
Definition: Zsl.hh:54
Place _place
Definition: Zsl.hh:53
vector< vector< unordered_map< unsigned, Zsl * > > > _negTable
Definition: Zsl.hh:142
Place place() const
Definition: Zsl.hh:103
const Net * _net
Definition: Zsl.hh:141
vector< vector< unordered_map< unsigned, Zsl * > > > _posTable
Definition: Zsl.hh:143