tp_2_constraints.cpp

Go to the documentation of this file.
00001 
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 
00026 TimeConstraints provides a container of ElemConstraints, the latter modeling Alur's
00027 elementary clock contraints. Each ElemConstraint is a simple inequality that restricts
00028 a clock e.g. "clock7 less than 120".  In this library, clocks are required to have 
00029 symbolic names that are resolved via a SymbolTable reference that is member of TimeConstraints. 
00030 By default, the reference is set to a global SymbolTable. This is the same behaviour
00031 as with events.
00032 
00033 
00034 */
00035 
00036 
00037 
00039 // main program
00041 
00042 int main() {
00043 
00044   /****************************
00045    * constraints file io and inspection
00046    *
00047    */
00048 
00049   // create a timeconstraint from file
00050 
00051   TimeConstraint tc1("data/timeconstraint.txt");
00052 
00053   // create an empty timeconstraint 
00054 
00055   TimeConstraint tc2;
00056 
00057   // inspect on console
00058 
00059   std::cout << "######################################\n";
00060   std::cout << "# a timeconstraint \n";
00061   tc1.DWrite();
00062   std::cout << "######################################\n";
00063 
00064   // write the constraint to a file 
00065 
00066   tc1.Write("tmp_timeconstraint.txt");
00067 
00068 
00069   // get set of active clocks
00070 
00071   ClockSet clocks1=tc1.ActiveClocks();
00072   
00073   // iterate over all clocks, inspect and convert to time interval
00074 
00075   std::cout << "######################################\n";
00076   std::cout << "# inspection ...  \n";
00077   ClockSet::Iterator cit;
00078   for(cit = clocks1.Begin(); cit != clocks1.End(); cit++) {
00079     std::cout << "clock: " << clocks1.SymbolicName(*cit) << "\n";
00080     TimeConstraint::Iterator tit;
00081     for(tit = tc1.Begin(*cit); tit != tc1.End(*cit); tit++) {
00082       std::cout << "elem constraint: " << tc1.EStr(*tit) << "\n";
00083     }
00084     TimeInterval tint=tc1.Interval(*cit);
00085     std::cout << "time interval: " << tint.Str() << "\n";
00086   }
00087   std::cout << "######################################\n";
00088   
00089 
00090   /****************************
00091    * edit constraint
00092    *
00093    */
00094 
00095   // some interaction 
00096 
00097   tc1.Insert("clockC", ElemConstraint::LessThan,    125);
00098   tc1.Insert("clockC", ElemConstraint::GreaterThan,  10);
00099   tc1.Insert("clockC", ElemConstraint::GreaterEqual, 10); // redundent, but still added
00100   tc1.Insert("clockB", ElemConstraint::GreaterThan, 110);
00101   tc1.Insert("clockB", ElemConstraint::GreaterThan, 110); // double, not added to set 
00102   tc1.Insert("clockB", ElemConstraint::LessEqual,   200); 
00103   tc1.Insert("clockB", ElemConstraint::LessEqual,   210); // redundent, but still added
00104   tc1.Insert("clockB", ElemConstraint::LessThan,    220); // redundent, but still added
00105 
00106   // report
00107 
00108   std::cout << "######################################\n";
00109   std::cout << "# after various insertions \n";
00110   tc1.DWrite();
00111   std::cout << "######################################\n";
00112 
00113   // erase an elementary constraint
00114 
00115   tc1.Erase("clockB", ElemConstraint::LessEqual,   200); 
00116 
00117   // report
00118 
00119   std::cout << "######################################\n";
00120   std::cout << "# after erase \n";
00121   tc1.DWrite();
00122   std::cout << "######################################\n";
00123 
00124   // introduce constraints to represent a valid interval
00125 
00126   TimeInterval tint; // to become "(150,300]"
00127   tint.LB(150);
00128   tint.UB(300);
00129   tint.UBincl(true);
00130   tc2.Interval("clockB",tint);
00131   tc2.Interval("clockD",tint);
00132   
00133   // report
00134 
00135   std::cout << "######################################\n";
00136   std::cout << "# another constraint \n";
00137   tc2.DWrite();
00138   std::cout << "######################################\n";
00139 
00140 
00141   // merge two time constraints (aka intersection)
00142 
00143   tc1.Insert(tc2);
00144 
00145   // remove redundant elem. constraints
00146 
00147   tc1.Minimize();
00148 
00149   // report
00150 
00151   std::cout << "######################################\n";
00152   std::cout << "# minimal version \n";
00153   tc1.DWrite();
00154   std::cout << "######################################\n";
00155 
00156 
00157   return 0;
00158 }
00159 
00160 
00161 

Generated on Mon Nov 10 08:13:15 2008 for libFAUDES 2.11v by  doxygen 1.4.4