sp_executor.h
Go to the documentation of this file.
1/** @file sp_executor.h Execute transitions in a timed generator */
2
3
4/*
5 FAU Discrete Event Systems Library (libfaudes)
6
7 Copyright (C) 2007 Ruediger Berndt
8 Copyright (C) 2007 Thomas Moor
9 Exclusive copyright is granted to Klaus Schmidt
10
11
12*/
13
14
15
16#ifndef FAUDES_SP_EXECUTOR_H
17#define FAUDES_SP_EXECUTOR_H
18
19#include "corefaudes.h"
20#include "tp_include.h"
21
22
23// debugging: executor level
24#ifdef FAUDES_DEBUG_EXECUTOR
25#define FD_DX(message) FAUDES_WRITE_CONSOLE("FAUDES_EXECUTOR: " << message)
26#else
27#define FD_DX(message)
28#endif
29
30// debugging: proposing executor level
31#ifdef FAUDES_DEBUG_SIMULATOR
32#define FD_DS(message) FAUDES_WRITE_CONSOLE("FAUDES_SIMULATOR: " << message)
33#else
34#define FD_DS(message)
35#endif
36
37// debugging: device synchronization level
38#ifdef FAUDES_DEBUG_SIMULATOR_SYNC
39#define FD_DS_SYNC(message) FAUDES_WRITE_CONSOLE("FAUDES_RUNSYNC: " << message)
40#else
41#define FD_DS_SYNC(message)
42#endif
43
44
45
46namespace faudes {
47
48
49/** Global Tyoedefs */
50
51
52/** typedef for external trace */
58
59/**
60 * An Executor is a timed generator that maintains a current state.
61 *
62 * The Executor is the lowest level building block for the libFAUDES simulator plugin.
63 * It maintains a current state that consists of
64 * - the discrete state;
65 * - a value map that assigns values to clock variables;
66 * - the current step aka logical time;
67 * - the current global clock aka clock time; as with faudes timed automata,
68 * clock time is in faudes-time units which may be mapped to physical time by a fixed
69 * conversion factor; see also DeviceExecutor.
70 * The state can be retrieved by the method Executor::CurrentState(void),
71 * and it is updated whenever time or transitions are executed via Executor::ExecuteTime(Time::Type)
72 * or Executor::ExecuteEvent(Idx). If you plan to execute multiple generators with synchronized shared
73 * events, you will find the class ParallelExecutor with a very similar interface more appropriate.
74 *
75 * The Executor provides Methods that indicate which transitions currently are enabled, referring to the
76 * current state, the current clock values and the guard and invariant data from the TimedGenerator.
77 * In contrast to enabled events, there is also the notion of active events, which refers to
78 * the discrete state only, ignoring guards and invariants.
79 *
80 * Technically, the Executor class is derived from the TimedGenerator, however inheritence is private.
81 * The common way to initialise an Executor object is to construct it from a const ref to a TimedGenerator,
82 * which sets up additional internal data structures. Read-only access to the underlying generator
83 * is given by the faudes::Executor::Generator() method.
84 *
85 * Note: a prequisit of the current implementation is that the underlying generator
86 * is deterministic ie the current discrete state is uniquely determind by the external
87 * sequence of discrete events.
88 *
89 *
90 * @ingroup SimulatorPlugin
91 */
92
94
96
97 public:
98
99
100 /** Typedef for timed state */
101 typedef struct {
102 Idx State; // discrete state
103 std::map<Idx,Time::Type> ClockValue; // map clockindex to value
104 } TimedState;
105
106
107 /**
108 * Creates an emtpy Executer
109 */
110 Executor(void);
111
112 /**
113 * Copy construct
114 */
115 Executor(const Executor& rOther);
116
117 /**
118 * Construct from tgenerator.
119 *
120 * Construction from a TimedGenerator will copy all given TimedGenerator data and complie it to
121 * some additional Executor specific data. Thus, if the original TimedGenerator changes
122 * the Executor will not reflect these changes.
123 *
124 * @param rGen
125 * Input generator
126 *
127 * @exception Exception
128 * - Nondetrministic input generator (id 501)
129 */
130 Executor(const TimedGenerator& rGen);
131
132 /**
133 * Construct from TimedGenerator file.
134 *
135 * @param rFileName
136 * File to read
137 *
138 * @exception Exception
139 * - IO errors (id 1)
140 * - token mismatch (id 50, 51, 52, 80, 85)
141 * - nondetrministic generator (id 501)
142 */
143 Executor(const std::string& rFileName);
144
145 /**
146 * Initialise from TimedGenerator.
147 *
148 * @param rGen
149 * Input generator
150 */
151 void Generator(const TimedGenerator& rGen);
152
153
154 /**
155 * Reference to the internal generator for inspection
156 *
157 * @return
158 * const reference of mTGen
159 */
160 const TimedGenerator& Generator(void) const;
161
162 /**
163 * Generator name (for convenience)
164 *
165 */
166 const std::string& Name(void) const {return TimedGenerator::Name();} ;
167
168 /**
169 * State name (for convenience)
170 *
171 */
172 std::string StateName(Idx idx) const {return TimedGenerator::StateName(idx);} ;
173
174
175 /**
176 * Event name (for convenience)
177 *
178 */
179 std::string EventName(Idx idx) const {return TimedGenerator::EventName(idx);} ;
180
181
182 /**
183 * Clear all data incl TimedGenerator
184 *
185 */
186 void Clear(void);
187
188
189 /**
190 * Reset all clocks and assign initial state.
191 */
192 void Reset();
193
194 /**
195 * Get maximal interval of time that can pass without executing an event.
196 * This corresponds to the inveriant of the current timed state.
197 *
198 * @return TimeInterval
199 *
200 */
201 const TimeInterval& EnabledTime() const;
202
203 /**
204 * Get set of events that are enabled at current (timed) state
205 *
206 * @return
207 * Set of enabled events
208 */
209 const EventSet& EnabledEvents() const;
210
211 /**
212 * Get set of events that are disabled at current (timed) state
213 *
214 * @return
215 * Set of disabled events
216 */
217 const EventSet& DisabledEvents() const;
218
219 /**
220 * Get maximal interval on which set of enabled events is constant
221 *
222 * @return TimeInterval
223 *
224 */
225 const TimeInterval& EnabledInterval() const;
226
227
228 /**
229 * Get interval on which an active event is enabled.
230 *
231 * @param event
232 * Active event
233 *
234 * @return TimeInterval
235 * (empty if event not active or active with guard violated)
236 *
237 */
238 TimeInterval EnabledEventTime(Idx event) const;
239
240
241 /**
242 * Get interval on which an active event satisfies its guard.
243 *
244 * @param event
245 * Active event
246 *
247 * @return TimeInterval
248 * (empty if event not active or active with guard violated)
249 *
250 */
251 TimeInterval EnabledGuardTime(Idx event) const;
252
253
254 /**
255 * Get set of events that are active at current (untimed) state.
256 *
257 * @return
258 * Set of active events
259 */
260 const EventSet& ActiveEventSet(void) const;
261
262 /**
263 * Get set of transitions that are active at current (untimed) state
264 *
265 * @return
266 * Set of active trans
267 */
268 const TransSet& ActiveTransSet(void) const;
269
270 /**
271 * Let time pass. Returns false if the specified amount
272 * of time cannot elapse without an event being executed
273 *
274 * @param time
275 * Amount of time that shall elapse.
276 * @return
277 * True/false -- success
278 */
279 bool ExecuteTime(Time::Type time);
280
281 /**
282 * Execute transition. Returns false if the transition
283 * is not enabled and hence cannot be executed at the current time
284 *
285 * @param event
286 * Indicate transition to execute
287 * @return
288 * True/false -- success
289 */
290 bool ExecuteEvent(Idx event);
291
292 /**
293 * Set timed state. Returns false if state or clock values are invalid.
294 *
295 * @param tstate
296 * State to set.
297 *
298 * @return
299 * True/false -- success
300 */
301 bool CurrentTimedState(const TimedState& tstate);
302
303 /**
304 * Get timed state.
305 *
306 * @return
307 * Current discrete state and clock values.
308 */
309 const TimedState& CurrentTimedState(void) const;
310
311 /**
312 * Set discrete state. Returns false if state is not
313 * in state set.
314 *
315 * @param index
316 * State index
317 *
318 * @return
319 * True/false -- success
320 */
321 bool CurrentState(Idx index);
322
323 /**
324 * Get discrete state.
325 *
326 * @return
327 * Discret state by index
328 */
329 Idx CurrentState(void) const;
330
331 /**
332 * Set value of clock variable.
333 * Returns false if clock not in clockset.
334 *
335 * @param clock
336 * Index of clock variable to set
337 * @param time
338 * Time to set
339 * @return
340 * True/false -- success
341 */
342 bool CurrentClockValue(Idx clock, Time::Type time);
343
344 /**
345 * Get value of clock
346 *
347 * @param clock
348 * Index of clock variable
349 * @return time
350 * Value of clock variable
351 */
352 Time::Type CurrentClockValue(Idx clock) const;
353
354 /**
355 * Set current time.
356 *
357 * @param time
358 * New current time
359 */
360 void CurrentTime(Time::Type time);
361
362 /**
363 * Get current time
364 *
365 * @return time
366 * Current time
367 */
368 Time::Type CurrentTime(void) const;
369
370 /**
371 * Set logic time (# of steps)
372 *
373 * @param step
374 * New logic time
375 */
376 void CurrentStep(int step);
377
378
379 /**
380 * Get logic time ie numer of transitions so far.
381 *
382 */
383 int CurrentStep(void) const;
384
385 /**
386 * Returns true if timed generator is in a deadlocked state.
387 *
388 * @return true/false
389 */
390 bool IsDeadlocked() const;
391
392
393 /**
394 * Check if Executor is valid.
395 * Not implemented, should check for determinism and consitency of current state and clock values.
396 *
397 * @return
398 * Success
399 */
400 virtual bool Valid(void) const {return true;};
401
402
403 /**
404 * Pretty printable string of current state
405 */
406 std::string CurrentTimedStateStr(void) const;
407
408 /**
409 * Pretty printable string of timed state
410 */
411 std::string TSStr(const TimedState& tstate) const;
412
413 /**
414 * Pretty printable string of timed event
415 */
416 std::string TEStr(const TimedEvent& tevent) const;
417
418 /**
419 * Pretty printable string of clock name
420 */
421 std::string CStr(Idx idx) const;
422
423 /**
424 * Pretty printable string of event
425 */
426 std::string EStr(Idx idx) const;
427
428 /**
429 * Pretty printable string of state
430 */
431 std::string SStr(Idx idx) const;
432
433 // std faudes type interface
434 using TimedGenerator::Read;
435 using TimedGenerator::Write;
436
437 protected:
438
439 /**
440 * Copyment method.
441 *
442 * @param rSrc
443 * Source to assign from
444 */
445 void DoCopy(const Executor& rSrc);
446
447 /**
448 * Copyment method.
449 *
450 * @param rSrc
451 * Source to assign from
452 */
453 void DoMove(Executor& rSrc);
454
455 /**
456 * Reads configuration from TokenReader, see Typefor public wrappers.
457 *
458 * @param rTr
459 * TokenReader to read from
460 * @param rLabel
461 * Section to read
462 * @param pContext
463 * Read context to provide contextual information
464 *
465 * @exception Exception
466 * - IO error (id 1)
467 */
468 virtual void DoRead(TokenReader& rTr, const std::string& rLabel="", const Type* pContext=0);
469
470 /**
471 * Writes configuration to TokenWriter, see Type for public wrappers.
472 *
473 * @param rTw
474 * TokenWriter to write to
475 * @param rLabel
476 * Section to write
477 * @param pContext
478 * Write context to provide contextual information
479 *
480 * @exception Exception
481 * - IO error (id 2)
482 */
483 virtual void DoWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
484
485
486
487
488 private:
489
490 /** Current state incl clock values */
492
493 /** Current clock time */
495
496 /** Current logic time */
498
499 /** Prepare internal data structurs from generator */
500 void Compile(void);
501
502 /** Compute enabled events and enabled interval (fake const) */
503 void ComputeEnabled(void) const;
504
505 /** Compute enabled core routine (non const) */
506 void ComputeEnabledNonConst(void);
507
508 /** Record enabled time */
510
511 /** Record enabled events */
513
514 /** Record rime on shich mEEvents is constant */
516
517 /** Record interval in which each guard is enabled */
518 std::map<Idx,TimeInterval> mEGuardInterval;
519
520 /** Record disabled events */
522
523 /** Record active events (ie regardles time) */
525
526 /** Record active transitions (regardles time) */
528
529 /** Validity flag for the above data */
531
532 /** Compiled generator data: map transition to clock to interval constraint */
533 std::map<Transition, std::map<Idx,TimeInterval> > mTransClockIntervalMap;
534
535 /** Compiled generator data: map state to clock to interval constraint */
536 std::map<Idx, std::map<Idx,TimeInterval> > mStateClockIntervalMap;
537
538}; // end class Executor
539
540
541
542} // namespace faudes
543
544
545#endif
546
#define FAUDES_API
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:918
const std::string & Name(void) const
std::map< Idx, TimeInterval > mEGuardInterval
virtual bool Valid(void) const
Time::Type mCurrentTime
std::map< Transition, std::map< Idx, TimeInterval > > mTransClockIntervalMap
std::map< Idx, std::map< Idx, TimeInterval > > mStateClockIntervalMap
std::string StateName(Idx idx) const
TimeInterval mETime
TimeInterval mEInterval
std::string EventName(Idx idx) const
TimedState mCurrentTimedState
uint32_t Idx
std::map< Idx, Time::Type > ClockValue

libFAUDES 2.34e --- 2026.03.16 --- c++ api documentaion by doxygen