sp_pexecutor.h
Go to the documentation of this file.
1/** @file sp_pexecutor.h Executor for multiple synchronized timed generators */
2
3/*
4 FAU Discrete Event Systems Library (libfaudes)
5
6 Copyright (C) 2007, 2008 Thomas Moor
7 Copyright (C) 2007 Ruediger Berndt
8 Exclusive copyright is granted to Klaus Schmidt
9
10*/
11
12
13
14#ifndef FAUDES_PEXECUTOR_H
15#define FAUDES_PEXECUTOR_H
16
17#include "corefaudes.h"
18#include "tp_include.h"
19#include "sp_executor.h"
20#include "sp_simconditionset.h"
21
22
23namespace faudes {
24
25/**
26 * Synchronized parallel execution of TimedGenerators
27 *
28 * \section SecSimulatorPEX1 Synchronisation
29 *
30 * The ParallelExecutor executes a family of timed generators with synchronized shared
31 * events according to Alur semantics. That is, we assume disjoint clock sets and synchronize
32 * shared events w.r.t. occurence at clock time.
33 *
34 * \section SecSimulatorPEX2 Implementation
35 *
36 * The external interface of a ParallelExecutor is the same as the single Executor, in that
37 * it indicats enabled events and in that it provides methods for executing
38 * events or letting time pass.
39 *
40 * Technically, a ParallelExecutor is a vector of executors. Clocks
41 * are treated on a per executor basis. That is, values of clocks in one generator are
42 * not effected by the reset of another generator, even if the respestive clock variables
43 * have the same index and name.
44 *
45 * \section SecSimulatorPEX3 File IO
46 *
47 * For token IO, the ParallelExecutor reads and writes the generators to execute within a
48 * section with default label "Executor". For disk space efficiency, the token IO
49 * format will use refernces by (relative) filename if the latter is known. Since TimedGenerators
50 * read any generator type from file, so does the ParallelExecutor. Example:
51 *
52 * \code
53 * <Executor>
54 * <Generators>
55 * "./some_generator.gen"
56 * "./other_generator.gen"
57 * </Generators>
58 * </Executor>
59 * \endcode
60 *
61 * @ingroup SimulatorPlugin
62 */
63
65
67
68 public:
69 /** Typedef for parallel discrete state*/
70 typedef std::vector<Idx> ParallelState;
71
72 /** Typedef for parallel clock values */
73 typedef std::vector< std::map<Idx,Time::Type> > ParallelClock;
74
75 /** Typedef for parallel timed state, incl token io */
77 public:
80 protected:
81 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
82 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
83 };
84
85 /** Provide typedef from Executor */
87
88 /**
89 * Construct an emtpy ParallelExecuter
90 */
91 ParallelExecutor(void);
92
93 /**
94 * Copy constructor
95 */
97
98 /**
99 * Construct from file.
100 *
101 * This constructor uses the DoRead method to initialize from file.
102 *
103 * @param rFileName
104 * Filename
105 *
106 * @exception Exception
107 * - non-deteministic generator (id 501)
108 * - token mismatch (id 502)
109 * - IO errors (id 1)
110 */
111 ParallelExecutor(const std::string& rFileName);
112
113
114 /**
115 * Explicit destructor.
116 */
117 virtual ~ParallelExecutor(void);
118
119 /**
120 * Clear all data. Removes all generators/executors and resets the
121 * current state to a void value.
122 *
123 */
124 virtual void Clear(void);
125
126 /**
127 * Number of TimedGenerators
128 *
129 */
130 Idx Size(void) const;
131
132
133 /**
134 * Add a TimedGenerator from file. This method uses the TimedGenerator's read to
135 * find the first generator in the file. If the generator found is not a TimedGenerator,
136 * timing data defaults to infinite invariants/guards and empty resets.
137 * After inserting generators and before starting to execute, you must call Reset() to update
138 * internal datastructures.
139 *
140 * @param rFileName
141 * File to read
142 *
143 * @exception Exception
144 * - non-deteministic generator (id 501)
145 * - token mismatch (id 502)
146 * - IO errors (id 1)
147 */
148 void Insert(const std::string& rFileName);
149
150 /**
151 * Add a TimedGenerator.
152 * After inserting generators and before starting to execute, you must call Reset() to update
153 * internal datastructures.
154 *
155 * @param rGen
156 * Generator to add
157 *
158 * @exception Exception
159 * - non-deteministic generator (id 501)
160 */
161 void Insert(const TimedGenerator& rGen);
162
163 /**
164 * Overall alphabet.
165 *
166 */
167 const EventSet& Alphabet(void) const;
168
169 /**
170 * Goto initial state. Reset all clock values to zero, assign initial states to each executor.
171 */
172 virtual void Reset(void);
173
174
175
176 /**
177 * Read-only access to individual executors.
178 *
179 */
180 typedef std::vector<Executor>::const_iterator Iterator;
181 Iterator Begin(void) const { return mExecutors.begin(); };
182 Iterator End(void) const { return mExecutors.end(); };
183 const Executor& At(int i) const { return mExecutors.at(i); };
184
185
186 /**
187 * Event index lookup.
188 *
189 * This convenience method refers to the global event symbol table.
190 *
191 * @param rName
192 * Name of event to lookup
193 *
194 * @return
195 * Valid index or 0 if non-existent
196 */
197 Idx EventIndex(const std::string& rName) const { return mAlphabet.Index(rName); };
198
199 /**
200 * Event name lookup
201 *
202 * This convenience method refers to the global event symbol table.
203 *
204 * @param index
205 * Index of event to look up
206 *
207 * @return
208 * Name or empty std::string if non-existent
209 */
210 std::string EventName(Idx index) const { return mAlphabet.SymbolicName(index); };
211
212 /**
213 * Get clock time.
214 *
215 */
216 Time::Type CurrentTime(void) const;
217
218 /**
219 * Get logical time, ie number of transitions so far,
220 *
221 */
222 int CurrentStep(void) const;
223
224 /**
225 * Test for deadlocked.
226 *
227 * The parallel executor is deadlocked if neither time can pass nor an event can
228 * be executed. Prototypical examples for such a situation is that the indvidual
229 * executers fail to agree on a common time interval, at which shaered events are
230 * enabled.
231 *
232 * @return True/false
233 */
234 bool IsDeadlocked() const;
235
236 /**
237 * Check validity of executors.
238 *
239 * This is currently not implemented.
240 *
241 * @return
242 * True on success
243 */
244 virtual bool Valid(void) const {return true;};
245
246 /**
247 * Get current state of the ParallelExecutor.
248 *
249 * With "the current state" w refer to all data relevant for
250 * events generated in future. This data consists of a discrete
251 * state vector and a mapping from clocks to closk values.
252 *
253 * @return
254 * Discrete state vector and clock value maps
255 */
256 const ParallelTimedState& CurrentParallelTimedState(void) const;
257
258 /**
259 * Get current discrete state vector of the ParallelExecutor
260 *
261 * By "the current discrete state" we refer to a vector of indices
262 * that indicate the current state of the untimed transition structure.
263 *
264 * @return
265 * Discrete state vector
266 */
267 const ParallelState& CurrentParallelState(void) const;
268
269 /**
270 * Set clock time.
271 * This does not affect clocks and, hence, is purely cosmetic.
272 * The trace buffer will record an invalid event.
273 *
274 * @param time
275 * New clock time
276 */
277 virtual void CurrentTime(Time::Type time);
278
279 /**
280 * Set logical time (# of steps)
281 *
282 * This does not affect clocks and, hence, is purely cosmetic.
283 * Note that, in contrast to clock time, the individual
284 * generators do not agree in logical time.
285 * The trace buffer will get out of order and should be cleared.
286 *
287 * @param step
288 * New logical time
289 */
290 virtual void CurrentStep(int step);
291
292 /**
293 * Set current state of the ParallelExecutor.
294 *
295 * This resets the parallel executor to the given state, incl clock values.
296 * Both, clock time and logical time is also reset (to 0).
297 *
298 * @return
299 * True for success
300 */
301 virtual bool CurrentParallelTimedState(const ParallelTimedState& ptstate);
302
303 /**
304 * Let time pass without executing a transition. Return false if the duration specified
305 * cannot elapse without an event being executed.
306 *
307 * @param duration
308 * Amount of time that shall elapse.
309 * @return
310 * True for success
311 */
312 virtual bool ExecuteTime(Time::Type duration);
313
314 /**
315 * Execute transition.
316 *
317 * Returns false if the transition
318 * cannot be executed at the current time.
319 *
320 * @param event
321 * Indicate transition to execute
322 * @return
323 * True on success
324 */
325 virtual bool ExecuteEvent(Idx event);
326
327 /**
328 * Get maximal duration that can pass without executing an event.
329 *
330 * @return TimeInterval
331 *
332 */
333 const TimeInterval& EnabledTime() const;
334
335 /**
336 * Get events that are enabled at current (timed) state.
337 *
338 * By "enabled" we refer to the synchronizes timed generators,
339 * that is, we do care about clock values, invariants and guards.
340 *
341 *
342 * @return
343 * Set of enabled events
344 */
345 const EventSet& EnabledEvents() const;
346
347 /**
348 * Get events that are disabled at current (timed) state
349 *
350 * By "disabled" we refer to the synchronizes timed generators,
351 * that is, we do care about clock values, invariants and guards.
352 *
353 * @return
354 * Set of disabled events
355 */
356 const EventSet& DisabledEvents() const;
357
358 /**
359 * Get an interval on which the set of enabled events is constant.
360 * Note: while this implementation tries to come up with a potentially large
361 * interval, it is not guaranteed to be maximal.
362 *
363 * @return TimeInterval
364 *
365 */
366 const TimeInterval& EnabledInterval() const;
367
368 /**
369 * Get interval on which the specified event is enabled.
370 *
371 * Returns empty, if the event is not active or never
372 * simultanuosly enabled in all executors.
373 *
374 * @param event
375 *
376 * @return TimeInterval
377 *
378 */
379 TimeInterval EnabledEventTime(Idx event) const;
380
381 /**
382 * Get interval on which the respective guard is satisfied.
383 *
384 * Returns empty, if the event is not active or if the guards
385 * are never simultanuosly satisfied in all executors.
386 *
387 * @param event
388 *
389 * @return TimeInterval
390 *
391 */
392 TimeInterval EnabledGuardTime(Idx event) const;
393
394 /**
395 * Get events that are active in all TimedGenerators.
396 *
397 * By "active" we refer to the untimed transition structure,
398 * that is, we ignore clock values etc.
399 *
400 * @param stateVec
401 * Discrete state
402 * @return
403 * Active EventSet
404 */
405 EventSet ActiveEventSet(const ParallelState& stateVec) const;
406
407 /**
408 * Test whether an event is active in a given discrete state.
409 *
410 * By "active" we refer to the untimed transition structure,
411 * that is, we ignore clock values etc.
412 *
413 * @param ev
414 * Event to test
415 * @param stateVec
416 * ParallelState
417 *
418 * @return
419 * True for active in all generators
420 */
421 bool Active(Idx ev, const ParallelState& stateVec) const;
422
423 /**
424 * Test whether an event is active at current (discrete) state.
425 *
426 * By "active" we refer to the untimed transition structure,
427 * that is, we ignore clock values etc.
428 *
429 * @param ev
430 * Event ro test
431 *
432 * @return
433 * True for active in all generators
434 */
435 bool Active(Idx ev) const;
436
437 /**
438 * Pretty printable string of timed parallel state
439 */
440 std::string PTSStr(const ParallelTimedState& ptstate) const;
441
442 /**
443 * Pretty printable string of parallel state
444 */
445 std::string PSStr(const ParallelState& pstate) const;
446
447 /**
448 * Pretty printable string of timed event
449 */
450 std::string TEStr(const TimedEvent& tevent) const;
451
452 /**
453 * Pretty printable string of clock name
454 */
455 std::string CStr(Idx clock) const;
456
457 /**
458 * Pretty printable string of event
459 */
460 std::string EStr(Idx event) const;
461
462 /**
463 * Pretty printable string of current state
464 */
465 std::string CurrentParallelTimedStateStr(void) const;
466
467 /**
468 * Pretty printable string of parallel state
469 */
470 std::string CurrentParallelStateStr(void) const;
471
472 /** Compute enabled events and enabled interval (fake const) */
473 /** this is public only for performance experiments --- dont use */
474 void ComputeEnabled(void) const;
475
476 /** Compute enabled core routine (non const) */
477 void ComputeEnabledNonConst(void);
478
479
480
481protected:
482
483 /**
484 * Reads parallel executor from TokenReader, see also public wrappers Read() in faudes::Type.
485 *
486 * @param rTr
487 * TokenReader to read from
488 * @param rLabel
489 * Section to read, defaults to "Executor"
490 * @param pContext
491 * Read context to provide contextual information (ignored)
492 *
493 * @exception Exception
494 * - non-deterministic generator(s) (id 501)
495 * - token mismatch (id 502)
496 * - IO error (id 1)
497 */
498 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
499
500 /**
501 * Write to TokenWriter, see also public wrappers Write() in faudes::Type.
502 *
503 * @param rTw
504 * Reference to TokenWriter
505 * @param rLabel
506 * Label of section to write, defaults to "Executor"
507 * @param pContext
508 * Write context to provide contextual information (ignored)
509 *
510 * @exception Exception
511 * - IO errors (id 2)
512 */
513 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
514
515
516 /**
517 * Reads generator files section from TokenReader
518 *
519 * @param rTr
520 * TokenReader to read from
521 *
522 * @exception Exception
523 * - non-deterministic generator(s) (id 501)
524 * - token mismatch (id 502)
525 * - IO error (id 1)
526 */
527 virtual void DoReadGenerators(TokenReader& rTr);
528
529 /**
530 * Write generator files section to TokenWriter
531 *
532 * @param rTw
533 * Reference to TokenWriter
534 *
535 * @exception Exception
536 * - IO errors (id 2)
537 */
538 virtual void DoWriteGenerators(TokenWriter& rTw) const;
539
540
541 /**
542 * Assignment method
543 *
544 * @param rSrc
545 * Source to assign from
546 */
547 void DoAssign(const ParallelExecutor& rSrc);
548
549 /** compile internal data (eg overall alphabet) */
550 virtual void Compile();
551
552 /** recent event */
554
555private:
556
557 /** list of executors */
558 std::vector<Executor> mExecutors;
559
560 /** list of executors */
561 std::vector<std::string> mExecutorNames;
562
563 /** Internal non-const iterator */
564 typedef std::vector<Executor>::iterator iterator;
565
566 /** overall alphabet */
568
569 /** global time (real) */
571
572 /** global time (step)*/
574
575 /** enabled time */
577
578 /** enabled events */
580
581 /** disabled events */
583
584 /** enabled interval */
586
587 /** validity flag for fevents and ftime */
589
590 /** current state */
592
593 /** update parallel timed state() */
594 void UpdateParallelTimedState(void);
595
596
597
598
599}; // end class ParallelExecutor
600
601
602
603} // namespace faudes
604
605
606#endif
607
#define FAUDES_API
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:879
virtual bool Valid(void) const
std::vector< Executor >::iterator iterator
std::vector< std::map< Idx, Time::Type > > ParallelClock
Idx EventIndex(const std::string &rName) const
std::vector< Executor >::const_iterator Iterator
ParallelTimedState mCurrentParallelTimedState
std::vector< Idx > ParallelState
Iterator Begin(void) const
const Executor & At(int i) const
std::vector< Executor > mExecutors
std::vector< std::string > mExecutorNames
Iterator End(void) const
std::string EventName(Idx index) const
Executor::TimedState TimedState
uint32_t Idx

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen