hio_3_hiofunctions.cpp

Go to the documentation of this file.
00001 /** @file hio_3_hiofunctions.cpp
00002 
00003 Tutorial, functions provided by hiosys plugin.
00004 
00005 @ingroup Tutorials 
00006 
00007 @include hio_3_hiofunctions.cpp
00008 
00009 */
00010 
00011 #include "libfaudes.h"
00012 
00013 // make the faudes namespace available to our program
00014 using namespace faudes;
00015 using namespace std;
00016 
00017 /** simple machine example to demonstrate I/O controller synthesis */
00018 void simpleMachine() {
00019  
00020   /* 
00021   % Simple machine example for hiosys-tutorial.
00022   % Machine sends YP-event "A_wait" to operator.
00023   % Does nothing after UP-event "A_stp", or executes
00024   % the process "A_do", which requires a shared
00025   % resource from the environment, modelled by
00026   % "A_req". The environment may provide or
00027   % deny access to the resource ("A_pack" or
00028   % "A_nack", respectively).
00029   */
00030    
00031   // read plant A model
00032   HioPlant plantA;
00033   plantA.Read("data/3_hiofunctions/hio_simplemachine_A.gen");
00034   plantA.GraphWrite("tmp_hio_simplemachine_A.png");
00035   // must be in I/O plant form
00036   if(!IsHioPlantForm(plantA)){
00037       std::stringstream errstr;
00038       errstr << "plant A not in HioPlantForm.\n";
00039     throw Exception("simpleMachine", errstr.str(), 0);
00040   }
00041   
00042   /*
00043   % Environment constraint:
00044   % Resources are always provided as requested.
00045   */
00046   // read plant A environment constraint
00047   HioConstraint SeA;
00048   SeA.Read("data/3_hiofunctions/hio_simpleEnvConstr_A.gen");
00049   //should be in I/O constraint form:
00050   if(!IsHioConstraintForm(SeA)) {
00051     std::cout<<"Warning: environment constraint A not in I/O constraint form.";
00052   }
00053   SeA.GraphWrite("tmp_hio_simpleEnvConstr_A.png");
00054   
00055   /*
00056   % Operator constraint:
00057   % simple machine is complete and YP-life wrt. to the
00058   % environment constraint and a minimal operator
00059   % constraint, which - for convenience - can be
00060   % modelled by an epsilon language HioConstraint.
00061   */
00062   // construct epsilon language operator constraint
00063   HioConstraint SpA;
00064   Idx init=SpA.InsInitState();
00065   SpA.SetMarkedState(init);
00066   
00067   // first, we synthesise a controller for the single plant A:  
00068 /*============================================================================
00069 ================ CONTROLLER SYNTHESIS FOR MONOLITHIC PLANT =============
00070 ==============================================================================*/
00071 
00072   /*
00073   % Specification:
00074   % Send YC-event "A_READY" as feedback to operator.
00075   % Accept UC-events "A_STANDBY" or "A_OPERATE" as 
00076   % operator inputs.
00077   % Command "A_STANDBY": do nothing.
00078   % Command "A_OPERATE": Process two resources.
00079   */
00080   HioPlant specA;
00081   specA.Read("data/3_hiofunctions/hio_simplespec_A.gen");
00082   specA.GraphWrite("tmp_hio_simplespec_A.png");
00083     
00084   /*
00085   % external operator constraint:
00086   % also specification A is complete and YP-life wrt. to the
00087   % environment constraint and a minimal operator
00088   % constraint.
00089   */
00090   // construct epsilon language external operator constraint
00091   HioConstraint ScA;
00092   init=ScA.InsInitState();
00093   ScA.SetMarkedState(init);
00094   
00095   // run controller synthesis algorithm
00096   HioController controllerA;
00097   HioSynthMonolithic(plantA,specA,ScA,SpA,SeA,controllerA);
00098   FAUDES_TEST_DUMP("HioSynthMonolithic",controllerA);
00099   controllerA.Write("tmp_hio_simpleController_A.gen");
00100   controllerA.GraphWrite("tmp_hio_simpleController_A.png");
00101   
00102   // now, we synthesise a controller for two plants A and B:  
00103 /*============================================================================
00104 ===================== HIERARCHICAL CONTROLLER SYNTHESIS =================
00105 ==============================================================================*/
00106   
00107   /*
00108   % Machine B Sends YP-event "B_wait" to operator.
00109   % Does nothing after UP-event "B_stp", or executes
00110   % the process "B_do", which produces a shared
00111   % resource provided to the environment, modelled
00112   % by "B_prov". The environment may or may not
00113   % accept the resource ("B_pack" or "B_nack",
00114   % respectively).
00115    */
00116    
00117   // read plant B model
00118   HioPlant plantB;
00119   plantB.Read("data/3_hiofunctions/hio_simplemachine_B.gen");
00120   plantB.GraphWrite("tmp_hio_simplemachine_B.png");
00121   // must be in I/O plant form
00122   if(!IsHioPlantForm(plantB)){
00123       std::stringstream errstr;
00124       errstr << "plant B not in HioPlantForm.\n";
00125     throw Exception("simpleMachine", errstr.str(), 0);
00126   }
00127   
00128   /*
00129   % Environment constraint:
00130   % Resources are always provided as requested.
00131   */
00132   // read plant A environment constraint
00133   HioConstraint SeB;
00134   SeB.Read("data/3_hiofunctions/hio_simpleEnvConstr_B.gen");
00135   if(!IsHioConstraintForm(SeB)) {
00136     std::cout<<"Warning: environment constraint B not in I/O constraint form.";
00137   }
00138   SeB.GraphWrite("tmp_hio_simpleEnvConstr_B.png");
00139   
00140   /*
00141   % Operator constraint:
00142   % simple machine B is complete and YP-life wrt. to the
00143   % environment constraint and a minimal operator
00144   % constraint, which - for convenience - can be
00145   % modelled by an epsilon language HioConstraint.
00146   */
00147   // construct epsilon language operator constraint
00148   HioConstraint SpB;
00149   init=SpB.InsInitState();
00150   SpB.SetMarkedState(init);
00151   
00152   /*===============================================
00153   I/O SHUFFLE OF PLANT A AND PLANT B
00154   =================================================*/
00155 
00156   HioPlant ioShuffleAB;
00157   HioShuffle(plantA,plantB,ioShuffleAB);
00158   FAUDES_TEST_DUMP("HioShuffle",ioShuffleAB);
00159   ioShuffleAB.Write("tmp_hio_simpleHioShuffle_AB.gen");
00160   ioShuffleAB.GraphWrite("tmp_hio_simpleHioShuffle_AB.png");
00161   
00162   // compose constraints of plant A and B_do
00163   HioConstraint intConstrAB;
00164   Parallel(SpA,SpB,intConstrAB);
00165   Parallel(intConstrAB,SeA,intConstrAB);
00166   Parallel(intConstrAB,SeB,intConstrAB);
00167   intConstrAB.StateNamesEnabled(false);
00168   
00169   /*===============================================
00170   ENVIRONMENT MODEL FOR PLANT AB
00171   =================================================*/
00172   /*
00173   % Simple machine example for hiosys-tutorial.
00174   % Environment:
00175   % A request of machine A (A_req) for a resource is
00176   % denied (A_nack) until machine B provides it
00177   % (B_prov, B_pack). Then, machine A has to request
00178   % the resource until machine B can provide the next
00179   % one. A resource provided by machine B and
00180   % requested by machine A is readily processed
00181   % and can be provided to the external
00182   % environment (AB_prov), which may or may not
00183   % accept the processed resource (AB_pack,
00184   % AB_nack).
00185   */
00186   HioEnvironment envAB("data/3_hiofunctions/hio_simpleenvironment_AB.gen");
00187   envAB.GraphWrite("tmp_hio_simpleenvironment_AB.png");
00188   
00189   /*
00190   % Environment constraint:
00191   % Processed resources are always accepted as provided.
00192   */
00193   // read plant A environment constraint
00194   HioConstraint SlAB;
00195   SlAB.Read("data/3_hiofunctions/hio_simpleEnvConstr_AB.gen");
00196   if(!IsHioConstraintForm(SlAB)) {
00197     std::cout<<"Warning: environment constraint AB not in I/O constraint form.";
00198   }
00199   SlAB.GraphWrite("tmp_hio_simpleEnvConstr_AB.png");
00200   
00201   /*====================================================
00202   SPECIFICATION AND EXTERNAL OPERATOR CONSTRAINT
00203   ======================================================*/  
00204   /*
00205   % Simple machine example for hiosys-tutorial.
00206   % Specification:
00207   % Send YC-event "AB_READY" as feedback to operator.
00208   % Accept UC-events "AB_STANDBY" or "AB_OPERATE" as 
00209   % operator inputs.
00210   % Command "AB_STANDBY": do nothing.
00211   % Command "AB_OPERATE": Provide processed resource (AB_prov).
00212    */
00213   HioPlant specAB;
00214   specAB.Read("data/3_hiofunctions/hio_simplespec_AB.gen");
00215   specAB.GraphWrite("tmp_hio_simplespec_AB.png");
00216     
00217   /*
00218   % external operator constraint:
00219   % also specification AB is complete and YP-life wrt. to the
00220   % environment constraint and a minimal operator
00221   % constraint.
00222   */
00223   // construct epsilon language external operator constraint
00224   HioConstraint ScAB;
00225   init=ScAB.InsInitState();
00226   ScAB.SetMarkedState(init);
00227   
00228   // run controller synthesis algorithm
00229   HioController controllerAB;
00230   HioSynthHierarchical(ioShuffleAB,envAB,specAB,intConstrAB,ScAB,SlAB,controllerAB);
00231   FAUDES_TEST_DUMP("HioSynthHierarchical",controllerAB);
00232   controllerAB.Write("tmp_hio_simpleController_AB.gen");
00233   controllerAB.GraphWrite("tmp_hio_simpleController_AB.png");
00234   
00235     return;
00236 }
00237 
00238 
00239 /** Run the tutorial */
00240 int main() {
00241   // call simple machine example
00242   try {
00243   simpleMachine();
00244   }
00245   catch (Exception& e) {
00246   std::cout << "function: " << e.Where() << std::endl;
00247   std::cout << "exception description: " << e.What() << std::endl;
00248   std::cout << "exception id: " << e.Id() << std::endl;
00249 }
00250   return 0;
00251 }

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen