pev_1_priorities.cpp
Go to the documentation of this file.
1/** @file pev_1_priorities.cpp
2
3Tutorial, events stes and generators with priorities
4
5@ingroup Tutorials
6
7@include pev_1_priorities.cpp
8
9*/
10
11#include "libfaudes.h"
12
13
14using namespace faudes;
15
16
17
18int main() {
19
20 ////////////////////////////////////////////////////
21 // TaEventSet with Attribute AttributePriority
22 ////////////////////////////////////////////////////
23
24 // set up some alphabet with prioritised events
25 TaEventSet<AttributePriority> prios1;
26 Idx alpha= prios1.Insert("alpha");
27 Idx beta= prios1.Insert("beta");
28 Idx gamma= prios1.Insert("gamma");
30 prio.Priority(10);
31 prios1.Attribute(alpha,prio);
32 prio.Priority(20);
33 prios1.Attribute(beta,prio);
34 prio.Priority(30);
35 prios1.Attribute(gamma,prio);
36 // report
37 std::cout << "alphabet of priorisied events (using vanilla attributed event set)" << std::endl;
38 prios1.XWrite();
39
40
41 ////////////////////////////////////////////////////
42 // Convenienceclass EventPriorities (fully registered faudes type)
43 ////////////////////////////////////////////////////
44
45 // set up some alphabet with prioritised events
46 EventPriorities prios2;
47 alpha= prios2.Insert("alpha");
48 beta= prios2.Insert("beta");
49 gamma= prios2.Insert("gamma");
50 prios2.Priority(alpha,0); // access by index
51 prios2.Priority("beta",10); // access by symbolic name (convenience, performance penalty)
52 prios2.Priority("gamma",20); // access by symbolic name (convenience, performance penalty)
53 // report
54 std::cout << "alphabet of priorisied events (using convenience class)" << std::endl;
55 prios2.Write();
56
57 // normalise to a consecutive range starting with 1
58 prios2.NormalisePriorities();
59 std::cout << "normalised priosities" << std::endl;
60 prios2.Write();
61
62 // stress test copy/casting/equality
63 EventSet events(prios2);
64 bool ok= events == prios2;
65 if(ok)
66 std::cout << "copy to plain alphabet: events match (PASS)" << std::endl;
67 else
68 std::cout << "copy to plain alphabet: events mismatch (FAIL)" << std::endl;
69 EventPriorities prios3(prios2);
70 ok= prios3 == prios2;
71 if(ok)
72 std::cout << "copy to prio alphabet: events match (PASS)" << std::endl;
73 else
74 std::cout << "copy to prio alphabet: events mismatch (FAIL)" << std::endl;
75 ok= prios2.EqualAttributes(prios3);
76 if(ok)
77 std::cout << "copy to prio alphabet: priorities match (PASS)" << std::endl;
78 else
79 std::cout << "copy to prio alphabet: priorities mismatch (FAIL)" << std::endl;
80 prios3.Priority("alpha",50);
81 prios3.Write();
82 ok=prios2.EqualAttributes(prios3);
83 if(ok)
84 std::cout << "manipulate priorities: still match (FAIL)" << std::endl;
85 else
86 std::cout << "manipulate priorities: mismatch (PASS)" << std::endl;
87
88
89 ////////////////////////////////////////////////////
90 // Fairness
91 ////////////////////////////////////////////////////
92
93 FairnessConstraints fconstr;
94 EventSet falph1, falph2;
95 falph1.FromString("<EventSet> alpha beta </EventSet>");
96 falph2.FromString("<EventSet> beta gamma </EventSet>");
97 fconstr.Append(falph1);
98 fconstr.Append(falph2);
99 fconstr.Write();
100 FairnessConstraints::Position pos=fconstr.Find(falph2);
101 if(pos==1)
102 std::cout << "found alph2 at " << pos << " (PASS)" << std::endl;
103 else
104 std::cout << "found alph2 at " << pos << " (FAIL)" << std::endl;
105
106
107
108 ////////////////////////////////////////////////////
109 // pGenerator
110 ////////////////////////////////////////////////////
111
112 pGenerator pgen;
113 pgen.FromString(R"(
114 <Generator>
115 <T>
116 1 alpha 2
117 2 beta 3
118 3 gamma 1
119 </T>
120 </Generator>
121 )");
122 pgen.Priorities(prios3);
123 pgen.Fairness(fconstr);
124 pgen.XWrite();
125
126
127}
std::vector< int >::size_type Position
Idx Priority(const std::string &rName) const
void NormalisePriorities(void)
FairnessConstraints Fairness(void) const
void Priorities(const TpEventSet< EventAttr > &rOtherSet)
void FromString(const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
virtual void XWrite(const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
void Write(const Type *pContext=0) const
virtual Position Find(const Type &rElem)
virtual void Append(const Type &rElem)
uint32_t Idx
int main()

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen