tp_1_tgenerator.cpp

Go to the documentation of this file.
00001 
00012 #include "libfaudes.h"
00013 #include "tp_include.h"
00014 
00015 
00016 // make the faudes namespace available to our program
00017 using namespace faudes;
00018 
00019 
00020 
00022 // main program
00024 
00025 int main() {
00026 
00027   /***************************************************************
00028    * constructor and file io
00029    *
00030    ***************************************************************/
00031 
00032   // At first we create an empty tGenerator object
00033 
00034   tGenerator g1;
00035 
00036   // We create a tGenerator by reading a tGenerator file
00037 
00038   tGenerator g2("data/tsimplemachine.gen");
00039  
00040   // We create a tGenerator by reading a Generator file (no timing, no control)
00041 
00042   tGenerator g3("data/simplemachine.gen");
00043 
00044   // We read a tGenerator from a cGenerator file (no timing)
00045 
00046   g1.Read("data/csimplemachine.gen");
00047 
00048   // We copy a Generator to a tGenerator (no timing, no control)
00049   tGenerator g4;
00050   Generator g5("data/simplemachine.gen");
00051   g5.Copy(g4);
00052 
00053   // We write the tGenerator to a files 
00054 
00055   g1.Write("tmp_tsimplemachine1.gen");
00056   g2.Write("tmp_tsimplemachine2.gen");
00057   g3.Write("tmp_tsimplemachine3.gen");
00058   g4.Write("tmp_tsimplemachine4.gen");
00059 
00060 
00061   // See result on console
00062 
00063   std::cout << "######################################\n";
00064   std::cout << "# tc simple machine (\n";
00065   g2.DWrite();
00066   std::cout << "######################################\n";
00067 
00068 
00069 
00070 
00071  /***************************************************************
00072   * access to controllability status of events
00073   * 
00074   * (using cGenerator methods)
00075   ***************************************************************/
00076 
00077   // Retrieve an EventSet containing all the controllabe events 
00078 
00079   EventSet cevents = g2.ControllableEvents();
00080 
00081   // See result on console
00082 
00083   std::cout << "######################################\n";
00084   std::cout << "# controllabel events\n";
00085   cevents.DWrite();
00086   std::cout << "######################################\n";
00087 
00088 
00089  /***************************************************************
00090   * access timing 
00091   *
00092   ***************************************************************/
00093   
00094 
00095 
00096   // insert a clock to tcsimplemachine
00097 
00098   g2.InsClock("cRepair");
00099 
00100   // read clocks from tcsimplemachine and set them for csimplemachine 
00101 
00102   ClockSet clocks = g2.Clocks();
00103  
00104   // report
00105 
00106   std::cout << "######################################\n";
00107   std::cout << "# tcsimple machine clocks \n";
00108   clocks.DWrite();
00109   std::cout << "######################################\n";
00110 
00111 
00112   // add constraints to invariant
00113  
00114   TimeConstraint inv;
00115   inv.Insert("cRepair",ElemConstraint::LessEqual,20);
00116   g2.InsInvariant("down", inv);
00117 
00118   // add constraints to guard and a reset
00119  
00120   TransSet::Iterator tit=g2.FindTransition("down","lambda","idle");
00121   if(tit==g2.TransRelEnd()) {}; // not found
00122 
00123   TimeConstraint guard;
00124   guard.Insert("cRepair",ElemConstraint::GreaterEqual,10);
00125   g2.InsGuard(*tit, guard);
00126   ClockSet resets;
00127   resets.Insert("cRepair");
00128   g2.InsResets(*tit, resets);
00129 
00130   // fix name
00131 
00132   g2.Name("tc simple machine with timed repair");
00133 
00134   // report
00135 
00136   std::cout << "######################################\n";
00137   std::cout << "# tcsimple machine with timed repair \n";
00138   g2.DWrite();
00139   g2.ActiveClocks().DWrite();
00140   std::cout << "######################################\n";
00141 
00142   // copy to g1 and remove a clock
00143 
00144   g1=g2;
00145   g1.DelClock("cBusy");
00146 
00147   // report
00148 
00149   std::cout << "######################################\n";
00150   std::cout << "# tcsimple machine with untimed busy \n";
00151   g1.DWrite();
00152   g1.ActiveClocks().DWrite();
00153   std::cout << "######################################\n";
00154 
00155 
00156 
00157 
00158 
00159   // read clocks from tcsimplemachine and set them for csimplemachine 
00160 
00161   std::cout << "######################################\n";
00162   std::cout << "# csimple machine (active clocks) \n";
00163   g3.InsClocks(g2.ActiveClocks());
00164   std::cout << g3.Clocks().ToString() << "\n";
00165 
00166   // read invriants from tcsimplemachine and set them for csimplemachine 
00167 
00168   std::cout << "######################################\n";
00169   std::cout << "# csimple machine (invariants) \n";
00170   StateSet::Iterator sit;
00171   for(sit=g2.StatesBegin(); sit!=g2.StatesEnd(); sit++) {
00172     TimeConstraint invariant = g2.Invariant(*sit);
00173     std::string state = g2.StateName(*sit);
00174     std::cout << state << " inv " << invariant.ToString() << "\n";
00175     g3.Invariant(state, invariant);
00176   }
00177 
00178   // read guards and resets from tcsimplemachine and set them for csimplemachine 
00179 
00180   std::cout << "######################################\n";
00181   std::cout << "# csimple machine (guards and resets) \n";
00182   TransSet::Iterator stit, dtit;
00183   for(stit=g2.TransRelBegin(); stit!= g2.TransRelEnd(); stit++) {
00184     std::cout << "src transition: " << g2.TStr(*stit) << "\n";
00185     std::cout << "guard:  " << g2.Guard(*stit).ToString() << "\n";
00186     std::cout << "resets: " << g2.Resets(*stit).ToString() << "\n";
00187     dtit=g3.FindTransition(g2.StateName(stit->X1),g2.EventName(stit->Ev),g2.StateName(stit->X2));
00188     g3.Guard(*dtit,g2.Guard(*stit));
00189     g3.Resets(*dtit,g2.Resets(*stit));
00190   }
00191 
00192   std::cout << "######################################\n";
00193   std::cout << "# csimple machine with timing \n";
00194   g3.DWrite();
00195   std::cout << "######################################\n";
00196 
00197 
00198   // check validiy (internal names and symboltables)
00199   if(g3.Valid())
00200     std::cout << "############# valid #################\n";
00201   
00202 
00203   return 0;
00204 }
00205 
00206 
00207 

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