cfl_parallel.h
Go to the documentation of this file.
1 /** @file cfl_parallel.h parallel composition */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2006 Bernd Opitz
6  Exclusive copyright is granted to Klaus Schmidt
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 #ifndef FAUDES_PARALLEL_H
24 #define FAUDES_PARALLEL_H
25 
26 #include "cfl_agenerator.h"
27 #include <stack>
28 #include <map>
29 #include <set>
30 
31 namespace faudes {
32 
33 
34 /**
35  * Rti-wrapper for composition maps
36  *
37  * Parallel-composition and related functions provide an optional
38  * argument to record a mapping from original state-indicees to
39  * result state-indicees. In order to support this data type in the
40  * run-time interface, we provide a wrapper class that is derived
41  * from faudes Type. The curent implementation is minimal (no token io).
42  */
45 public:
46 
47  using Type::operator=;
48  using Type::operator==;
49  using Type::operator!=;
50 
51  // std faudes type
54  virtual ~ProductCompositionMap(void);
55  virtual void Clear(void);
56  // access C++/STL data
57  const std::map< std::pair<Idx,Idx> , Idx >& StlMap(void) const;
58  std::map< std::pair<Idx,Idx> , Idx >& StlMap(void);
59  void StlMap(const std::map< std::pair<Idx,Idx> , Idx >& rMap);
60  // translate states (return 0 on out-of-range)
61  Idx CompState(Idx s1, Idx s2) const;
62  Idx Arg1State(Idx s12) const;
63  Idx Arg2State(Idx s12) const;
64 protected:
65  // std faudes type
66  void DoAssign(const ProductCompositionMap& rSrc);
67  bool DoEqual(const ProductCompositionMap& rOther) const;
68  // my data (primary)
69  std::map< std::pair<Idx,Idx> , Idx > mCompositionMap;
70  // my data (derived)
71  mutable bool mCompiled;
72  mutable std::map<Idx,Idx> mArg1Map;
73  mutable std::map<Idx,Idx> mArg2Map;
74 };
75 
76 
77 
78 /**
79  * Parallel composition.
80  *
81  * Constructs the parallel composition of two generators, where shared events
82  * are synchronised while non-shared events are executed independantly.
83  * The resulting generators alphabet is the union of the argument alphabets.
84  * In this implementation, only accessible states are generated.
85  * On deterministic input this functions constructs a deterministic output.
86  * See also Parallel(const Generator&,std::map< std::pair<Idx,Idx>, Idx>&,const Generator&, Generator&).
87  *
88  * @param rGen1
89  * First generator
90  * @param rGen2
91  * Second generator
92  * @param rResGen
93  * Reference to resulting parallel composition generator
94  *
95  * <h4>Example:</h4>
96  * <table border=0> <tr> <td> <table>
97  * <tr> <td> Generator G1 </td> <td> Generator G2 </td> </tr>
98  * <tr>
99  * <td> @image html tmp_parallel_g1.png </td>
100  * <td> @image html tmp_parallel_g2.png </td>
101  * </tr>
102  * </table> </td> </tr> <tr> <td> <table width=100%>
103  * <tr> <td> G1 || G2 </td> </tr>
104  * <tr> <td> @image html tmp_parallel_g1g2.png </td> </tr>
105  * </table> </td> </tr> </table>
106  *
107  * @ingroup GeneratorFunctions
108  *
109  */
110 extern FAUDES_API void Parallel(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
111 
112 
113 /**
114  * Parallel composition.
115  *
116  * See also Parallel(const Generator&, const Generator&, Generator&).
117  * This version takes a vector of generators as argument to perform
118  * a synchronous composition of multiple generators. The implementation
119  * calls the std Parallel multiple times, future implementations may
120  * explore the overall reachable state set.
121  *
122  * @param rGenVec
123  * Vector of input generators
124  * @param rResGen
125  * Reference to resulting composition generator
126  *
127  */
128 extern FAUDES_API void Parallel(const GeneratorVector& rGenVec, Generator& rResGen);
129 
130 
131 /**
132  * Parallel composition, non-blocking part.
133  *
134  * See also Parallel(const Generator&, const Generator&, Generator&).
135  * This version takes a vector of generators as argument to perform
136  * a synchronous composition of multiple generators. The implementation
137  * calls the std Parallel multiple times, and, at each stage, removes outgoing transitions
138  * from blocking states. Thus, the result will be accurate for non-blocking part only.
139  *
140  * @param rGenVec
141  * Vector of input generators
142  * @param rResGen
143  * Reference to resulting composition generator
144  *
145  */
146 extern FAUDES_API void ParallelNB(const GeneratorVector& rGenVec, Generator& rResGen);
147 
148 
149 /**
150  * Parallel composition.
151  *
152  * See also Parallel(const Generator&, const Generator&, Generator&).
153  * This version tries to be transparent on event attributes: if
154  * argument attributes match and if the result can take the respective
155  * attributes, then they are copied; it is considered an error if
156  * argument attributes do not match.
157  *
158  * @param rGen1
159  * First generator
160  * @param rGen2
161  * Second generator
162  * @param rResGen
163  * Reference to resulting composition generator
164  *
165  * @ingroup GeneratorFunctions
166  */
167 extern FAUDES_API void aParallel(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
168 
169 /**
170  * Parallel composition.
171  *
172  * See also aParallel(const Generator&, const Generator&, Generator&).
173  * This version takes a vector of generators as argument to perform
174  * a synchronous composition of multiple generators. The implementation
175  * calls the std aParallel multiple times, future implementations may
176  * explore the overall reachable state set.
177  *
178  * @param rGenVec
179  * Vector of input generators
180  * @param rResGen
181  * Reference to resulting composition generator
182  *
183  */
184 extern FAUDES_API void aParallel(const GeneratorVector& rGenVec, Generator& rResGen);
185 
186 
187 
188 /**
189  * Parallel composition.
190  *
191  * See also Parallel(const Generator&, const Generator&, Generator&).
192  * This version fills a composition map to map pairs of old states
193  * to new states.
194  *
195  * @param rGen1
196  * First generator
197  * @param rGen2
198  * Second generator
199  * @param rCompositionMap
200  * Composition map
201  * @param rResGen
202  * Reference to resulting composition generator
203  *
204  * @ingroup GeneratorFunctions
205  */
206 extern FAUDES_API void aParallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
207 
208 
209 
210 
211 /**
212  * Parallel composition.
213  *
214  * See Parallel(const Generator&, const Generator&, Generator&).
215  * This version fills a composition map to map pairs of old states
216  * to new states.
217  *
218  * @param rGen1
219  * First generator
220  * @param rGen2
221  * Second generator
222  * @param rCompositionMap
223  * Composition map (map< pair<Idx,Idx>, Idx>)
224  * @param rResGen
225  * Reference to resulting parallel composition generator
226  */
227 extern FAUDES_API void Parallel(
228  const Generator& rGen1, const Generator& rGen2,
229  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
230  Generator& rResGen);
231 
232 
233 /**
234  * Parallel composition.
235  *
236  * See also Parallel(const Generator&, const Generator&, Generator&).
237  * This version fills a composition map to map pairs of old states
238  * to new states.
239  *
240  * @param rGen1
241  * First generator
242  * @param rGen2
243  * Second generator
244  * @param rCompositionMap
245  * Composition map
246  * @param rResGen
247  * Reference to resulting composition generator
248  *
249  * @ingroup GeneratorFunctions
250  */
251 extern FAUDES_API void Parallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
252 
253 
254 
255 /**
256  * Parallel composition.
257  *
258  * See Parallel(const Generator&, const Generator&, Generator&).
259  * This version fills a composition map to map pairs of old states
260  * to new states. It also returns the sets of states marked w.r.t. the
261  * argument generators.
262  *
263  * @param rGen1
264  * First generator
265  * @param rGen2
266  * Second generator
267  * @param rCompositionMap
268  * Composition map (map< pair<Idx,Idx>, Idx>)
269  * @param rMark2
270  * States maked in first generator
271  * @param rMark1
272  * States maked in second generator
273  * @param rResGen
274  * Reference to resulting parallel composition generator
275  */
276 extern FAUDES_API void Parallel(
277  const Generator& rGen1, const Generator& rGen2,
278  ProductCompositionMap& rCompositionMap,
279  StateSet& rMark1,
280  StateSet& rMark2,
281  Generator& rResGen);
282 
283 
284 /**
285  * Product composition.
286  *
287  * The product composition executes shared events only. The resulting
288  * generators alphabet is the interscetion of the argument alphabets.
289  * In this implementation, only accessible states are generated.
290  * Assumes deterministic input generators, result is deterministic.
291  *
292  * @param rGen1
293  * First generator
294  * @param rGen2
295  * Second generator
296  * @param rResGen
297  * Reference to resulting product composition generator
298  *
299  * @ingroup GeneratorFunctions
300  */
301 extern FAUDES_API void Product(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
302 
303 
304 /**
305  * Product composition.
306  *
307  * See Product(const Generator&, const Generator&, Generator&).
308  * This version fills given composition map to map pairs of old states
309  * to new states.
310  *
311  * @param rGen1
312  * First generator
313  * @param rGen2
314  * Second generator
315  * @param rCompositionMap
316  * Composition map (map< pair<Idx,Idx>, Idx>)
317  * @param rResGen
318  * Reference to resulting product composition generator
319  */
320 extern FAUDES_API void Product(
321  const Generator& rGen1, const Generator& rGen2,
322  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
323  Generator& rResGen);
324 
325 
326 /**
327  * Product composition.
328  *
329  * See Product(const Generator&, const Generator&, Generator&).
330  * This version fills given composition map to map pairs of old states
331  * to new states. It also returns the sets of states marked w.r.t. the
332  * argument generators.
333  *
334  * @param rGen1
335  * First generator
336  * @param rGen2
337  * Second generator
338  * @param rCompositionMap
339  * Composition map (map< pair<Idx,Idx>, Idx>)
340  * @param rMark2
341  * States maked in first generator
342  * @param rMark1
343  * States maked in second generator
344  * @param rResGen
345  * Reference to resulting product composition generator
346  */
347 extern FAUDES_API void Product(
348  const Generator& rGen1, const Generator& rGen2,
349  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
350  StateSet& rMark1,
351  StateSet& rMark2,
352  Generator& rResGen);
353 
354 
355 /**
356  * Product composition.
357  *
358  * See also Product(const Generator&, const Generator&, Generator&).
359  * This version tries to be transparent on event attributes: if
360  * argument attributes match and if the result can take the respective
361  * attributes, then they are copied; it is considered an error if
362  * argument attributes do not match.
363  *
364  * @param rGen1
365  * First generator
366  * @param rGen2
367  * Second generator
368  * @param rResGen
369  * Reference to resulting product composition generator
370  *
371  * @ingroup GeneratorFunctions
372  */
373 extern FAUDES_API void aProduct(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
374 
375 
376 /**
377  * Product composition.
378  *
379  * See also Product(const Generator&, const Generator&, Generator&).
380  * This version fills a omposition map to map pairs of old states
381  * to new states.
382  *
383  * @param rGen1
384  * First generator
385  * @param rGen2
386  * Second generator
387  * @param rCompositionMap
388  * Composition map
389  * @param rResGen
390  * Reference to resulting composition generator
391  *
392  * @ingroup GeneratorFunctions
393  */
394 extern FAUDES_API void aProduct(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
395 
396 /**
397  * Helper: uses composition map to track state names
398  * in a paralell composition. Purely cosmetic.
399  *
400  * @param rGen1
401  * First generator
402  * @param rGen2
403  * Second generator
404  * @param rCompositionMap
405  * Composition map (map< pair<Idx,Idx>, Idx>)
406  * @param rGen12
407  * Reference to resulting parallel composition generator
408  */
410  const Generator& rGen1, const Generator& rGen2,
411  const std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
412  Generator& rGen12);
413 
414 } // namespace faudes
415 
416 
417 #endif
418 
#define FAUDES_API
Definition: cfl_platform.h:80
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:872
std::map< Idx, Idx > mArg2Map
Definition: cfl_parallel.h:73
std::map< Idx, Idx > mArg1Map
Definition: cfl_parallel.h:72
std::map< std::pair< Idx, Idx >, Idx > mCompositionMap
Definition: cfl_parallel.h:69
void Product(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void aParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void aProduct(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
uint32_t Idx
void SetComposedStateNames(const Generator &rGen1, const Generator &rGen2, const std::map< std::pair< Idx, Idx >, Idx > &rCompositionMap, Generator &rGen12)
void ParallelNB(const GeneratorVector &rGenVec, Generator &rResGen)

libFAUDES 2.33c --- 2025.05.15 --- c++ api documentaion by doxygen