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 * Assignment method.
328 *
329 * @param rSrcAttr
330 * Source to assign from
331 */
332 void DoAssign(const AttributeSimCondition& rSrcAttr);
333
334 /**
335 * Equality method.
336 *
337 * @param rAttr
338 * Source to compare with
339 */
340 bool DoEqual(const AttributeSimCondition& rAttr) const;
341
342 /**
343 * Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
344 *
345 * If the current token indicates a condition section, the method reads the
346 * condition data from that section. Else it does nothing. Exceptions may only be thrown
347 * on invalid data within the condition section. The label argiment is ignored, we
348 * use hardcoded labled "EventCondition" and "StateCondition" to figure the type of
349 * condition. When a ParallelExecutor is provided as context, it is used to interpret
350 * symbolc state names of a state condition.
351 *
352 * @param rTr
353 * TokenReader to read from
354 * @param rLabel
355 * Section to read
356 * @param pContext
357 * Read context to provide contextual information
358 *
359 * @exception Exception
360 * - IO error (id 1)
361 */
362 virtual void DoRead(TokenReader& rTr, const std::string& rLabel="", const Type* pContext=0);
363
364 /**
365 * Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
366 *
367 * Writes a condition section to include data on state- or event-condition. The label argument
368 * is ignored, we use hardcoded keywords "EventCondition" and StateCondition". When a
369 * ParallelExecutor is provided as context, it state conditions are written with
370 * symbolic state names.
371 *
372 * @param rTw
373 * TokenWriter to write to
374 * @param rLabel
375 * Section to write
376 * @param pContext
377 * Read context to provide contextual information
378 *
379 * @exception Exception
380 * - IO error (id 2)
381 */
382 virtual void DoWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
383
384private:
385
386 /** Overall default value */
387 const static fType mDefSCFlags =0x01;
388
389 /** All flags used by CFlags */
390 const static fType mAllSCFlags =0x03;
391
392
393
394}; // class AttributeSimCondition
395
396
397/**
398 * Set of simulation named conditions.
399 *
400 * Note: we currently share a symboltabel with the global
401 * event set. This will definitely change in a future revision.
402 */
403
404class FAUDES_API SimConditionSet : public TaNameSet<AttributeSimCondition> {
405
407
408 public:
409
410 /** Default constructor */
411 SimConditionSet(void);
412
413 /** Copy constructor */
414 SimConditionSet(const SimConditionSet& rOtherSet);
415
416 /** Virtual destructor */
417 virtual ~SimConditionSet(void) {};
418
419 /** Test condition for enabled */
420 bool Enabled(Idx cond) const { return Attribute(cond).Enabled(); };
421
422 /** Set condition enabled */
423 void Enabled(Idx cond, bool on) { Attributep(cond)->Enabled(on); };
424
425 /** Get set of enabled conditions */
426 SimConditionSet EnabledConditions(void);
427
428 /** Reset all condition states */
429 void Reset(void);
430
431protected:
432
433 /**
434 * Assign from other condition set.
435 *
436 * @param rSourceSet
437 * Destination to copy from
438 */
439 void DoAssign(const SimConditionSet& rSourceSet) {
441
442
443
444
445};
446
447
448
449/** @} doxygen group */
450
451} // namespace
452
453#endif
#define FAUDES_API
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:879
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)
bool Enabled(Idx cond) const
void DoAssign(const 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.33k --- 2025.09.16 --- c++ api documentaion by doxygen