cgenfunct.cpp

Go to the documentation of this file.
00001 
00003 /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005    Copyright (C) 2006  Bernd Opitz
00006    Copyright (C) 2007  Thomas Moor
00007    Exclusive copyright is granted to Klaus Schmidt
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Lesser General Public
00011    License as published by the Free Software Foundation; either
00012    version 2.1 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Lesser General Public License for more details.
00018 
00019    You should have received a copy of the GNU Lesser General Public
00020    License along with this library; if not, write to the Free Software
00021    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00022 
00023 
00024 #include "cgenfunct.h"
00025 
00026 namespace faudes {
00027 
00028 // controllability test for cGenerator plant
00029 bool cIsControllable(
00030   const cGenerator& rPlantGen, 
00031   const vGenerator& rSupCandGen)
00032 {
00033   return IsControllable(rPlantGen, rPlantGen.ControllableEvents(), rSupCandGen);
00034 }
00035 
00036 
00037 // supcon for cGenerators:
00038 // uses and maintains controllablity from plant 
00039 void cSupConNB(
00040   const cGenerator& rPlantGen, 
00041   const vGenerator& rSpecGen, 
00042   cGenerator& rResGen) {
00043 
00044   // prepare result
00045   cGenerator* pResGen = &rResGen;
00046   if(&rResGen== &rPlantGen || &rResGen== &rSpecGen) {
00047     pResGen= rResGen.NewP();
00048   }
00049 
00050   // execute 
00051   SupConNB(rPlantGen, rPlantGen.ControllableEvents(),rSpecGen,*pResGen);
00052 
00053   // copy controllability of input alphabets
00054   pResGen->SetControllable(rPlantGen.ControllableEvents());
00055 
00056   // copy result
00057   if(pResGen != &rResGen) {
00058     rResGen = *pResGen;
00059     delete pResGen;
00060   }
00061 
00062 }
00063 
00064 // supcon for cGenerators
00065 // uses and maintains controllablity from plant 
00066 void cSupCon(
00067   const cGenerator& rPlantGen, 
00068   const vGenerator& rSpecGen, 
00069   cGenerator& rResGen) {
00070 
00071   // prepare result
00072   cGenerator* pResGen = &rResGen;
00073   if(&rResGen== &rPlantGen || &rResGen== &rSpecGen) {
00074     pResGen= rResGen.NewP();
00075   }
00076 
00077   // execute
00078   SupCon(rPlantGen, rPlantGen.ControllableEvents(),rSpecGen,*pResGen);
00079 
00080   // copy controllability of input alphabets
00081   pResGen->SetControllable(rPlantGen.ControllableEvents());
00082 
00083   // copy result
00084   if(pResGen != &rResGen) {
00085     rResGen = *pResGen;
00086     delete pResGen;
00087   }
00088 
00089 }
00090 
00091 // parallel for cGenerators: sets the controllability 
00092 // attributes of the events of the result.
00093 void cParallel(
00094   const cGenerator& rGen1,
00095   const cGenerator& rGen2,
00096   cGenerator& rResGen) 
00097 {
00098 
00099   // inputs have to agree on controllability of shared events:
00100 #ifdef FAUDES_CHECKED
00101   EventSet inconsistent =
00102     (rGen1.ControllableEvents()*rGen2.UncontrollableEvents())
00103     +(rGen1.UncontrollableEvents()*rGen2.ControllableEvents());
00104     
00105     if(!inconsistent.Empty()) {
00106       std::stringstream errstr;
00107       errstr << "cParallel: inconsistent controllability flags";
00108       //throw Exception("TaGenerator::write", errstr.str(), 500);
00109     }
00110 #endif
00111 
00112   // prepare result
00113   cGenerator* pResGen = &rResGen;
00114   if(&rResGen== &rGen1 || &rResGen== &rGen2) {
00115     pResGen= rResGen.NewP();
00116   }
00117 
00118   // make parallel composition of inputs
00119   Parallel(rGen1,rGen2,*pResGen);
00120 
00121   // copy controllability of input alphabets
00122   pResGen->SetControllable(rGen1.ControllableEvents());
00123   pResGen->SetControllable(rGen2.ControllableEvents());
00124 
00125   // copy result
00126   if(pResGen != &rResGen) {
00127     rResGen = *pResGen;
00128     delete pResGen;
00129   }
00130 }
00131 
00132 // cheap version of projection for cGenerators that sets the
00133 // controllability attributes of the events of the result.
00134 void cProject(
00135   const cGenerator& rGen,
00136   const EventSet& rProjectAlphabet,
00137   cGenerator& rResGen) 
00138 {
00139 
00140   // prepare result
00141   cGenerator* pResGen = &rResGen;
00142   if(&rResGen== &rGen) {
00143     pResGen= rResGen.NewP();
00144   }
00145 
00146   // execute Project
00147   Project(rGen,rProjectAlphabet,*pResGen);
00148 
00149   // copy controllability of input alphabets
00150   pResGen->SetControllable(rGen.ControllableEvents()*rProjectAlphabet);
00151 
00152   // copy result
00153   if(pResGen != &rResGen) {
00154     rResGen = *pResGen;
00155     delete pResGen;
00156   }
00157 }
00158 
00159 
00160 
00161 }// namespace

Generated on Fri May 9 11:26:47 2008 for libFAUDES 2.09b by  doxygen 1.4.4