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  // std faudes type
49  virtual ~ProductCompositionMap(void);
50  virtual void Clear(void);
51  // access C++/STL data
52  const std::map< std::pair<Idx,Idx> , Idx >& StlMap(void) const;
53  std::map< std::pair<Idx,Idx> , Idx >& StlMap(void);
54  void StlMap(const std::map< std::pair<Idx,Idx> , Idx >& rMap);
55  // translate states (return 0 on out-of-range)
56  Idx CompState(Idx s1, Idx s2) const;
57  Idx Arg1State(Idx s12) const;
58  Idx Arg2State(Idx s12) const;
59 protected:
60  // std faudes type
61  void DoAssign(const ProductCompositionMap& rSrc);
62  bool DoEqual(const ProductCompositionMap& rOther) const;
63  // my data (primary)
64  std::map< std::pair<Idx,Idx> , Idx > mCompositionMap;
65  // my data (derived)
66  mutable bool mCompiled;
67  mutable std::map<Idx,Idx> mArg1Map;
68  mutable std::map<Idx,Idx> mArg2Map;
69 };
70 
71 
72 
73 /**
74  * Parallel composition.
75  *
76  * Constructs the parallel composition of two generators, where shared events
77  * are synchronised while non-shared events are executed independantly.
78  * The resulting generators alphabet is the union of the argument alphabets.
79  * In this implementation, only accessible states are generated.
80  * On deterministic input this functions constructs a deterministic output.
81  * See also Parallel(const Generator&,std::map< std::pair<Idx,Idx>, Idx>&,const Generator&, Generator&).
82  *
83  * @param rGen1
84  * First generator
85  * @param rGen2
86  * Second generator
87  * @param rResGen
88  * Reference to resulting parallel composition generator
89  *
90  * <h4>Example:</h4>
91  * <table border=0> <tr> <td> <table>
92  * <tr> <td> Generator G1 </td> <td> Generator G2 </td> </tr>
93  * <tr>
94  * <td> @image html tmp_parallel_g1.png </td>
95  * <td> @image html tmp_parallel_g2.png </td>
96  * </tr>
97  * </table> </td> </tr> <tr> <td> <table width=100%>
98  * <tr> <td> G1 || G2 </td> </tr>
99  * <tr> <td> @image html tmp_parallel_g1g2.png </td> </tr>
100  * </table> </td> </tr> </table>
101  *
102  * @ingroup GeneratorFunctions
103  *
104  */
105 extern FAUDES_API void Parallel(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
106 
107 
108 /**
109  * Parallel composition.
110  *
111  * See also Parallel(const Generator&, const Generator&, Generator&).
112  * This version tries to be transparent on event attributes: if
113  * argument attributes match and if the result can take the respective
114  * attributes, then they are copied; it is considered an error if
115  * argument attributes do not match.
116  *
117  * @param rGen1
118  * First generator
119  * @param rGen2
120  * Second generator
121  * @param rResGen
122  * Reference to resulting composition generator
123  *
124  * @ingroup GeneratorFunctions
125  */
126 extern FAUDES_API void aParallel(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
127 
128 /**
129  * Parallel composition.
130  *
131  * See also aParallel(const Generator&, const Generator&, Generator&).
132  * This version takes a vector of generators as argument to perform
133  * a synchronous composition of multiple generators. The implementation
134  * calls the std aParallel multiple times, future implementations may
135  * explore the overall reachable state set.
136  *
137  * @param rGenVec
138  * Vector of input generators
139  * @param rResGen
140  * Reference to resulting composition generator
141  *
142  */
143 extern FAUDES_API void aParallel(const GeneratorVector& rGenVec, Generator& rResGen);
144 
145 
146 
147 /**
148  * Parallel composition.
149  *
150  * See also Parallel(const Generator&, const Generator&, Generator&).
151  * This version fills a composition map to map pairs of old states
152  * to new states.
153  *
154  * @param rGen1
155  * First generator
156  * @param rGen2
157  * Second generator
158  * @param rCompositionMap
159  * Composition map
160  * @param rResGen
161  * Reference to resulting composition generator
162  *
163  * @ingroup GeneratorFunctions
164  */
165 extern FAUDES_API void aParallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
166 
167 
168 
169 
170 /**
171  * Parallel composition.
172  *
173  * See Parallel(const Generator&, const Generator&, Generator&).
174  * This version fills a composition map to map pairs of old states
175  * to new states.
176  *
177  * @param rGen1
178  * First generator
179  * @param rGen2
180  * Second generator
181  * @param rCompositionMap
182  * Composition map (map< pair<Idx,Idx>, Idx>)
183  * @param rResGen
184  * Reference to resulting parallel composition generator
185  */
186 extern FAUDES_API void Parallel(
187  const Generator& rGen1, const Generator& rGen2,
188  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
189  Generator& rResGen);
190 
191 
192 /**
193  * Parallel composition.
194  *
195  * See also Parallel(const Generator&, const Generator&, Generator&).
196  * This version fills a composition map to map pairs of old states
197  * to new states.
198  *
199  * @param rGen1
200  * First generator
201  * @param rGen2
202  * Second generator
203  * @param rCompositionMap
204  * Composition map
205  * @param rResGen
206  * Reference to resulting composition generator
207  *
208  * @ingroup GeneratorFunctions
209  */
210 extern FAUDES_API void Parallel(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
211 
212 
213 
214 /**
215  * Parallel composition.
216  *
217  * See Parallel(const Generator&, const Generator&, Generator&).
218  * This version fills a composition map to map pairs of old states
219  * to new states. It also returns the sets of states marked w.r.t. the
220  * argument generators.
221  *
222  * @param rGen1
223  * First generator
224  * @param rGen2
225  * Second generator
226  * @param rCompositionMap
227  * Composition map (map< pair<Idx,Idx>, Idx>)
228  * @param rMark2
229  * States maked in first generator
230  * @param rMark1
231  * States maked in second generator
232  * @param rResGen
233  * Reference to resulting parallel composition generator
234  */
235 extern FAUDES_API void Parallel(
236  const Generator& rGen1, const Generator& rGen2,
237  ProductCompositionMap& rCompositionMap,
238  StateSet& rMark1,
239  StateSet& rMark2,
240  Generator& rResGen);
241 
242 
243 /**
244  * Product composition.
245  *
246  * The product composition executes shared events only. The resulting
247  * generators alphabet is the interscetion of the argument alphabets.
248  * In this implementation, only accessible states are generated.
249  * Assumes deterministic input generators, result is deterministic.
250  *
251  * @param rGen1
252  * First generator
253  * @param rGen2
254  * Second generator
255  * @param rResGen
256  * Reference to resulting product composition generator
257  *
258  * @ingroup GeneratorFunctions
259  */
260 extern FAUDES_API void Product(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
261 
262 
263 /**
264  * Product composition.
265  *
266  * See Product(const Generator&, const Generator&, Generator&).
267  * This version fills given composition map to map pairs of old states
268  * to new states.
269  *
270  * @param rGen1
271  * First generator
272  * @param rGen2
273  * Second generator
274  * @param rCompositionMap
275  * Composition map (map< pair<Idx,Idx>, Idx>)
276  * @param rResGen
277  * Reference to resulting product composition generator
278  */
279 extern FAUDES_API void Product(
280  const Generator& rGen1, const Generator& rGen2,
281  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
282  Generator& rResGen);
283 
284 
285 /**
286  * Product composition.
287  *
288  * See Product(const Generator&, const Generator&, Generator&).
289  * This version fills given composition map to map pairs of old states
290  * to new states. It also returns the sets of states marked w.r.t. the
291  * argument generators.
292  *
293  * @param rGen1
294  * First generator
295  * @param rGen2
296  * Second generator
297  * @param rCompositionMap
298  * Composition map (map< pair<Idx,Idx>, Idx>)
299  * @param rMark2
300  * States maked in first generator
301  * @param rMark1
302  * States maked in second generator
303  * @param rResGen
304  * Reference to resulting product composition generator
305  */
306 extern FAUDES_API void Product(
307  const Generator& rGen1, const Generator& rGen2,
308  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
309  StateSet& rMark1,
310  StateSet& rMark2,
311  Generator& rResGen);
312 
313 
314 /**
315  * Product composition.
316  *
317  * See also Product(const Generator&, const Generator&, Generator&).
318  * This version tries to be transparent on event attributes: if
319  * argument attributes match and if the result can take the respective
320  * attributes, then they are copied; it is considered an error if
321  * argument attributes do not match.
322  *
323  * @param rGen1
324  * First generator
325  * @param rGen2
326  * Second generator
327  * @param rResGen
328  * Reference to resulting product composition generator
329  *
330  * @ingroup GeneratorFunctions
331  */
332 extern FAUDES_API void aProduct(const Generator& rGen1, const Generator& rGen2, Generator& rResGen);
333 
334 
335 /**
336  * Product composition.
337  *
338  * See also Product(const Generator&, const Generator&, Generator&).
339  * This version fills a omposition map to map pairs of old states
340  * to new states.
341  *
342  * @param rGen1
343  * First generator
344  * @param rGen2
345  * Second generator
346  * @param rCompositionMap
347  * Composition map
348  * @param rResGen
349  * Reference to resulting composition generator
350  *
351  * @ingroup GeneratorFunctions
352  */
353 extern FAUDES_API void aProduct(const Generator& rGen1, const Generator& rGen2, ProductCompositionMap& rCompositionMap, Generator& rResGen);
354 
355 /**
356  * Helper: uses composition map to track state names
357  * in a paralell composition. Purely cosmetic.
358  *
359  * @param rGen1
360  * First generator
361  * @param rGen2
362  * Second generator
363  * @param rCompositionMap
364  * Composition map (map< pair<Idx,Idx>, Idx>)
365  * @param rGen12
366  * Reference to resulting parallel composition generator
367  */
369  const Generator& rGen1, const Generator& rGen2,
370  const std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
371  Generator& rGen12);
372 
373 } // namespace faudes
374 
375 
376 #endif
377 
Attributed generator class TaGenerator.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:81
#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:68
std::map< Idx, Idx > mArg1Map
Definition: cfl_parallel.h:67
std::map< std::pair< Idx, Idx >, Idx > mCompositionMap
Definition: cfl_parallel.h:64
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.32b --- 2024.03.01 --- c++ api documentaion by doxygen