DiaDes  0.1
DIAgnosis of Discrete-Event System
LabelledNet.hh
Go to the documentation of this file.
1 #ifndef __DIADES_PETRI_LABELLEDNET__HH__
2 #define __DIADES_PETRI_LABELLEDNET__HH__
3 
4 #include<unordered_set>
8 
9 
10 namespace Diades {
11  namespace Petri {
12  using Diades::Utils::Msg;
13 
20  class LabelledNet : public BoundedNet {
21  public:
22 
28  static string
30  return "Diades::Petri::LabelledNet";
31  }
32 
38 
40 
41 
47  typedef set<Event>::const_iterator EventIterator;
48 
53  typedef unordered_set<Transition>::const_iterator TransitionEventIterator;
54 
55  private:
56  unordered_map<Event, unordered_set<Transition> > _eventTransitions;
57  set<Event> _eventList;
59  Event _lambda;
60 
61 
62  public:
63 
69  Event
70  lambda() const {
71  return _lambda;
72  }
73 
78  typedef unordered_set<Transition>::const_iterator EventTransitionIterator;
79 
84  _eventTransitions(),
85  _eventList(),
86  _event(),
87  _lambda(PetriEventManager::petriEventManager().temporalEvent()) {
88  _event.init(graph());
89  }
90 
91 
96  LabelledNet(const LabelledNet & net);
97 
98 
99 
104  LabelledNet & operator=(const LabelledNet & net);
105 
106 
116  LabelledNet & append(const LabelledNet & net);
117 
118 
119 
120 
128  LabelledNet(const LabelledNet & lpn1, const LabelledNet & lpn2, const unordered_set<Event> & syncEvents);
129 
143  LabelledNet & merge(const LabelledNet & lpn1, const LabelledNet & lpn2,
144  const unordered_set<Event> & syncEvents,
145  std::unordered_map< Transition, std::list<Transition> > & lpn1SyncTrans,
146  std::unordered_map< Transition, std::list<Transition> > & lpn2SyncTrans,
147  unordered_map<Transition, std::pair<Transition, Transition>> &synchronisations,
148  std::unordered_map< Place, Place > & lpn1Place,
149  std::unordered_map< Place, Place > & lpn2Place,
150  std::unordered_map< Place, std::pair<Place, Place> > & syncPlaces);
151 
157  //EventTransitionIterator
158  //transitionBegin(Event e) const {
159  // return _eventTransitions.find(e)->second.begin();
160  //}
161 
167  //EventTransitionIterator
168  //ransitionEnd(Event e) const {
169  // return _eventTransitions.find(e)->second.end();
170  //}
171 
177  virtual void
178  nameOfTransition2Dot(ostream & os, Transition transition) const {
179  os << " " << nameOfTransition(transition)
180  << ":"
182  }
183 
184  public:
185 
194  virtual Transition newTransition(const set<Place> & pre,
195  const set<Place> & post,
196  const string & name,
197  Event e);
198 
203 
208  EventIterator
209  beginOfEvents() const {
210  return _eventList.begin();
211  }
212 
217  EventIterator
218  endOfEvents() const {
219  return _eventList.end();
220  }
221 
227  Event
228  getEvent(Transition t) const {
229 
230  require(Exception, t.valid(), "getEvent: invalid transition");
231  require(Exception, &t.owner() == &_graph, "getEvent: the transition does not belong to the Petri Net");
232  require(Exception, _nodeType[t] == T, "getEvent; this is not a transition but a place");
233  return _event[t];
234  }
235 
241  bool
242  containsEvent(Event event) const {
243  return _eventTransitions.find(event) != _eventTransitions.end();
244  }
245 
247 
253  TransitionEventIterator
254  beginOfTransitionWithEvent(Event event) const {
255  require(Exception, containsEvent(event),
256  Msg("beginOfTransitionWithEvent: the event %1% (i.e. %2%) is not associated to a transition of this Petri Net")
258  return _eventTransitions.at(event).begin();
259  }
260 
266  TransitionEventIterator
267  endOfTransitionWithEvent(Event event) const {
268  require(Exception, containsEvent(event),
269  Msg("endOfTransitionWithEvent: the event %1% (i.e. %2%) is not associated to a transition of this Petri Net")
271  return _eventTransitions.at(event).end();
272  }
273 
274 
283 
288  virtual void deleteTransition(Transition t);
289 
295  virtual void
296  net2TinaTransitionName(ostream & os, Transition trans) const {
297  os << " : " << PetriEventManager::petriEventManager().getEvent(getEvent(trans)) << " ";
298  }
299 
300 
310  virtual void copyLabelledNet(const LabelledNet & net,
315 
327  virtual void appendLabelledNet(const LabelledNet & net,
332 
333 
350  virtual void mergeLabelledNet(const LabelledNet & lpn1, const LabelledNet & lpn2,
351  const unordered_set<Event> & syncEvents,
356  std::unordered_map< Transition, std::list<Transition> > & lpn1SyncTrans,
357  std::unordered_map< Transition, std::list<Transition> > & lpn2SyncTrans,
358  std::unordered_map< Transition, std::pair<Transition, Transition> > & syncTransitions,
359  std::unordered_map< Place, Place > & lppn1Place,
360  std::unordered_map< Place, Place > & lppn2Place,
361  std::unordered_map< Place, std::pair<Place, Place> > & syncPlaces);
362 
363 
364 
365 
366 
367 
368 
369  };
370  };
371 };
372 
373 #endif
unordered_set< Transition >::const_iterator TransitionEventIterator
Definition: LabelledNet.hh:53
unordered_set< Transition >::const_iterator EventTransitionIterator
Definition: LabelledNet.hh:78
virtual Transition newTransition(const set< Place > &pre, const set< Place > &post, const string &name, Event e)
EventIterator endOfEvents() const
Definition: LabelledNet.hh:218
n-bounded Petri nets
Definition: BoundedNet.hh:50
Diades::Graph::Node Transition
Definition: BoundedNet.hh:31
virtual void copyLabelledNet(const LabelledNet &net, Diades::Graph::ConstNodeMap< Diades::Graph::Node > &nodeMap, Diades::Graph::NodeMap< Diades::Graph::Node > &nodeMapCopy, Diades::Graph::ConstEdgeMap< Diades::Graph::Edge > &edgeMap, Diades::Graph::EdgeMap< Diades::Graph::Edge > &edgeMapCopy)
PetriEventManager::EventId Event
Definition: LabelledNet.hh:39
static string typeName()
Definition: LabelledNet.hh:29
LabelledNet & merge(const LabelledNet &lpn1, const LabelledNet &lpn2, const unordered_set< Event > &syncEvents, std::unordered_map< Transition, std::list< Transition > > &lpn1SyncTrans, std::unordered_map< Transition, std::list< Transition > > &lpn2SyncTrans, unordered_map< Transition, std::pair< Transition, Transition >> &synchronisations, std::unordered_map< Place, Place > &lpn1Place, std::unordered_map< Place, Place > &lpn2Place, std::unordered_map< Place, std::pair< Place, Place > > &syncPlaces)
Diades::Graph::Node Place
Definition: BoundedNet.hh:24
Transition duplicateTransition(Transition t)
set< Event >::const_iterator EventIterator
Definition: LabelledNet.hh:47
bool containsEvent(Event event) const
Definition: LabelledNet.hh:242
unordered_map< Event, unordered_set< Transition > > _eventTransitions
Definition: LabelledNet.hh:56
TransitionEventIterator beginOfTransitionWithEvent(Event event) const
Definition: LabelledNet.hh:254
const Diades::Graph::Graph & graph() const
Definition: BoundedNet.hh:420
LabelledNet & operator=(const LabelledNet &net)
virtual void deleteTransition(Transition t)
Diades::Graph::NodeMap< NodeType > _nodeType
Definition: BoundedNet.hh:293
#define require(Exception, expr, message)
Definition: Assertion.hh:90
const Event & getEvent(EventId id) const
Definition: Event.hh:183
Namespace of the Diades project.
Diades::Graph::ConstNodeMap< Event > _event
Definition: LabelledNet.hh:58
LabelledNet & append(const LabelledNet &net)
Diades::Utils::Exception< LabelledNet > Exception
Definition: LabelledNet.hh:37
Event getEvent(Transition t) const
Definition: LabelledNet.hh:228
virtual void mergeLabelledNet(const LabelledNet &lpn1, const LabelledNet &lpn2, const unordered_set< Event > &syncEvents, Diades::Graph::ConstNodeMap< Diades::Graph::Node > &nodeMapLpn1, Diades::Graph::NodeMap< Diades::Graph::Node > &nodeMapFromLpn1, Diades::Graph::ConstNodeMap< Diades::Graph::Node > &nodeMapLpn2, Diades::Graph::NodeMap< Diades::Graph::Node > &nodeMapFromLpn2, std::unordered_map< Transition, std::list< Transition > > &lpn1SyncTrans, std::unordered_map< Transition, std::list< Transition > > &lpn2SyncTrans, std::unordered_map< Transition, std::pair< Transition, Transition > > &syncTransitions, std::unordered_map< Place, Place > &lppn1Place, std::unordered_map< Place, Place > &lppn2Place, std::unordered_map< Place, std::pair< Place, Place > > &syncPlaces)
virtual void nameOfTransition2Dot(ostream &os, Transition transition) const
Definition: LabelledNet.hh:178
virtual void appendLabelledNet(const LabelledNet &net, Diades::Graph::ConstNodeMap< Diades::Graph::Node > &nodeMap, Diades::Graph::NodeMap< Diades::Graph::Node > &nodeMapCopy, Diades::Graph::ConstEdgeMap< Diades::Graph::Edge > &edgeMap, Diades::Graph::EdgeMap< Diades::Graph::Edge > &edgeMapCopy)
Diades::Graph::Graph _graph
Definition: BoundedNet.hh:292
boost::format Msg
Definition: Verbose.hh:42
const string & name() const
Definition: BoundedNet.hh:388
void init(const Graph &g, SizeType capacity=0, ValueType dflt=ValueType())
static PetriEventManager & petriEventManager()
EventIterator beginOfEvents() const
Definition: LabelledNet.hh:209
const string & nameOfTransition(Transition transition) const
Definition: BoundedNet.hh:902
virtual void net2TinaTransitionName(ostream &os, Transition trans) const
Definition: LabelledNet.hh:296
TransitionEventIterator endOfTransitionWithEvent(Event event) const
Definition: LabelledNet.hh:267