DiaDes  0.1
DIAgnosis of Discrete-Event System
PriorityPetriNet.hh
Go to the documentation of this file.
1 #ifndef __DIADES__PETRI__PRIORITYPETRINET_HH_
2 #define __DIADES__PETRI__PRIORITYPETRINET_HH_
3 
4 #include<unordered_map>
5 #include<list>
6 
7 using namespace std;
8 
9 
10 namespace Diades
11 {
12  namespace Petri
13  {
14 
15  class PriorityPetriNet : virtual public Petri::Net
16  {
17  private:
18  std::unordered_multimap<Transition,Transition> _priorities;
19 
20  public:
21  typedef std::unordered_multimap<Transition,Transition> Priorities;
22  typedef pair<Priorities::const_iterator,Priorities::const_iterator> Range;
23 
24  PriorityPetriNet():Net(),_priorities(){}
25 
26  virtual ~PriorityPetriNet(){}
27 
29  {
30  removePriority(t1,t2);
31  _priorities.insert(make_pair(t1,t2));
32  }
33 
35  {
36  Range range = priorities(t1);
37  bool removed = false;
38  while(!removed && (range.first != range.second))
39  {
40  removed = ((range.first->second) == t2);
41  if(removed)
42  {
43  _priorities.erase(range.first);
44  }
45  else
46  {
47  ++(range.first);
48  }
49  }
50  }
51 
52  Range priorities() const
53  {
54  return make_pair(_priorities.begin(),_priorities.end());
55  }
56 
57 
58  Range priorities(Transition t) const
59  {
60  return _priorities.equal_range(t);
61  }
62 
63  bool hasPriority(Transition t1, Transition t2) const
64  {
65  Range range = priorities(t1);
66  bool found = false;
67  while(!found && (range.first != range.second))
68  {
69  found = ((range.first->second) == t2);
70  ++(range.first);
71  }
72  return found;
73  }
74 
75 
76  virtual void priorities2Tina(ostream & os) const
77  {
78  //prdesc ::= ’pr’ (<transition>)+ ("<"|">") (<transition>)+
79  Range range = priorities();
80  while(range.first != range.second)
81  {
82  os << "pr ";
83  os << labelOfTransition(range.first->first)
84  << " < " << labelOfTransition(range.first->second)
85  << std::endl;
86  ++range.first;
87  }
88  }
89 
90  };
91 
92 
93  };
94 };
95 
96 #endif
void removePriority(Transition t1, Transition t2)
Diades::Graph::Node Transition
Definition: BoundedNet.hh:31
STL namespace.
std::unordered_multimap< Transition, Transition > Priorities
Namespace of the Diades project.
std::unordered_multimap< Transition, Transition > _priorities
1-bounded Petri nets
Definition: Net.hh:62
Range priorities(Transition t) const
bool hasPriority(Transition t1, Transition t2) const
virtual void priorities2Tina(ostream &os) const
pair< Priorities::const_iterator, Priorities::const_iterator > Range
void setPriority(Transition t1, Transition t2)