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  * Constructs the parallel composition of two generators, where shared events
117  * are synchronised while non-shared events are executed independantly.
118  * The resulting generators alphabet is the union of the argument alphabets.
119  *
120  * This variant stops to explore the accessible region when attained a non-conaccessible
121  * state. Thus, the result is accurate for the marked languages only.
122  * See also Parallel(const Generator&,std::map< std::pair<Idx,Idx>, Idx>&,const Generator&, Generator&).
123  *
124  * @param rGen1
125  * First generator
126  * @param rGen2
127  * Second generator
128  * @param rResGen
129  * Reference to resulting parallel composition generator
130  *
131  * <h4>Example:</h4>
132  * <table border=0> <tr> <td> <table>
133  * <tr> <td> Generator G1 </td> <td> Generator G2 </td> </tr>
134  * <tr>
135  * <td> @image html tmp_parallel_g1.png </td>
136  * <td> @image html tmp_parallel_g2.png </td>
137  * </tr>
138  * </table> </td> </tr> <tr> <td> <table width=100%>
139  * <tr> <td> G1 || G2 </td> </tr>
140  * <tr> <td> @image html tmp_parallel_g1g2.png </td> </tr>
141  * </table> </td> </tr> </table>
142  *
143  * @ingroup GeneratorFunctions
144  *
145  */
146 extern FAUDES_API void ParallelLive(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
147 
148 /**
149  * Parallel composition.
150  *
151  * See also Parallel(const Generator&, const Generator&, Generator&).
152  * This version takes a vector of generators as argument to perform
153  * a synchronous composition of multiple generators. The implementation
154  * calls the std Parallel multiple times, future implementations may
155  * explore the overall reachable state set.
156  *
157  * @param rGenVec
158  * Vector of input generators
159  * @param rResGen
160  * Reference to resulting composition generator
161  *
162  */
163 extern FAUDES_API void Parallel(const GeneratorVector& rGenVec, Generator& rResGen);
164 
165 
166 /**
167  * Parallel composition, non-blocking part.
168  *
169  * See also Parallel(const Generator&, const Generator&, Generator&).
170  * This version takes a vector of generators as argument to perform
171  * a synchronous composition of multiple generators. The implementation
172  * calls the std Parallel multiple times, and, at each stage, removes outgoing transitions
173  * from blocking states. Thus, the result will be accurate for non-blocking part only.
174  *
175  * @param rGenVec
176  * Vector of input generators
177  * @param rResGen
178  * Reference to resulting composition generator
179  *
180  */
181 extern FAUDES_API void ParallelLive(const GeneratorVector& rGenVec, Generator& rResGen);
182 
183 
184 /**
185  * Parallel composition.
186  *
187  * See also Parallel(const Generator&, const Generator&, Generator&).
188  * This version tries to be transparent on event attributes: if
189  * argument attributes match and if the result can take the respective
190  * attributes, then they are copied; it is considered an error if
191  * argument attributes do not match.
192  *
193  * @param rGen1
194  * First generator
195  * @param rGen2
196  * Second generator
197  * @param rResGen
198  * Reference to resulting composition generator
199  *
200  * @ingroup GeneratorFunctions
201  */
202 extern FAUDES_API void aParallel(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
203 
204 /**
205  * Parallel composition.
206  *
207  * See also aParallel(const Generator&, const Generator&, Generator&).
208  * This version takes a vector of generators as argument to perform
209  * a synchronous composition of multiple generators. The implementation
210  * calls the std aParallel multiple times, future implementations may
211  * explore the overall reachable state set.
212  *
213  * @param rGenVec
214  * Vector of input generators
215  * @param rResGen
216  * Reference to resulting composition generator
217  *
218  */
219 extern FAUDES_API void aParallel(const GeneratorVector& rGenVec, Generator& rResGen);
220 
221 
222 
223 /**
224  * Parallel composition.
225  *
226  * See also Parallel(const Generator&, const Generator&, Generator&).
227  * This version fills a composition map to map pairs of old states
228  * to new states.
229  *
230  * @param rGen1
231  * First generator
232  * @param rGen2
233  * Second generator
234  * @param rCompositionMap
235  * Composition map
236  * @param rResGen
237  * Reference to resulting composition generator
238  *
239  * @ingroup GeneratorFunctions
240  */
241 extern FAUDES_API void aParallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
242 
243 
244 
245 
246 /**
247  * Parallel composition.
248  *
249  * See Parallel(const Generator&, const Generator&, Generator&).
250  * This version fills a composition map to map pairs of old states
251  * to new states.
252  *
253  * @param rGen1
254  * First generator
255  * @param rGen2
256  * Second generator
257  * @param rCompositionMap
258  * Composition map (map< pair<Idx,Idx>, Idx>)
259  * @param rResGen
260  * Reference to resulting parallel composition generator
261  */
262 extern FAUDES_API void Parallel(
263  const Generator& rGen1, const Generator& rGen2,
264  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
265  Generator& rResGen, bool live_only=false);
266 
267 
268 /**
269  * Parallel composition.
270  *
271  * See also Parallel(const Generator&, const Generator&, Generator&).
272  * This version fills a composition map to map pairs of old states
273  * to new states.
274  *
275  * @param rGen1
276  * First generator
277  * @param rGen2
278  * Second generator
279  * @param rCompositionMap
280  * Composition map
281  * @param rResGen
282  * Reference to resulting composition generator
283  *
284  * @ingroup GeneratorFunctions
285  */
286 extern FAUDES_API void Parallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
287 
288 
289 
290 /**
291  * Parallel composition.
292  *
293  * See Parallel(const Generator&, const Generator&, Generator&).
294  * This version fills a composition map to map pairs of old states
295  * to new states. It also returns the sets of states marked w.r.t. the
296  * argument generators.
297  *
298  * @param rGen1
299  * First generator
300  * @param rGen2
301  * Second generator
302  * @param rCompositionMap
303  * Composition map (map< pair<Idx,Idx>, Idx>)
304  * @param rMark2
305  * States maked in first generator
306  * @param rMark1
307  * States maked in second generator
308  * @param rResGen
309  * Reference to resulting parallel composition generator
310  */
311 extern FAUDES_API void Parallel(
312  const Generator& rGen1, const Generator& rGen2,
313  ProductCompositionMap& rCompositionMap,
314  StateSet& rMark1,
315  StateSet& rMark2,
316  Generator& rResGen);
317 
318 
319 /**
320  * Product composition.
321  *
322  * The product composition executes shared events only. The resulting
323  * generators alphabet is the interscetion of the argument alphabets.
324  * In this implementation, only accessible states are generated.
325  * Assumes deterministic input generators, result is deterministic.
326  *
327  * @param rGen1
328  * First generator
329  * @param rGen2
330  * Second generator
331  * @param rResGen
332  * Reference to resulting product composition generator
333  *
334  * @ingroup GeneratorFunctions
335  */
336 extern FAUDES_API void Product(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
337 
338 
339 /**
340  * Product composition.
341  *
342  * See Product(const Generator&, const Generator&, Generator&).
343  * This version fills given composition map to map pairs of old states
344  * to new states.
345  *
346  * @param rGen1
347  * First generator
348  * @param rGen2
349  * Second generator
350  * @param rCompositionMap
351  * Composition map (map< pair<Idx,Idx>, Idx>)
352  * @param rResGen
353  * Reference to resulting product composition generator
354  */
355 extern FAUDES_API void Product(
356  const Generator& rGen1, const Generator& rGen2,
357  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
358  Generator& rResGen);
359 
360 
361 /**
362  * Product composition.
363  *
364  * See Product(const Generator&, const Generator&, Generator&).
365  * This version fills given composition map to map pairs of old states
366  * to new states. It also returns the sets of states marked w.r.t. the
367  * argument generators.
368  *
369  * @param rGen1
370  * First generator
371  * @param rGen2
372  * Second generator
373  * @param rCompositionMap
374  * Composition map (map< pair<Idx,Idx>, Idx>)
375  * @param rMark2
376  * States maked in first generator
377  * @param rMark1
378  * States maked in second generator
379  * @param rResGen
380  * Reference to resulting product composition generator
381  */
382 extern FAUDES_API void Product(
383  const Generator& rGen1, const Generator& rGen2,
384  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
385  StateSet& rMark1,
386  StateSet& rMark2,
387  Generator& rResGen);
388 
389 
390 /**
391  * Product composition.
392  *
393  * See also Product(const Generator&, const Generator&, Generator&).
394  * This version tries to be transparent on event attributes: if
395  * argument attributes match and if the result can take the respective
396  * attributes, then they are copied; it is considered an error if
397  * argument attributes do not match.
398  *
399  * @param rGen1
400  * First generator
401  * @param rGen2
402  * Second generator
403  * @param rResGen
404  * Reference to resulting product composition generator
405  *
406  * @ingroup GeneratorFunctions
407  */
408 extern FAUDES_API void aProduct(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
409 
410 
411 /**
412  * Product composition.
413  *
414  * See also Product(const Generator&, const Generator&, Generator&).
415  * This version fills a omposition map to map pairs of old states
416  * to new states.
417  *
418  * @param rGen1
419  * First generator
420  * @param rGen2
421  * Second generator
422  * @param rCompositionMap
423  * Composition map
424  * @param rResGen
425  * Reference to resulting composition generator
426  *
427  * @ingroup GeneratorFunctions
428  */
429 extern FAUDES_API void aProduct(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
430 
431 /**
432  * Helper: uses composition map to track state names
433  * in a paralell composition. Purely cosmetic.
434  *
435  * @param rGen1
436  * First generator
437  * @param rGen2
438  * Second generator
439  * @param rCompositionMap
440  * Composition map (map< pair<Idx,Idx>, Idx>)
441  * @param rGen12
442  * Reference to resulting parallel composition generator
443  */
445  const Generator& rGen1, const Generator& rGen2,
446  const std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
447  Generator& rGen12);
448 
449 } // namespace faudes
450 
451 
452 #endif
453 
#define FAUDES_API
Definition: cfl_platform.h:80
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:880
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 ParallelLive(const GeneratorVector &rGenVec, Generator &rResGen)

libFAUDES 2.33h --- 2025.06.18 --- c++ api documentaion by doxygen