sp_simeventset.h
Go to the documentation of this file.
1 /** @file sp_simeventset.h Eventsets with execution data for simulation */
2 
3 /*
4  Copyright (C) 2008 Thomas Moor
5  Exclusive copyright is granted to Klaus Schmidt
6 */
7 
8 
9 #ifndef FAUDES_SP_SIMEVENTSET_H
10 #define FAUDES_SP_SIMEVENTSET_H
11 
12 #include "corefaudes.h"
13 #include "tp_include.h"
14 
15 namespace faudes {
16 
17 
18 /**
19 
20 @defgroup SimEventAttributes Simulation Event Attributes
21 
22 @ingroup SimulatorPlugin
23 
24 Attributes to define stochastic and priority properties.
25 
26 @copydoc faudes::SimEventAttribute
27 
28 @{
29 
30 
31 */
32 
33 
34 /**
35  * Defining data to prioritise events.
36  *
37  * There are both prefer and avoid priorities. See ProposingExecutor for details.
38  * - Positive priority: preferred execution of event, larger number wins
39  * - Negative priority: avoid execution of event, smaller number wins
40  *
41  */
43  public:
44  long int mPriority;
45  bool operator==(const SimPriorityEventAttribute& rOther) const {
46  return mPriority==rOther.mPriority;}
47 };
48 
49 /**
50  * Defining data of stochastic behaviour.
51  *
52  * The occurence of events with stochastic behaviour is scheduled by sampling a random variable.
53  * While the attribute class only holds the defining data, actual semantics
54  * are implemented in the ProposingExecutor.
55  *
56  * The type indicates the mechanism for sampling the random variable and for scheduling the event.
57  * - Extern: the random variable models an external stochastic process.
58  * - Trigger: the random variable is used to narrow down the effective guard interval to a
59  * point.
60  * - Delay: the random variable models a delay relative to the time while the event is
61  * enabled.
62  *
63  * The propability density function may be one of
64  * - Exponential
65  * - Uniform
66  * - Gauss
67  * - Vector (arbitrary discrete density, not implemented)
68  *
69  */
71  public:
72 
73  /** When to re-evaluate the random variable */
74  typedef enum {Extern, Trigger, Delay} Type;
76 
77  /** Convert type to string */
78  std::string static TStr(Type type) {
79  if(type == Extern) return "extern";
80  if(type == Trigger) return "trigger";
81  if(type == Delay) return "delay";
82  return "unknown";
83  };
84 
85  /** Pdf to use when evaluating the random variable */
86  typedef enum {Exponential, Uniform, Gauss, Vector} Pdf;
88 
89  /** Pdf parameters */
90  std::vector<Float> mParameter;
91 
92  /** Equality operator */
93  bool operator==(const SimStochasticEventAttribute& rOther) const {
94  return (mType==rOther.mType) && (mPdf==rOther.mPdf) && (mParameter==rOther.mParameter);}
95 
96 };
97 
98 
99 
100 
101 /**
102  * Attribute for an event in the context of simulation.
103  *
104  * When simulating one or more generators, at each instance of time
105  * there will be one or more transitions enabled. In order resolve this non-determinism
106  * in a defined way, each event may be equipped with either one of the following
107  * properties.
108  *
109  * - a SimPriorityEventAttribute to prioritise events
110  * - a SimStochasticEventAttribute to determine timing by random variables
111  *
112  *
113  * Note that the SimEventAttribute just holds the data to define the properties,
114  * a semantic implementation is in faudes::ProposingExecutor. The current implementation
115  * also stores simulation state data (ie evaluations of random variables), but
116  * this is likely to change in a future revision.
117  *
118  * As a faudes attribute, SimEventAttribute provides token io and is prepared
119  * for the use in the context of a faudes container. The file format of a set of
120  * events equipped with simulation attributes is illustrated by the below example
121  * for the simulation of a simple machine:
122  *
123  * @code
124  *
125  * <SimEvents>
126  *
127  * % machine start: prioritised event with priority 100
128  * "alpha"
129  * <Priority> 100 </Priority>
130  *
131  * % machine finsh: gauss distributed event with mue=10 and sigma=5, relative to guard
132  * "beta"
133  * <Stochastic> +Trigger+ +Gauss+ <Parameter> 10 5 </Parameter> </Stochastic>
134  *
135  * % break down: gauss distributed event with mue=20 and sigma=5, relative to enabled time
136  * "mue"
137  * <Stochastic> +Delay+ +Gauss+ <Parameter> 20 5 </Parameter> </Stochastic>
138  *
139  * % machine repair: prioritised event with priority 100
140  * "lambda"
141  * <Priority> 100 </Priority>
142  *
143  * </SimEvents>
144  *
145  * @endcode
146  *
147  */
148 
150 
152 
153  public:
154 
155  /**
156  * Default constructor. Construct a SimEventAttribute with
157  * priority 0.
158  */
160  mStochastic=false; mPriority=true; mPriorityAttribute.mPriority=0;};
161 
162  /**
163  * Copy constructor.
164  */
166  DoAssign(rSrc); }
167 
168  /**
169  * Test for default value
170  *
171  * @return
172  * True, if this attribute has its default value
173  */
174  virtual bool IsDefault(void) const {return (!mStochastic) &&
175  (mPriority && mPriorityAttribute.mPriority==0) && AttributeCFlags::IsDefault(); };
176 
177  /**
178  * Test for stochastic property.
179  *
180  * @return
181  * True, if this attribute defines stochastic behaviour
182  */
183  bool IsStochastic(void) const {return mStochastic; };
184 
185  /**
186  * Test for priority property.
187  *
188  * @return
189  * True, if this attribute defines priority behaviour
190  */
191  bool IsPriority(void) const {return mPriority; };
192 
193  /**
194  * Set stochastic behaviour. Define this attribute to
195  * indicate the specified stochastic bahaviour.
196  *
197  * @param rStochasticAttribute
198  * Define stochastic behaviour
199  */
200  void Stochastic(const SimStochasticEventAttribute& rStochasticAttribute) {
201  mStochasticAttribute= rStochasticAttribute; mStochastic=true; mPriority=false;};
202 
203 
204  /**
205  * Set priority behaviour. Define this attribute to
206  * indicate execution with the specified priority.
207  *
208  * @param rPriorityAttribute
209  * Define stochastic behaviour
210  */
211  void Priority(const SimPriorityEventAttribute& rPriorityAttribute) {
212  mPriorityAttribute = rPriorityAttribute; mPriority=true; mStochastic=false; }
213 
214 
215  /**
216  * Get priority attribute. Note that the return value
217  * is only meaningful if the attribute actually is a priority attribute.
218  *
219  * @return
220  * Defining data of this attribute's priority behaviour
221  *
222  */
223  const SimPriorityEventAttribute& Priority(void) const {return mPriorityAttribute; };
224 
225  /**
226  * Get stochastic attribute. Note that the return value
227  * is only meaningful if the attribute defines stochastic behaviour.
228  *
229  * @return
230  * Defining data of this attribute's stochastic behaviour
231  *
232  */
233  const SimStochasticEventAttribute& Stochastic(void) const {return mStochasticAttribute; };
234 
235  /**
236  * Next scheduled occurence of this event relative to current time. This is part of the
237  * execution state. It indicates the instance of time for which the respective event is scheduled
238  * to occur. Schedules, however, may expire or otherwise become invalid.
239  */
241 
242  /**
243  * Time at which the recent schedule expires. This is part of the
244  * execution state. Once a schedule expires, the event is re-scheduled.
245  */
247 
248  /**
249  * Amount of time to defer the event. This is part of the
250  * execution state. It is used for events of delay type and is a count down type
251  * alarm to trigger the event.
252  */
254 
255  /**
256  * Time domain on which the recent schedule was computed. This is part of the
257  * execution state. It is used to invalidate schedules for events of trigger type.
258  */
260 
261  /**
262  * Debug string, incl state
263  *
264  */
265  std::string Str(void) const;
266 
267 protected:
268 
269  /** Indicate precense of stochastic behaviour */
271 
272  /** Indicate precense of priority property */
273  bool mPriority;
274 
275  /** Priority definition data */
277 
278  /** Stochastic definition data */
280 
281  /**
282  * Assignment method.
283  *
284  * @param rSrcAttr
285  * Source to assign from
286  */
287  void DoAssign(const SimEventAttribute& rSrcAttr);
288 
289  /**
290  * Test equality
291  *
292  * @param rOther
293  * Attribute to compare with
294  * @return
295  * True/False
296  */
297  bool DoEqual(const SimEventAttribute& rOther) const;
298 
299  /**
300  * Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
301  *
302  * If the current token indicates a simulation event section, the method reads all
303  * consecutive simulation attributes. Else it does nothing. Exceptions may only be thrown
304  * on invalid data within the section. The label argument is ignored, we use hardcoded
305  * keywords for the four attributes. The context argument is ignored.
306  *
307  * @param rTr
308  * TokenReader to read from
309  * @param rLabel
310  * Section to read
311  * @param pContext
312  * Read context to provide contextual information
313  *
314  * @exception Exception
315  * - IO error (id 1)
316  */
317  virtual void DoRead(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0);
318 
319  /**
320  * Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
321  *
322  * Writes all present simulation event attributes to include the defining data.
323  * The label argument is ignored, we use hardcoded keywords. The context argument is ignored.
324  *
325  * @param rTw
326  * TokenWriter to write to
327  * @param rLabel
328  * Section to write
329  * @param pContext
330  * Read context to provide contextual information
331  *
332  * @exception Exception
333  * - IO error (id 2)
334  */
335  virtual void DoWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
336 
337 
338 
339 
340 }; // class SimEventAttribute
341 
342 
343 /**
344  * Typedef for events with simulation attributes.
345  */
346 
348 
349 /** @} doxygen group */
350 
351 } // namespace
352 
353 #endif
#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
Attribute class to model event controllability properties.
virtual bool IsDefault(void) const
Test for default value.
Attribute for an event in the context of simulation.
Time::Type mExpiresAt
Time at which the recent schedule expires.
Time::Type mScheduledFor
Next scheduled occurence of this event relative to current time.
void Priority(const SimPriorityEventAttribute &rPriorityAttribute)
Set priority behaviour.
SimStochasticEventAttribute mStochasticAttribute
Stochastic definition data
TimeInterval mReferenceInterval
Time domain on which the recent schedule was computed.
bool mPriority
Indicate precense of priority property.
SimEventAttribute(const SimEventAttribute &rSrc)
Copy constructor.
SimEventAttribute(void)
Default constructor.
const SimStochasticEventAttribute & Stochastic(void) const
Get stochastic attribute.
virtual bool IsDefault(void) const
Test for default value.
SimPriorityEventAttribute mPriorityAttribute
Priority definition data
const SimPriorityEventAttribute & Priority(void) const
Get priority attribute.
bool IsPriority(void) const
Test for priority property.
bool IsStochastic(void) const
Test for stochastic property.
void Stochastic(const SimStochasticEventAttribute &rStochasticAttribute)
Set stochastic behaviour.
Time::Type mDelayFor
Amount of time to defer the event.
bool mStochastic
Indicate precense of stochastic behaviour.
Defining data to prioritise events.
bool operator==(const SimPriorityEventAttribute &rOther) const
Defining data of stochastic behaviour.
Type
When to re-evaluate the random variable.
static std::string TStr(Type type)
Convert type to string.
bool operator==(const SimStochasticEventAttribute &rOther) const
Equality operator.
std::vector< Float > mParameter
Pdf parameters.
Pdf
Pdf to use when evaluating the random variable.
Model of a time interval.
Int Type
Datatype for point on time axis.
A TokenReader reads sequential tokens from a file or string.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
Vector of scalars.
Includes all libFAUDES headers, no plugins.
TaNameSet< SimEventAttribute > sEventSet
Typedef for events with simulation attributes.
libFAUDES resides within the namespace faudes.
Include timed plugin headers.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen