tp_2_constraints.cppGo to the documentation of this file.00001 /** @file tp_2_constraints.cpp 00002 00003 Tutorial, class faudes::TimeConstraint. This tutorial demonstrates 00004 basic usage of faudes::TimeConstraint objects 00005 00006 @ingroup Tutorials 00007 00008 @include tp_2_constraints.cpp 00009 00010 */ 00011 00012 00013 00014 #include "libfaudes.h" 00015 #include "tp_include.h" 00016 00017 00018 // make the faudes namespace available to our program 00019 using namespace faudes; 00020 00021 /* 00022 00023 General Description of the TimeConstraints Class. 00024 00025 TimeConstraints provides a container of ElemConstraints, the latter modeling Alur's 00026 elementary clock contraints. Each ElemConstraint is a simple inequality that restricts 00027 a clock e.g. "clock7 less than 120". In this library, clocks are required to have 00028 symbolic names that are resolved via a SymbolTable reference that is member of TimeConstraints. 00029 By default, the reference is set to a global SymbolTable. This is the same behaviour 00030 as with events. 00031 00032 00033 */ 00034 00035 00036 00037 ///////////////// 00038 // main program 00039 ///////////////// 00040 00041 int main() { 00042 00043 //////////////////////////////////////////////////// 00044 // constraints file io and inspection 00045 //////////////////////////////////////////////////// 00046 00047 // Create a timeconstraint from file 00048 TimeConstraint tc1("data/timeconstraint.txt"); 00049 00050 // Create an empty timeconstraint 00051 TimeConstraint tc2; 00052 00053 // Inspect on console 00054 std::cout << "######################################\n"; 00055 std::cout << "# a timeconstraint \n"; 00056 tc1.DWrite(); 00057 std::cout << "######################################\n"; 00058 00059 // Write the constraint to a file 00060 tc1.Write("tmp_timeconstraint.txt"); 00061 00062 00063 // Get set of active clocks 00064 ClockSet clocks1=tc1.ActiveClocks(); 00065 00066 // Iterate over all clocks, inspect and convert to time interval 00067 std::cout << "######################################\n"; 00068 std::cout << "# inspection ... \n"; 00069 ClockSet::Iterator cit; 00070 for(cit = clocks1.Begin(); cit != clocks1.End(); cit++) { 00071 std::cout << "clock: " << clocks1.SymbolicName(*cit) << "\n"; 00072 TimeConstraint::Iterator tit; 00073 for(tit = tc1.Begin(*cit); tit != tc1.End(*cit); tit++) { 00074 std::cout << "elem constraint: " << tc1.EStr(*tit) << "\n"; 00075 } 00076 TimeInterval tint=tc1.Interval(*cit); 00077 std::cout << "time interval: " << tint.Str() << "\n"; 00078 } 00079 std::cout << "######################################\n"; 00080 00081 00082 //////////////////////////////////////////////////// 00083 // edit constraint 00084 //////////////////////////////////////////////////// 00085 00086 // Some interaction 00087 tc1.Insert("clockC", ElemConstraint::LessThan, 125); 00088 tc1.Insert("clockC", ElemConstraint::GreaterThan, 10); 00089 tc1.Insert("clockC", ElemConstraint::GreaterEqual, 10); // redundent, but still added 00090 tc1.Insert("clockB", ElemConstraint::GreaterThan, 110); 00091 tc1.Insert("clockB", ElemConstraint::GreaterThan, 110); // double, not added to set 00092 tc1.Insert("clockB", ElemConstraint::LessEqual, 200); 00093 tc1.Insert("clockB", ElemConstraint::LessEqual, 210); // redundent, but still added 00094 tc1.Insert("clockB", ElemConstraint::LessThan, 220); // redundent, but still added 00095 00096 // Report 00097 std::cout << "######################################\n"; 00098 std::cout << "# after various insertions \n"; 00099 tc1.DWrite(); 00100 std::cout << "######################################\n"; 00101 00102 // Erase an elementary constraint 00103 tc1.Erase("clockB", ElemConstraint::LessEqual, 200); 00104 00105 // Report 00106 std::cout << "######################################\n"; 00107 std::cout << "# after erase \n"; 00108 tc1.DWrite(); 00109 std::cout << "######################################\n"; 00110 00111 // Introduce constraints to represent a valid interval 00112 TimeInterval tint; // to become "(150,300]" 00113 tint.LB(150); 00114 tint.UB(300); 00115 tint.UBincl(true); 00116 tc2.Interval("clockB",tint); 00117 tc2.Interval("clockD",tint); 00118 00119 // Report 00120 std::cout << "######################################\n"; 00121 std::cout << "# another constraint \n"; 00122 tc2.DWrite(); 00123 std::cout << "######################################\n"; 00124 00125 00126 // Merge two time constraints (aka intersection) 00127 tc1.Insert(tc2); 00128 00129 // Remove redundant elem. constraints 00130 tc1.Minimize(); 00131 00132 // Report 00133 std::cout << "######################################\n"; 00134 std::cout << "# minimal version \n"; 00135 tc1.DWrite(); 00136 std::cout << "######################################\n"; 00137 00138 // Test protocol 00139 FAUDES_TEST_DUMP("final constraint",tc1.ToString()); 00140 00141 00142 return 0; 00143 } 00144 00145 00146 libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |