cfl_parallel.hGo to the documentation of this file.00001 /** @file cfl_parallel.h parallel composition */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2006 Bernd Opitz 00006 Exclusive copyright is granted to Klaus Schmidt 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00021 00022 00023 #ifndef FAUDES_PARALLEL_H 00024 #define FAUDES_PARALLEL_H 00025 00026 #include "cfl_agenerator.h" 00027 #include <stack> 00028 #include <map> 00029 #include <set> 00030 00031 namespace faudes { 00032 00033 00034 /** 00035 * Rti-wrapper for composition maps 00036 * 00037 * Parallel-composition and related functions provide an optional 00038 * argument to record a mapping from original state-indicees to 00039 * result state-indicees. In order to support this data type in the 00040 * run-time interface, we provide a wrapper class that is derived 00041 * from faudes Type. The curent implementation is minimal (no token io). 00042 */ 00043 class ProductCompositionMap : public Type { 00044 FAUDES_TYPE_DECLARATION(ProductCompositionMap,ProductCompositionMap,Type) 00045 public: 00046 // std faudes type 00047 ProductCompositionMap(void); 00048 ProductCompositionMap(const ProductCompositionMap& rOther); 00049 virtual ~ProductCompositionMap(void); 00050 virtual void Clear(void); 00051 // access C++/STL data 00052 const std::map< std::pair<Idx,Idx> , Idx >& StlMap(void) const; 00053 std::map< std::pair<Idx,Idx> , Idx >& StlMap(void); 00054 void StlMap(const std::map< std::pair<Idx,Idx> , Idx >& rMap); 00055 // translate states (return 0 on out-of-range) 00056 Idx CompState(Idx s1, Idx s2) const; 00057 Idx Arg1State(Idx s12) const; 00058 Idx Arg2State(Idx s12) const; 00059 protected: 00060 // std faudes type 00061 virtual void DoAssign(const ProductCompositionMap& rSrc); 00062 virtual bool DoEqual(const ProductCompositionMap& rOther) const; 00063 // my data (primary) 00064 std::map< std::pair<Idx,Idx> , Idx > mCompositionMap; 00065 // my data (derived) 00066 mutable bool mCompiled; 00067 mutable std::map<Idx,Idx> mArg1Map; 00068 mutable std::map<Idx,Idx> mArg2Map; 00069 }; 00070 00071 00072 00073 /** 00074 * Parallel composition. 00075 * 00076 * Constructs the parallel composition of two generators, where shared events 00077 * are synchronised while non-shared events are executed independantly. 00078 * The resulting generators alphabet is the union of the argument alphabets. 00079 * In this implementation, only accessible states are generated. 00080 * On deterministic input this functions constructs a deterministic output. 00081 * See also Parallel(const Generator&,std::map< std::pair<Idx,Idx>, Idx>&,const Generator&, Generator&). 00082 * 00083 * @param rGen1 00084 * First generator 00085 * @param rGen2 00086 * Second generator 00087 * @param rResGen 00088 * Reference to resulting parallel composition generator 00089 * 00090 * <h4>Example:</h4> 00091 * <table border=0> <tr> <td> <table> 00092 * <tr> <td> Generator G1 </td> <td> Generator G2 </td> </tr> 00093 * <tr> 00094 * <td> @image html tmp_parallel_g1.png </td> 00095 * <td> @image html tmp_parallel_g2.png </td> 00096 * </tr> 00097 * </table> </td> </tr> <tr> <td> <table width=100%> 00098 * <tr> <td> G1 || G2 </td> </tr> 00099 * <tr> <td> @image html tmp_parallel_g1g2.png </td> </tr> 00100 * </table> </td> </tr> </table> 00101 * 00102 * @ingroup GeneratorFunctions 00103 * 00104 */ 00105 void Parallel(const Generator& rGen1, const Generator& rGen2, Generator& rResGen); 00106 00107 00108 /** 00109 * Parallel composition. 00110 * 00111 * See also Parallel(const Generator&, const Generator&, Generator&). 00112 * This version tries to be transparent on event attributes: if 00113 * argument attributes match and if the result can take the respective 00114 * attributes, then they are copied; it is considered an error if 00115 * argument attributes do not match. 00116 * 00117 * @param rGen1 00118 * First generator 00119 * @param rGen2 00120 * Second generator 00121 * @param rResGen 00122 * Reference to resulting composition generator 00123 * 00124 * @ingroup GeneratorFunctions 00125 */ 00126 void aParallel(const Generator& rGen1, const Generator& rGen2, Generator& rResGen); 00127 00128 /** 00129 * Parallel composition. 00130 * 00131 * See also aParallel(const Generator&, const Generator&, Generator&). 00132 * This version takes a vector of generators as argument to perform 00133 * a synchronous composition of multiple generators. The implementation 00134 * calls the std aParallel multiple times, future implementations may 00135 * explore the overall reachable state set. 00136 * 00137 * @param rGenVec 00138 * Vector of input generators 00139 * @param rResGen 00140 * Reference to resulting composition generator 00141 * 00142 */ 00143 void aParallel(const GeneratorVector& rGenVec, Generator& rResGen); 00144 00145 00146 00147 /** 00148 * Parallel composition. 00149 * 00150 * See also Parallel(const Generator&, const Generator&, Generator&). 00151 * This version fills a composition map to map pairs of old states 00152 * to new states. 00153 * 00154 * @param rGen1 00155 * First generator 00156 * @param rGen2 00157 * Second generator 00158 * @param rCompositionMap 00159 * Composition map 00160 * @param rResGen 00161 * Reference to resulting composition generator 00162 * 00163 * @ingroup GeneratorFunctions 00164 */ 00165 void aParallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen); 00166 00167 00168 00169 00170 /** 00171 * Parallel composition. 00172 * 00173 * See Parallel(const Generator&, const Generator&, Generator&). 00174 * This version fills a composition map to map pairs of old states 00175 * to new states. 00176 * 00177 * @param rGen1 00178 * First generator 00179 * @param rGen2 00180 * Second generator 00181 * @param rCompositionMap 00182 * Composition map (map< pair<Idx,Idx>, Idx>) 00183 * @param rResGen 00184 * Reference to resulting parallel composition generator 00185 */ 00186 void Parallel( 00187 const Generator& rGen1, const Generator& rGen2, 00188 std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap, 00189 Generator& rResGen); 00190 00191 00192 /** 00193 * Parallel composition. 00194 * 00195 * See also Parallel(const Generator&, const Generator&, Generator&). 00196 * This version fills a composition map to map pairs of old states 00197 * to new states. 00198 * 00199 * @param rGen1 00200 * First generator 00201 * @param rGen2 00202 * Second generator 00203 * @param rCompositionMap 00204 * Composition map 00205 * @param rResGen 00206 * Reference to resulting composition generator 00207 * 00208 * @ingroup GeneratorFunctions 00209 */ 00210 void Parallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen); 00211 00212 00213 00214 /** 00215 * Parallel composition. 00216 * 00217 * See Parallel(const Generator&, const Generator&, Generator&). 00218 * This version fills a composition map to map pairs of old states 00219 * to new states. It also returns the sets of states marked w.r.t. the 00220 * argument generators. 00221 * 00222 * @param rGen1 00223 * First generator 00224 * @param rGen2 00225 * Second generator 00226 * @param rCompositionMap 00227 * Composition map (map< pair<Idx,Idx>, Idx>) 00228 * @param rMark2 00229 * States maked in first generator 00230 * @param rMark1 00231 * States maked in second generator 00232 * @param rResGen 00233 * Reference to resulting parallel composition generator 00234 */ 00235 void Parallel( 00236 const Generator& rGen1, const Generator& rGen2, 00237 ProductCompositionMap& rCompositionMap, 00238 StateSet& rMark1, 00239 StateSet& rMark2, 00240 Generator& rResGen); 00241 00242 00243 /** 00244 * Product composition. 00245 * 00246 * The product composition executes shared events only. The resulting 00247 * generators alphabet is the interscetion of the argument alphabets. 00248 * In this implementation, only accessible states are generated. 00249 * Assumes deterministic input generators, result is deterministic. 00250 * 00251 * @param rGen1 00252 * First generator 00253 * @param rGen2 00254 * Second generator 00255 * @param rResGen 00256 * Reference to resulting product composition generator 00257 * 00258 * @ingroup GeneratorFunctions 00259 */ 00260 void Product(const Generator& rGen1, const Generator& rGen2, Generator& rResGen); 00261 00262 00263 /** 00264 * Product composition. 00265 * 00266 * See Product(const Generator&, const Generator&, Generator&). 00267 * This version fills given composition map to map pairs of old states 00268 * to new states. 00269 * 00270 * @param rGen1 00271 * First generator 00272 * @param rGen2 00273 * Second generator 00274 * @param rCompositionMap 00275 * Composition map (map< pair<Idx,Idx>, Idx>) 00276 * @param rResGen 00277 * Reference to resulting product composition generator 00278 */ 00279 void Product( 00280 const Generator& rGen1, const Generator& rGen2, 00281 std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap, 00282 Generator& rResGen); 00283 00284 00285 /** 00286 * Product composition. 00287 * 00288 * See Product(const Generator&, const Generator&, Generator&). 00289 * This version fills given composition map to map pairs of old states 00290 * to new states. It also returns the sets of states marked w.r.t. the 00291 * argument generators. 00292 * 00293 * @param rGen1 00294 * First generator 00295 * @param rGen2 00296 * Second generator 00297 * @param rCompositionMap 00298 * Composition map (map< pair<Idx,Idx>, Idx>) 00299 * @param rMark2 00300 * States maked in first generator 00301 * @param rMark1 00302 * States maked in second generator 00303 * @param rResGen 00304 * Reference to resulting product composition generator 00305 */ 00306 void Product( 00307 const Generator& rGen1, const Generator& rGen2, 00308 std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap, 00309 StateSet& rMark1, 00310 StateSet& rMark2, 00311 Generator& rResGen); 00312 00313 00314 /** 00315 * Product composition. 00316 * 00317 * See also Product(const Generator&, const Generator&, Generator&). 00318 * This version tries to be transparent on event attributes: if 00319 * argument attributes match and if the result can take the respective 00320 * attributes, then they are copied; it is considered an error if 00321 * argument attributes do not match. 00322 * 00323 * @param rGen1 00324 * First generator 00325 * @param rGen2 00326 * Second generator 00327 * @param rResGen 00328 * Reference to resulting product composition generator 00329 * 00330 * @ingroup GeneratorFunctions 00331 */ 00332 void aProduct(const Generator& rGen1, const Generator& rGen2, Generator& rResGen); 00333 00334 00335 /** 00336 * Product composition. 00337 * 00338 * See also Product(const Generator&, const Generator&, Generator&). 00339 * This version fills a omposition map to map pairs of old states 00340 * to new states. 00341 * 00342 * @param rGen1 00343 * First generator 00344 * @param rGen2 00345 * Second generator 00346 * @param rCompositionMap 00347 * Composition map 00348 * @param rResGen 00349 * Reference to resulting composition generator 00350 * 00351 * @ingroup GeneratorFunctions 00352 */ 00353 void aProduct(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen); 00354 00355 /** 00356 * Helper: uses composition map to track state names 00357 * in a paralell composition. Purely cosmetic. 00358 * 00359 * @param rGen1 00360 * First generator 00361 * @param rGen2 00362 * Second generator 00363 * @param rCompositionMap 00364 * Composition map (map< pair<Idx,Idx>, Idx>) 00365 * @param rGen12 00366 * Reference to resulting parallel composition generator 00367 */ 00368 void SetComposedStateNames( 00369 const Generator& rGen1, const Generator& rGen2, 00370 const std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap, 00371 Generator& rGen12); 00372 00373 } // namespace faudes 00374 00375 00376 #endif 00377 libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |