DiaDes  0.1
DIAgnosis of Discrete-Event System
ReachabilityGraph.hh
Go to the documentation of this file.
1 #ifndef __DIADES__PETRI__REACHABILITYGRAPH__HH
2 #define __DIADES__PETRI__REACHABILITYGRAPH__HH
3 
4 #include <string>
5 #include <set>
6 #include <unordered_map>
9 #include <diades/graph/Graph.hh>
10 #include <diades/graph/NodeMap.hh>
11 #include <diades/graph/EdgeMap.hh>
12 
13 using namespace std;
14 
15 namespace Diades
16 {
17  namespace Petri
18  {
25  {
26  public:
27  static string typeName() { return "Diades::Petri::ReachabilityGraph"; }
29 
30  public:
41  typedef unordered_map<unsigned,RState> StateDictionnary;
42 
43  private:
44  RGraph _graph;
45  RState _initial;
46  Marking _marking;
47  TransitionLabel _transLabel;
48  Ids _id;
49  StateDictionnary _dictionary;
50 
51  public:
52  ReachabilityGraph():_graph(),_initial(),_marking(),_transLabel(),_id(),_dictionary()
53  {
54  _marking.init(_graph);
55  _transLabel.init(_graph);
56  _id.init(_graph);
57  }
59  {
60  }
61 
66  const set<string> & getMarking(RState state)
67  {
68  require(Exception,state.valid() && &state.owner()==&_graph,"getMarking: invalid state");
69  return _marking[state];
70  }
71 
76  void addMarking(RState state, const string & mark)
77  {
78  require(Exception,state.valid() && &state.owner()==&_graph,"addMarking: invalid state");
79  require(Exception,!mark.empty(),"addMarking: empty label");
80  _marking[state].insert(mark);
81  }
82 
87  const string & getLabel(RTransition transition)
88  {
89  require(Exception,transition.valid() && &transition.owner()==&_graph,"getLabel: invalid transition");
90  return _transLabel[transition];
91  }
92 
93 
94 
95 
101  unsigned numberOfStates() const
102  {
103  return _graph.numberOfNodes();
104  }
105 
111  unsigned numberOfTransitions() const
112  {
113  return _graph.numberOfEdges();
114  }
115 
121  bool empty() const
122  {
123  return _graph.empty();
124  }
125 
126 
132  RState target(const RTransition & trans) const
133  {
134  return _graph.target(trans);
135  }
136 
137 
143  RState source(const RTransition & trans) const
144  {
145  return _graph.source(trans);
146  }
147 
151 
157  RStateIterator stateBegin() {
158  return _graph.nodeBegin();
159  }
160 
166  RStateIterator stateEnd() {
167  return _graph.nodeEnd();
168  }
169 
175  RStateIterator stateBegin() const {
176  return _graph.nodeBegin();
177  }
178 
184  RStateIterator stateEnd() const {
185  return _graph.nodeEnd();
186  }
187 
193  RTransitionIterator transBegin()
194  {
195  return _graph.edgeBegin();
196  }
197 
203  RTransitionIterator transEnd()
204  {
205  return _graph.edgeEnd();
206  }
207 
213  RTransitionIterator transBegin() const
214  {
215  return _graph.edgeBegin();
216  }
217 
223  RTransitionIterator transEnd() const
224  {
225  return _graph.edgeEnd();
226  }
227 
228 
229 
230  virtual void addTimeConstraint(RState state, const string & transitionName, const Diades::Utils::Interval & interval)
231  {
233  }
234 
239  {
240  return _graph;
241  }
242 
246  const Graph::Graph & graph() const
247  {
248  return _graph;
249  }
250 
256  OutRTransitionIterator outTransBegin(const RState & state) const
257  {
258  return _graph.outEdgeBegin(state);
259  }
260 
266  OutRTransitionIterator outTransEnd(const RState & state) const
267  {
268  return _graph.outEdgeEnd(state);
269  }
270 
271 
277  InRTransitionIterator outTransBegin(const RState & state)
278  {
279  return _graph.inEdgeBegin(state);
280  }
281 
287  InRTransitionIterator outTransEnd(const RState & state)
288  {
289  return _graph.inEdgeEnd(state);
290  }
291 
292 
296  void clear()
297  {
298  _graph.clear();
299  }
300 
301 
307  RState getState(unsigned id);
308 
309 
317  RTransition getTrans(RState source,RState target, const string & label);
318 
319 
325  unsigned getId(RState state) const
326  {
327  require(Exception, state.valid() && &state.owner() == &graph(),"getId: invalid state");
328  return _id[state];
329  }
330 
331 
337  void setInitial(RState state)
338  {
339  require(Exception, state.valid() && &state.owner() == &graph(),"setInitial: invalid state");
340  _initial = state;
341  }
342 
343  RState initialState() const
344  {
345  return _initial;
346  }
347 
348 
357  bool importTinaGraph(const string & fileAut, const string & fileVrb);
358 
359 
360 
365  virtual bool exportGraphToDot(const string & fileDot);
366 
367 
368  protected:
374  bool importTinaAut(const string & fileAut);
380  virtual bool importTinaVrb(const string & fileVrb);
381 
382 
383  };
384 
385 
386 
387 
388  };
389 };
390 
391 #endif
void addMarking(RState state, const string &mark)
Diades::Graph::InEdgeIterator InRTransitionIterator
InRTransitionIterator outTransBegin(const RState &state)
Diades::Utils::Exception< ReachabilityGraph > Exception
GraphIterator< Edge > EdgeIterator
Definition: GraphInt.hh:143
RState source(const RTransition &trans) const
const string & getLabel(RTransition transition)
InRTransitionIterator outTransEnd(const RState &state)
STL namespace.
RState _initial
the underlying graph
unsigned getId(RState state) const
Ids _id
the label associated to each RTransition of the
Diades::Graph::NodeMap< set< string > > Marking
Diades::Graph::NodeIterator RStateIterator
GraphIterator< Node > NodeIterator
Definition: GraphInt.hh:139
const set< string > & getMarking(RState state)
#define require(Exception, expr, message)
Definition: Assertion.hh:90
Namespace of the Diades project.
Diades::Graph::EdgeMap< string > TransitionLabel
RTransitionIterator transEnd() const
StateDictionnary _dictionary
the ids associated to the states
TransitionLabel _transLabel
the marking associated to each RState of the graph
list< Edge >::iterator OutEdgeIterator
Definition: Edge.hh:314
RTransitionIterator transBegin() const
boost::adjacency_list Graph
Definition: ScaleFree.cc:9
const Graph::Graph & graph() const
Diades::Graph::EdgeIterator RTransitionIterator
OutRTransitionIterator outTransBegin(const RState &state) const
list< Edge >::iterator InEdgeIterator
Definition: Edge.hh:313
virtual void addTimeConstraint(RState state, const string &transitionName, const Diades::Utils::Interval &interval)
RState target(const RTransition &trans) const
unordered_map< unsigned, RState > StateDictionnary
Diades::Graph::NodeMap< unsigned > Ids
OutRTransitionIterator outTransEnd(const RState &state) const
Marking _marking
the initial state
Diades::Graph::OutEdgeIterator OutRTransitionIterator