DiaDes  0.1
DIAgnosis of Discrete-Event System
Trace.hh
Go to the documentation of this file.
1 #ifndef __DIADES__AUTOMATA__TRACE_HH
2 #define __DIADES__AUTOMATA__TRACE_HH
3 
8 
9 namespace Diades {
10 
11  namespace Automata {
12 
19  class Trace : public Component {
20  private:
21  unordered_set<State> _acceptors;
23 
24  public:
25 
26  static string typeName() {
27  return "Automata::Trace";
28  }
30 
31 
32 
33  /*************** CONSTRUCTORS **********************************/
34 
39  Trace();
40 
41  /************** TRACE OPERATORS *******************************/
42 
43  private:
44 
45  void pruneSpuriousStates();
46 
47  void extractUnobservableBehaviours(const Component & comp,
48  const ObservableMask & mask,
49  const unordered_map<State, State> & sources,
50  unordered_map<State, State> & targets,
51  unsigned level);
52 
53  bool extractBehaviours(const Component & comp,
54  const ObservableMask & mask,
55  const unordered_map<State, State> & sources,
56  const Event & obs,
57  unordered_map<State, State> & targets,
58  unsigned level);
59 
60  public:
61 
74  bool extract(const Component & comp, const ObservableMask & mask,
75  const vector<Event> & observations);
76 
77 
78 
79 
94  void extract(const Component & comp, Event event, bool presence);
95 
108  void extract(const Trace & trace, const Trace & projection, const set<Event> & projectedEvents);
109 
110 
111 
129  void extractObservableTrace(const ObservableComponent & comp, Event event, bool presence);
130 
131 
142 
143 
144 
145 
146 
147 
148 
149 
159  bool project(const Trace & trace,
160  const set<Event> & projectedEvents);
161 
162 
163 
172  bool intersection(const Trace & trace1, const Trace & trace2);
173 
174 
184  bool substract(const Trace & trace1, const Trace & trace2);
185 
197  bool complement(const Trace & trace, const set<Event> & events);
198 
199 
209  bool compose(const Trace & trace1, const Trace & trace2, const set<Event> & events);
210 
211 
220 
221 
222  private:
223 
237  void computeTrace(const Component & comp, Event event, bool presence);
238 
239 
240  public:
241 
242  /*************** MISC *******************************************/
243 
250  bool isFinite(list< set<Event> > & combinations) const;
251 
252 
253 
254 
258  bool isContinuationFinite() const;
259 
263  State initialState() const {
264  try {
265  return *initialStateBegin();
266  } catch (exception & e) {
267  throw Exception("initialState(): unable to get access to the initial state", e);
268  }
269  return State();
270  }
271 
272 
273  /**************** ACCEPTORS MANAGEMENT **************************/
274 
282  bool isAcceptor(State state) const {
283  try {
284  require(Exception, state.valid(), "isAcceptor(), invalid state");
285  require(Exception, &state.owner() == &behaviour(), "isAcceptor(), the state does not belong to this trace");
286  return (state.valid()
287  && (&state.owner() == &behaviour())
288  && (_status[state] == 1));
289  } catch (exception & e) {
290  throw Exception("isAcceptor(): unable to get the accepting status of the state", e);
291  }
292  }
293 
299  void setAcceptor(State state) {
300  try {
301  require(Exception, state.valid(), "setAcceptor(), invalid state");
302  require(Exception, &state.owner() == &behaviour(), "setAcceptor(), the state does not belong to this trace");
303  if (state.valid() && (&state.owner() == &behaviour())) {
304  if (_status[state] == 0) {
305  _status[state] = 1;
306  _acceptors.insert(state);
307  }
308  }
309  } catch (exception & e) {
310  throw Exception("setAcceptor(): unable to get the accepting status of the state", e);
311  }
312  }
313 
319  void setNonAcceptor(State state) {
320  try {
321  require(Exception, state.valid(), "setNonAcceptor(), invalid state");
322  require(Exception, &state.owner() == &behaviour(), "setNonAcceptor(), the state does not belong to this trace");
323  if (state.valid() && (&state.owner() == &behaviour())) {
324  if (_status[state] == 1) {
325  _status[state] = 0;
326  _acceptors.erase(state);
327  }
328  }
329  } catch (exception & e) {
330  throw Exception("setNonAcceptor(): unable to get the accepting status of the state", e);
331  }
332  }
333 
340  unordered_set<State>::const_iterator beginOfAcceptorStates() const {
341  try {
342  return _acceptors.begin();
343  } catch (exception & e) {
344  throw Exception("beginOfAcceptorStates(): unable to get the iterator", e);
345  }
346  return _acceptors.begin();
347  }
348 
355  unordered_set<State>::const_iterator endOfAcceptorStates() const {
356  try {
357  return _acceptors.end();
358  } catch (exception & e) {
359  throw Exception("endOfAcceptorStates(): unable to get the iterator", e);
360  }
361  return _acceptors.end();
362  }
363 
369  try {
370  for (StateIterator stateIt = stateBegin();
371  stateIt != stateEnd();
372  ++stateIt) {
373  setAcceptor(*stateIt);
374  }
375  } catch (exception & e) {
376  throw Exception("makeAllAcceptors(): unable to set the states as acceptor states", e);
377  }
378  }
379 
385  try {
386  for (StateIterator stateIt = stateBegin();
387  stateIt != stateEnd();
388  ++stateIt) {
389  setNonAcceptor(*stateIt);
390  }
391  } catch (exception & e) {
392  throw Exception("makeAllNonAcceptors(): unable to set the states as non-acceptor states", e);
393  }
394  }
395 
402  const unordered_set<State> & acceptors() const {
403  return _acceptors;
404  }
405 
414  virtual void mergeInfoStates(const vector<const Component *> & components, const vector<State> & states, State currentState);
415 
416  /**************************** GENERAL METHODS ******************/
417 
422  void clear() {
424  _acceptors.clear();
425  _status.init(behaviour());
426  }
427 
428  public:
433  void trace2dot(const string & filename) const;
434 
435 
436 
437  };
438 
439 
440 
441 
442 
443 
444  };
445 
446 };
447 
448 #endif
Graph::Graph & behaviour()
Definition: Component.hh:215
bool substract(const Trace &trace1, const Trace &trace2)
bool isContinuationFinite() const
bool complement(const Trace &trace, const set< Event > &events)
void setAcceptor(State state)
Definition: Trace.hh:299
bool isAcceptor(State state) const
Definition: Trace.hh:282
bool isFinite(list< set< Event > > &combinations) const
bool intersection(const Trace &trace1, const Trace &trace2)
bool extractBehaviours(const Component &comp, const ObservableMask &mask, const unordered_map< State, State > &sources, const Event &obs, unordered_map< State, State > &targets, unsigned level)
void extractObservableTrace(const ObservableComponent &comp, Event event, bool presence)
StateIterator stateBegin() const
Definition: Component.hh:572
void init(Graph &g, SizeType capacity=0, ValueType dflt=ValueType())
Definition: NodeMap.hh:315
StateIterator stateEnd() const
Definition: Component.hh:579
void extractUnobservableBehaviours(const Component &comp, const ObservableMask &mask, const unordered_map< State, State > &sources, unordered_map< State, State > &targets, unsigned level)
StIndexes states
Definition: Run.cc:266
An observable Component defined as a automaton.
Diades::Graph::NodeIterator StateIterator
Definition: Component.hh:67
void trace2dot(const string &filename) const
Diades::Utils::Exception< Trace > Exception
Definition: Trace.hh:29
virtual void mergeInfoStates(const vector< const Component *> &components, const vector< State > &states, State currentState)
void computeTrace(const Component &comp, Event event, bool presence)
InitialStateIterator initialStateBegin() const
Definition: Component.hh:638
Diades::Graph::NodeMap< int > _status
set of acceptor states
Definition: Trace.hh:22
const unordered_set< State > & acceptors() const
Definition: Trace.hh:402
static string typeName()
_status = 1 acceptor, non-acceptor otherwise
Definition: Trace.hh:26
#define require(Exception, expr, message)
Definition: Assertion.hh:90
Namespace of the Diades project.
void makeAllNonAcceptors()
Definition: Trace.hh:384
void setNonAcceptor(State state)
Definition: Trace.hh:319
unordered_set< State >::const_iterator beginOfAcceptorStates() const
Definition: Trace.hh:340
void extractAllObservableTraces(const ObservableComponent &comp)
unordered_set< State >::const_iterator endOfAcceptorStates() const
Definition: Trace.hh:355
Diades::Graph::Node State
Definition: BeliefState.hh:36
bool compose(const Trace &trace1, const Trace &trace2, const set< Event > &events)
const set< Event > & events() const
Definition: Component.hh:318
State initialState() const
Definition: Trace.hh:263
unordered_set< State > _acceptors
Definition: Trace.hh:21
bool project(const Trace &trace, const set< Event > &projectedEvents)
bool extract(const Component &comp, const ObservableMask &mask, const vector< Event > &observations)