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 tries to be transparent on event attributes: if
118  * argument attributes match and if the result can take the respective
119  * attributes, then they are copied; it is considered an error if
120  * argument attributes do not match.
121  *
122  * @param rGen1
123  * First generator
124  * @param rGen2
125  * Second generator
126  * @param rResGen
127  * Reference to resulting composition generator
128  *
129  * @ingroup GeneratorFunctions
130  */
131 extern FAUDES_API void aParallel(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
132 
133 /**
134  * Parallel composition.
135  *
136  * See also aParallel(const Generator&, const Generator&, Generator&).
137  * This version takes a vector of generators as argument to perform
138  * a synchronous composition of multiple generators. The implementation
139  * calls the std aParallel multiple times, future implementations may
140  * explore the overall reachable state set.
141  *
142  * @param rGenVec
143  * Vector of input generators
144  * @param rResGen
145  * Reference to resulting composition generator
146  *
147  */
148 extern FAUDES_API void aParallel(const GeneratorVector& rGenVec, Generator& rResGen);
149 
150 
151 
152 /**
153  * Parallel composition.
154  *
155  * See also Parallel(const Generator&, const Generator&, Generator&).
156  * This version fills a composition map to map pairs of old states
157  * to new states.
158  *
159  * @param rGen1
160  * First generator
161  * @param rGen2
162  * Second generator
163  * @param rCompositionMap
164  * Composition map
165  * @param rResGen
166  * Reference to resulting composition generator
167  *
168  * @ingroup GeneratorFunctions
169  */
170 extern FAUDES_API void aParallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
171 
172 
173 
174 
175 /**
176  * Parallel composition.
177  *
178  * See Parallel(const Generator&, const Generator&, Generator&).
179  * This version fills a composition map to map pairs of old states
180  * to new states.
181  *
182  * @param rGen1
183  * First generator
184  * @param rGen2
185  * Second generator
186  * @param rCompositionMap
187  * Composition map (map< pair<Idx,Idx>, Idx>)
188  * @param rResGen
189  * Reference to resulting parallel composition generator
190  */
191 extern FAUDES_API void Parallel(
192  const Generator& rGen1, const Generator& rGen2,
193  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
194  Generator& rResGen);
195 
196 
197 /**
198  * Parallel composition.
199  *
200  * See also Parallel(const Generator&, const Generator&, Generator&).
201  * This version fills a composition map to map pairs of old states
202  * to new states.
203  *
204  * @param rGen1
205  * First generator
206  * @param rGen2
207  * Second generator
208  * @param rCompositionMap
209  * Composition map
210  * @param rResGen
211  * Reference to resulting composition generator
212  *
213  * @ingroup GeneratorFunctions
214  */
215 extern FAUDES_API void Parallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
216 
217 
218 
219 /**
220  * Parallel composition.
221  *
222  * See Parallel(const Generator&, const Generator&, Generator&).
223  * This version fills a composition map to map pairs of old states
224  * to new states. It also returns the sets of states marked w.r.t. the
225  * argument generators.
226  *
227  * @param rGen1
228  * First generator
229  * @param rGen2
230  * Second generator
231  * @param rCompositionMap
232  * Composition map (map< pair<Idx,Idx>, Idx>)
233  * @param rMark2
234  * States maked in first generator
235  * @param rMark1
236  * States maked in second generator
237  * @param rResGen
238  * Reference to resulting parallel composition generator
239  */
240 extern FAUDES_API void Parallel(
241  const Generator& rGen1, const Generator& rGen2,
242  ProductCompositionMap& rCompositionMap,
243  StateSet& rMark1,
244  StateSet& rMark2,
245  Generator& rResGen);
246 
247 
248 /**
249  * Product composition.
250  *
251  * The product composition executes shared events only. The resulting
252  * generators alphabet is the interscetion of the argument alphabets.
253  * In this implementation, only accessible states are generated.
254  * Assumes deterministic input generators, result is deterministic.
255  *
256  * @param rGen1
257  * First generator
258  * @param rGen2
259  * Second generator
260  * @param rResGen
261  * Reference to resulting product composition generator
262  *
263  * @ingroup GeneratorFunctions
264  */
265 extern FAUDES_API void Product(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
266 
267 
268 /**
269  * Product composition.
270  *
271  * See Product(const Generator&, const Generator&, Generator&).
272  * This version fills given 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 (map< pair<Idx,Idx>, Idx>)
281  * @param rResGen
282  * Reference to resulting product composition generator
283  */
284 extern FAUDES_API void Product(
285  const Generator& rGen1, const Generator& rGen2,
286  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
287  Generator& rResGen);
288 
289 
290 /**
291  * Product composition.
292  *
293  * See Product(const Generator&, const Generator&, Generator&).
294  * This version fills given 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 product composition generator
310  */
311 extern FAUDES_API void Product(
312  const Generator& rGen1, const Generator& rGen2,
313  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
314  StateSet& rMark1,
315  StateSet& rMark2,
316  Generator& rResGen);
317 
318 
319 /**
320  * Product composition.
321  *
322  * See also Product(const Generator&, const Generator&, Generator&).
323  * This version tries to be transparent on event attributes: if
324  * argument attributes match and if the result can take the respective
325  * attributes, then they are copied; it is considered an error if
326  * argument attributes do not match.
327  *
328  * @param rGen1
329  * First generator
330  * @param rGen2
331  * Second generator
332  * @param rResGen
333  * Reference to resulting product composition generator
334  *
335  * @ingroup GeneratorFunctions
336  */
337 extern FAUDES_API void aProduct(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
338 
339 
340 /**
341  * Product composition.
342  *
343  * See also Product(const Generator&, const Generator&, Generator&).
344  * This version fills a omposition map to map pairs of old states
345  * to new states.
346  *
347  * @param rGen1
348  * First generator
349  * @param rGen2
350  * Second generator
351  * @param rCompositionMap
352  * Composition map
353  * @param rResGen
354  * Reference to resulting composition generator
355  *
356  * @ingroup GeneratorFunctions
357  */
358 extern FAUDES_API void aProduct(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
359 
360 /**
361  * Helper: uses composition map to track state names
362  * in a paralell composition. Purely cosmetic.
363  *
364  * @param rGen1
365  * First generator
366  * @param rGen2
367  * Second generator
368  * @param rCompositionMap
369  * Composition map (map< pair<Idx,Idx>, Idx>)
370  * @param rGen12
371  * Reference to resulting parallel composition generator
372  */
374  const Generator& rGen1, const Generator& rGen2,
375  const std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
376  Generator& rGen12);
377 
378 } // namespace faudes
379 
380 
381 #endif
382 
Attributed generator class TaGenerator.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:80
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
faudes type declaration macro
Definition: cfl_types.h:867
Set of indices.
Definition: cfl_indexset.h:78
Rti-wrapper for composition maps.
Definition: cfl_parallel.h:43
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
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
Base class of all FAUDES generators.
void Product(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Product composition.
void aParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
void aProduct(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Product composition.
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
void SetComposedStateNames(const Generator &rGen1, const Generator &rGen2, const std::map< std::pair< Idx, Idx >, Idx > &rCompositionMap, Generator &rGen12)
Helper: uses composition map to track state names in a paralell composition.

libFAUDES 2.32f --- 2024.12.22 --- c++ api documentaion by doxygen