sp_simconditionset.h
Go to the documentation of this file.
1/** @file sp_simconditionset.h Set of named simulation conditions */
2
3/*
4 Copyright (C) 2008 Thomas Moor
5 Exclusive copyright is granted to Klaus Schmidt
6*/
7
8
9#include "corefaudes.h"
10#include "sp_densityfnct.h"
11
12
13#ifndef FAUDES_SP_SIMCONDITIONSET_H
14#define FAUDES_SP_SIMCONDITIONSET_H
15
16namespace faudes {
17
18/**
19
20@defgroup SimConditionAttributes Simulation Condition Attributes
21
22@ingroup SimulatorPlugin
23
24Attributes to define simulation conditions used for statistic analysis
25of simulation runs.
26
27@copydoc faudes::AttributeSimCondition
28
29@{
30
31*/
32
33/**
34 * Defining data of event based simulation condition
35 *
36 * An event based condition has a set of start events and a set of
37 * stop events. It becomes satisfied when a start event occurs and it
38 * becomes unsatisfied when a stop event occurs. Thus, when start or stop
39 * events fail to alternate, the first event of the respective type is relevant.
40 *
41 */
43 public:
46 bool operator==(const SimEventCondition rOther) const {
47 return mStart==rOther.mStart && mStop==rOther.mStop;};
48};
49
50/**
51 * Defining data of state based simulation condition
52 *
53 * A state based condition has a set of states per generator an is satisfied
54 * while the components of the current discrete state vector are within the
55 * respective set. A flag indicates whether each or some component
56 * must comply with the state set to satisfy the condition.
57 *
58 * Note: Since state indices are local to generators, a SimStateCondition
59 * is only meaningful in the context of a particular ParallelExecutor.
60 *
61 */
62
63// state based condition
65public:
67 std::vector<StateSet> mStateSets;
68 bool operator==(const SimStateCondition rOther) const {
69 return mAllFlag==rOther.mAllFlag && mStateSets==rOther.mStateSets;};
70};
71
72
73/**
74 * Attribute for a simulation condition
75 *
76 * In order to extract statistical data from a simulation by a LoggingExecutor
77 * or some derived class, so called simulation conditions
78 * are defined. At any instance of time, a condition is satisfied or
79 * dissatisfied. Statistical data can then be requested regarding
80 * the period and duration of each condition. Currently, two
81 * types of conditions are available:
82 *
83 * - SimStateCondition addresses conditions of the current state
84 * - SimEventCondition addresses the external event sequence.
85 *
86 * A Condition may be flagged as a break condition to halt simulation
87 * when satisfied. A condition may be enabled for tracking or not.
88 *
89 * The class AttributeSimCondition summarizes all data to represent
90 * faudes simulation conditions. It also holds some state of the condition
91 * wrt execution and provides an interface for sampling. The latter
92 * may be seperated to a different class in a future revision. The class
93 * AttributeSimCondition does, however, not implement any test whether
94 * or not a condition is satisfied. This is done by the LoggingExecutor.
95 *
96 * As a faudes attribute, conditions can be referenced by
97 * names via the std faudes container TaNameSet. For token io, a
98 * ParallelExecutor should be provided as context to access symbolic
99 * state names. The file format of a set of
100 * events equipped with condition attributes is illustrated by the below example
101 * to monitor some performance aspects of one simple machine:
102 *
103 * @code
104 *
105 * <Conditions>
106 *
107 * % monitor when the machine is idle
108 * "IdleCond"
109 * <StateCondition>
110 * <StateSet> "idle" </StateSet>
111 * </StateCondition>
112 *
113 * % halt simulation when the machine is down
114 * % however, the condition is disabled
115 * "DownCond"
116 * +Break+
117 * +Disabled+
118 * <StateCondition>
119 * <StateSet> "down" </StateSet>
120 * </StateCondition>
121 *
122 * % monitor how long the prozessing one work piece takes
123 * "OperationCond"
124 * <EventCondition>
125 * <StartEvents> "alpha" </StartEvents>
126 * <StopEvents> "beta" </StopEvents>
127 * </EventCondition>
128 *
129 * </Conditions>
130 *
131 * @endcode
132 */
133
135
137
138 public:
139
140 /** Convenience typedef */
141 typedef std::vector<StateSet>::iterator Iterator;
142 typedef std::vector<StateSet>::const_iterator CIterator;
143
144 /**
145 * Default constructor. Constructs a AttributeSimCondition of
146 * with no type ie neither state condition nor event condition.
147 */
149
150 /**
151 * Copy constructor.
152 * with no type ie neither state condition nor event condition.
153 */
155
156 /**
157 * Test for default value
158 *
159 * @return
160 * True, if this attribute has its default value
161 */
162 virtual bool IsDefault(void) const {
163 return !mEventCondition && !mStateCondition && (mFlags==mDefSCFlags); };
164
165
166 /**
167 * Test for state condition.
168 *
169 * @return
170 * True, if this attribute defines a state condition
171 */
172 bool IsStateCondition(void) const {return mStateCondition; };
173
174 /**
175 * Test for event condition.
176 *
177 * @return
178 * True, if this attribute defines an event condition
179 */
180 bool IsEventCondition(void) const {return mEventCondition; };
181
182 /**
183 * Test for break condition.
184 *
185 * @return
186 * True, if this condition halts simulation.
187 */
188 bool Breakpoint(void) const {return ((mFlags & mBreakpointFlag) != 0); };
189
190 /**
191 * Test whether condition is enabled.
192 *
193 * @return
194 * True, if this condition is monitored during simulation.
195 */
196 bool Enabled(void) const { return ((mFlags & mEnabledFlag) != 0); };
197
198 /**
199 * Set state condition attribute. Define this attribute to
200 * represent the specified state condition.
201 *
202 * @param rStateConditionAttribute
203 * Define state condition
204 */
205 void StateCondition(const SimStateCondition& rStateConditionAttribute)
206 {mStateConditionAttribute=rStateConditionAttribute; mStateCondition=true; mEventCondition=false;
207 for(Idx i=0; i<mStateConditionAttribute.mStateSets.size(); i++)
208 mStateConditionAttribute.mStateSets.at(i).Name("StateSet");
209 };
210
211 /**
212 * Set event condition attribute. Define this attribute to
213 * represent the specified event condition.
214 *
215 * @param rEventConditionAttribute
216 * Define event condition
217 */
218 void EventCondition(const SimEventCondition& rEventConditionAttribute)
219 {mEventConditionAttribute=rEventConditionAttribute; mEventCondition=true; mStateCondition=false;};
220
221 /**
222 * Set break flag.
223 *
224 * @param on
225 * True, to indicate that this condition halts simulation.
226 */
227 void Breakpoint(bool on) { if(on) mFlags |= mBreakpointFlag; else mFlags &= ~mBreakpointFlag; };
228
229 /**
230 * Set enabled flag.
231 *
232 * @param on
233 * True, to indicate that this condition is to be monitored during simulation.
234 */
235 void Enabled(bool on) { if(on) mFlags |= mEnabledFlag; else mFlags &= ~mEnabledFlag; };
236
237 /**
238 * Get event condition. Note that the attribute can only return
239 * meaningful data if it actually is an event condition.
240 *
241 * @return
242 * Defining data of this attribute's event condition.
243 *
244 */
245 const SimEventCondition& EventCondition(void) const {return mEventConditionAttribute; };
246
247 /**
248 * Get state condition. Note that the attribute can only return
249 * meaningful data if it actually is an state condition.
250 *
251 * @return
252 * Defining data of this attribute's state condition.
253 *
254 */
255 const SimStateCondition& StateCondition(void) const {return mStateConditionAttribute; };
256
257 /**
258 * Reset conditions execution state. The execution state of a condition
259 * consists of all data accumulated during simulation eg statistical data
260 * and whether or not the condition is currently satisfied. The execution state
261 * resides in the attribute for pragmatic reasons only.
262 */
263 void Reset(void)
264 { mSatisfied=false; mActivationTime=-1; mSamplesPeriod.Clear(); mSamplesDuration.Clear(); };
265
266 /**
267 * Test whether the condition is currently satisfied. This is part
268 * of the condition execution state.
269 *
270 * @return
271 * True, if the conditions is considered satisfied
272 */
273 bool Satisfied(void) const { return mSatisfied; };
274
275 /**
276 * Set the condition to be satisfied. This is part
277 * of the condition execution state. Since it is the executor
278 * that determines whether a condition is satisfied, and since
279 * the condition state resides in the attribute, the executor
280 * is meant to notify state changes.
281 *
282 * @param on
283 * True, if the conditions is considered satisfied
284 * @param now
285 * Time at which the state change occures
286 */
287 void Satisfied(bool on, Time::Type now);
288
289 /**
290 * Sampled period, at which this condition becomes satisfied.
291 */
293
294 /**
295 * Sampled durations, for which this condition remains satisfied.
296 */
298
299 // flag masks for the three properties
300 const static fType mEnabledFlag =0x01;
301 const static fType mBreakpointFlag =0x02;
302
303protected:
304
305 /** Indicate precense of a event condition */
307
308 /** Indicate precense of a state condition */
310
311 /** Event based condition data */
313
314 /** State based condition data */
316
317 /** Condotion state: recorded as satisfied */
319
320 /** Condition state: when last satisfied became true */
322
323
324 protected:
325
326 /**
327 * Copyment method.
328 *
329 * @param rSrcAttr
330 * Source to assign from
331 */
332 void DoCopy(const AttributeSimCondition& rSrcAttr);
333
334 /**
335 * Copyment method.
336 *
337 * @param rSrcAttr
338 * Source to assign from
339 */
340 void DoMove(AttributeSimCondition& rSrcAttr);
341
342 /**
343 * Equality method.
344 *
345 * @param rAttr
346 * Source to compare with
347 */
348 bool DoEqual(const AttributeSimCondition& rAttr) const;
349
350 /**
351 * Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
352 *
353 * If the current token indicates a condition section, the method reads the
354 * condition data from that section. Else it does nothing. Exceptions may only be thrown
355 * on invalid data within the condition section. The label argiment is ignored, we
356 * use hardcoded labled "EventCondition" and "StateCondition" to figure the type of
357 * condition. When a ParallelExecutor is provided as context, it is used to interpret
358 * symbolc state names of a state condition.
359 *
360 * @param rTr
361 * TokenReader to read from
362 * @param rLabel
363 * Section to read
364 * @param pContext
365 * Read context to provide contextual information
366 *
367 * @exception Exception
368 * - IO error (id 1)
369 */
370 virtual void DoRead(TokenReader& rTr, const std::string& rLabel="", const Type* pContext=0);
371
372 /**
373 * Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
374 *
375 * Writes a condition section to include data on state- or event-condition. The label argument
376 * is ignored, we use hardcoded keywords "EventCondition" and StateCondition". When a
377 * ParallelExecutor is provided as context, it state conditions are written with
378 * symbolic state names.
379 *
380 * @param rTw
381 * TokenWriter to write to
382 * @param rLabel
383 * Section to write
384 * @param pContext
385 * Read context to provide contextual information
386 *
387 * @exception Exception
388 * - IO error (id 2)
389 */
390 virtual void DoWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
391
392private:
393
394 /** Overall default value */
395 const static fType mDefSCFlags =0x01;
396
397 /** All flags used by CFlags */
398 const static fType mAllSCFlags =0x03;
399
400
401
402}; // class AttributeSimCondition
403
404
405/**
406 * Set of simulation named conditions.
407 *
408 * Note: we currently share a symboltabel with the global
409 * event set. This will definitely change in a future revision.
410 */
411
412class FAUDES_API SimConditionSet : public TaNameSet<AttributeSimCondition> {
413
415
416 public:
417
418 /** Default constructor */
419 SimConditionSet(void);
420
421 /** Copy constructor */
422 SimConditionSet(const SimConditionSet& rOtherSet);
423
424 /** Virtual destructor */
425 virtual ~SimConditionSet(void) {};
426
427 /** Test condition for enabled */
428 bool Enabled(Idx cond) const { return Attribute(cond).Enabled(); };
429
430 /** Set condition enabled */
431 void Enabled(Idx cond, bool on) { Attributep(cond)->Enabled(on); };
432
433 /** Get set of enabled conditions */
434 SimConditionSet EnabledConditions(void);
435
436 /** Reset all condition states */
437 void Reset(void);
438
439protected:
440
441 /**
442 * Copy from other condition set.
443 *
444 * @param rSourceSet
445 * Destination to copy from
446 */
447 void DoCopy(const SimConditionSet& rSourceSet) {
449
450 /**
451 * Copy from other condition set.
452 *
453 * @param rSourceSet
454 * Destination to copy from
455 */
456 void DoMove(SimConditionSet& rSourceSet) {
458
459
460
461
462};
463
464
465
466/** @} doxygen group */
467
468} // namespace
469
470#endif
#define FAUDES_API
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:918
std::vector< StateSet >::const_iterator CIterator
void StateCondition(const SimStateCondition &rStateConditionAttribute)
void EventCondition(const SimEventCondition &rEventConditionAttribute)
SimEventCondition mEventConditionAttribute
SampledDensityFunction mSamplesDuration
const SimEventCondition & EventCondition(void) const
SimStateCondition mStateConditionAttribute
SampledDensityFunction mSamplesPeriod
std::vector< StateSet >::iterator Iterator
const SimStateCondition & StateCondition(void) const
virtual bool IsDefault(void) const
void Enabled(Idx cond, bool on)
void DoCopy(const SimConditionSet &rSourceSet)
bool Enabled(Idx cond) const
void DoMove(SimConditionSet &rSourceSet)
bool operator==(const SimEventCondition rOther) const
std::vector< StateSet > mStateSets
bool operator==(const SimStateCondition rOther) const
uint32_t Idx
unsigned long int fType

libFAUDES 2.34d --- 2026.03.11 --- c++ api documentaion by doxygen