tp_2_constraints.cpp
Go to the documentation of this file.
1/** @file tp_2_constraints.cpp
2
3Tutorial, class faudes::TimeConstraint. This tutorial demonstrates
4basic usage of faudes::TimeConstraint objects
5
6@ingroup Tutorials
7
8@include tp_2_constraints.cpp
9
10*/
11
12
13#include "libfaudes.h"
14
15
16// make the faudes namespace available to our program
17using namespace faudes;
18
19/*
20
21General Description of the TimeConstraints Class.
22
23TimeConstraints provides a container of ElemConstraints, the latter modeling Alur's
24elementary clock contraints. Each ElemConstraint is a simple inequality that restricts
25a clock e.g. "clock7 less than 120". In this library, clocks are required to have
26symbolic names that are resolved via a SymbolTable reference that is member of TimeConstraints.
27By default, the reference is set to a global SymbolTable. This is the same behaviour
28as with events.
29
30
31*/
32
33
34
35/////////////////
36// main program
37/////////////////
38
39int main() {
40
41 ////////////////////////////////////////////////////
42 // constraints file io and inspection
43 ////////////////////////////////////////////////////
44
45 // Create a timeconstraint from file
46 TimeConstraint tc1("data/timeconstraint.txt");
47
48 // Create an empty timeconstraint
50
51 // Inspect on console
52 std::cout << "######################################\n";
53 std::cout << "# a timeconstraint \n";
54 tc1.DWrite();
55 std::cout << "######################################\n";
56
57 // Write the constraint to a file
58 tc1.Write("tmp_timeconstraint.txt");
59
60
61 // Get set of active clocks
62 ClockSet clocks1=tc1.ActiveClocks();
63
64 // Iterate over all clocks, inspect and convert to time interval
65 std::cout << "######################################\n";
66 std::cout << "# inspection ... \n";
67 ClockSet::Iterator cit;
68 for(cit = clocks1.Begin(); cit != clocks1.End(); cit++) {
69 std::cout << "clock: " << clocks1.SymbolicName(*cit) << "\n";
71 for(tit = tc1.Begin(*cit); tit != tc1.End(*cit); tit++) {
72 std::cout << "elem constraint: " << tc1.EStr(*tit) << "\n";
73 }
74 TimeInterval tint=tc1.Interval(*cit);
75 std::cout << "time interval: " << tint.Str() << "\n";
76 }
77 std::cout << "######################################\n";
78
79
80 ////////////////////////////////////////////////////
81 // edit constraint
82 ////////////////////////////////////////////////////
83
84 // Some interaction
85 tc1.Insert("clockC", ElemConstraint::LessThan, 125);
86 tc1.Insert("clockC", ElemConstraint::GreaterThan, 10);
87 tc1.Insert("clockC", ElemConstraint::GreaterEqual, 10); // redundent, but still added
88 tc1.Insert("clockB", ElemConstraint::GreaterThan, 110);
89 tc1.Insert("clockB", ElemConstraint::GreaterThan, 110); // double, not added to set
90 tc1.Insert("clockB", ElemConstraint::LessEqual, 200);
91 tc1.Insert("clockB", ElemConstraint::LessEqual, 210); // redundent, but still added
92 tc1.Insert("clockB", ElemConstraint::LessThan, 220); // redundent, but still added
93
94 // Report
95 std::cout << "######################################\n";
96 std::cout << "# after various insertions \n";
97 tc1.DWrite();
98 std::cout << "######################################\n";
99
100 // Erase an elementary constraint
101 tc1.Erase("clockB", ElemConstraint::LessEqual, 200);
102
103 // Report
104 std::cout << "######################################\n";
105 std::cout << "# after erase \n";
106 tc1.DWrite();
107 std::cout << "######################################\n";
108
109 // Introduce constraints to represent a valid interval
110 TimeInterval tint; // to become "(150,300]"
111 tint.LB(150);
112 tint.UB(300);
113 tint.UBincl(true);
114 tc2.Interval("clockB",tint);
115 tc2.Interval("clockD",tint);
116
117 // Report
118 std::cout << "######################################\n";
119 std::cout << "# another constraint \n";
120 tc2.DWrite();
121 std::cout << "######################################\n";
122
123
124 // Merge two time constraints (aka intersection)
125 tc1.Insert(tc2);
126
127 // Remove redundant elem. constraints
128 tc1.Minimize();
129
130 // Report
131 std::cout << "######################################\n";
132 std::cout << "# minimal version \n";
133 tc1.DWrite();
134 std::cout << "######################################\n";
135
136 // Test protocol
137 FAUDES_TEST_DUMP("final constraint",tc1.ToString());
138
139
140 return 0;
141}
142
143
144
#define FAUDES_TEST_DUMP(mes, dat)
Definition cfl_utils.h:505
void SymbolicName(Idx index, const std::string &rName)
std::set< ElemConstraint >::const_iterator Iterator
Iterator Erase(Iterator it)
std::string ToString(void) const
Iterator End(void) const
std::string EStr(const ElemConstraint &rElemConstr) const
TimeInterval Interval(Idx clockindex) const
Iterator Begin(void) const
Iterator Insert(const ElemConstraint &rElemConstr)
ClockSet ActiveClocks(void) const
void LB(Time::Type time)
std::string Str(void) const
void UBincl(bool incl)
void UB(Time::Type time)
Iterator End(void) const
Iterator Begin(void) const
int main()

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