sp_simeventset.cpp
Go to the documentation of this file.
1 /** @file sp_simeventset.cpp Eventsets with execution data for simulation */
2 
3 
4 /*
5  Copyright (C) 2008 Thomas Moor
6  Exclusive copyright is granted to Klaus Schmidt
7 */
8 
9 #include "sp_simeventset.h"
10 
11 namespace faudes {
12 
13 
14 // faudes type std
15 FAUDES_TYPE_IMPLEMENTATION(Void,SimEventAttribute,AttributeCFlags)
16 
17 
18 // Assign my members
19 void SimEventAttribute::DoAssign(const SimEventAttribute& rSrcAttr) {
20  // call base (incl. virtual clear)
21  AttributeCFlags::DoAssign(rSrcAttr);
22  // my additional members
23  mStochastic=rSrcAttr.mStochastic;
24  mPriority=rSrcAttr.mPriority;
25  mPriorityAttribute=rSrcAttr.mPriorityAttribute;
26  mStochasticAttribute=rSrcAttr.mStochasticAttribute;
27  // my dynamic state
28  mScheduledFor=rSrcAttr.mScheduledFor;
29  mExpiresAt=rSrcAttr.mExpiresAt;
30  mDelayFor=rSrcAttr.mDelayFor;
31  mReferenceInterval=rSrcAttr.mReferenceInterval;
32 }
33 
34 
35 // Test equality
36 bool SimEventAttribute::DoEqual(const SimEventAttribute& rOther) const {
37  // call base
38  if(!AttributeCFlags::DoEqual(rOther)) return false;
39  // my additional members
40  if(mStochastic!=rOther.mStochastic) return false;
41  if(mPriority!=rOther.mPriority) return false;
42  if(!(mPriorityAttribute==rOther.mPriorityAttribute)) return false;
43  if(!(mStochasticAttribute==rOther.mStochasticAttribute)) return false;
44  // pass
45  return true;
46 }
47 
48 
49 //DoWrite(rTw);
50 void SimEventAttribute::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
51  (void) rLabel;
52  // do base first
53  AttributeCFlags::DoWrite(rTw,"",pContext);
54  FD_DC("SimEventAttribute(" << this << ")::DoWrite(tr)");
55  Token token;
56  // write priority
57  if(mPriority) {
58  rTw.WriteBegin("Priority");
60  rTw.WriteEnd("Priority");
61  }
62  // write stochastic
63  if(mStochastic) {
64  rTw.WriteBegin("Stochastic");
71  if(mStochasticAttribute.mParameter.size()>0) {
72  rTw.WriteBegin("Parameter");
73  std::vector<Float>::const_iterator pit=mStochasticAttribute.mParameter.begin();
74  for(; pit!=mStochasticAttribute.mParameter.end(); pit++) {
75  rTw.WriteFloat(*pit);
76  }
77  rTw.WriteEnd("Parameter");
78  }
79  rTw.WriteEnd("Stochastic");
80  }
81 }
82 
83 //DoRead(rTr)
84 void SimEventAttribute::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
85  (void) rLabel;
86  // call base first
87  AttributeCFlags::DoRead(rTr,"",pContext);
88 
89  // report
90  FD_DC("SimEventAttribute(" << this << ")::DoRead(tr)");
91 
92  // clear myself
93  mStochastic=false;
94  mPriority=false;
95 
96  // read as long as we can handle
97  Token token;
98  bool err=false;
99  while(rTr.Peek(token)) {
100 
101  // try priority
102  if(token.IsBegin() && token.StringValue()=="Priority") {
103  rTr.ReadBegin("Priority");
104  mPriority=true;
105  rTr.Get(token);
106  if(!token.IsFloat()) {
107  err=true;
108  } else {
110  }
111  rTr.ReadEnd("Priority");
112  continue;
113  }
114 
115  // try stochastic
116  if(token.IsBegin() && token.StringValue()=="Stochastic") {
117  rTr.ReadBegin("Stochastic");
118  // stochastic default
119  mStochastic=true;
123  mStochasticAttribute.mParameter.push_back(1);
124  // mandatory option: intern/extern/delay
125  rTr.Get(token);
126  if(!token.IsOption()) {
127  err=true;
128  } else {
129  if(token.OptionValue() == "Extern")
131  if(token.OptionValue() == "Trigger")
133  if(token.OptionValue() == "Delay")
135  }
136  // mandatory option: exponential/gauss/ etc
137  rTr.Get(token);
138  if(!token.IsOption()) {
139  err=true;
140  } else {
141  if(token.OptionValue() == "Exponential")
143  if(token.OptionValue() == "Gauss")
145  if(token.OptionValue() == "Uniform")
147  }
148  // optional data: parameter vector
149  rTr.Peek(token);
150  if(token.StringValue()=="Parameter" && token.IsBegin()) {
152  rTr.ReadBegin("Parameter");
153  while (!rTr.Eos("Parameter")) {
154  Float par = rTr.ReadFloat();
155  mStochasticAttribute.mParameter.push_back(par);
156  }
157  rTr.ReadEnd("Parameter");
158  }
159  // old file format: fix missing restricted support pdfs
161  && mStochasticAttribute.mParameter.size() == 1) {
162  Float lambda= mStochasticAttribute.mParameter.at(0);
164  mStochasticAttribute.mParameter.push_back(0);
165  mStochasticAttribute.mParameter.push_back(std::numeric_limits<Float>::max());
166  mStochasticAttribute.mParameter.push_back(lambda);
167  }
169  && mStochasticAttribute.mParameter.size() == 2) {
173  mStochasticAttribute.mParameter.push_back(0);
174  mStochasticAttribute.mParameter.push_back(std::numeric_limits<Float>::max());
175  mStochasticAttribute.mParameter.push_back(mue);
176  mStochasticAttribute.mParameter.push_back(sigma);
177  }
178  // check parameter vector consistency
180  && mStochasticAttribute.mParameter.size() != 3)
181  err=true;
183  && mStochasticAttribute.mParameter.size() != 4)
184  err=true;
186  && mStochasticAttribute.mParameter.size() != 2)
187  err=true;
188  rTr.ReadEnd("Stochastic");
189  }
190 
191  // report error
192  if(err) {
193  std::stringstream errstr;
194  errstr << "invalid simulation event property" << rTr.FileLine();
195  throw Exception("SimEventAttribute::Read", errstr.str(), 52);
196  }
197 
198  // cannot digest? -> done
199  break;
200 
201  }
202 }
203 
204 
205 // debug str
206 std::string SimEventAttribute::Str(void) const {
207  std::stringstream retstr;
208  //retstr << "[" << this << "] ";
209  if(IsPriority()) {
210  retstr<< "priority=" << Priority().mPriority << " ";
211  }
212  if(IsStochastic()) {
213  retstr<< "stochastic=" << SimStochasticEventAttribute::TStr(Stochastic().mType) << " " ;
214  retstr<< "scheduled_for=" << Time::Str(mScheduledFor) << " ";
215  retstr<< " expires_at=" << Time::Str(mExpiresAt) << " ";
216  retstr<< " delay_for=" << Time::Str(mDelayFor) << " ";
217  }
218  return retstr.str();
219 }
220 
221 
222 
223 } // namespace faudes
224 
#define FD_DC(message)
Debug: optional report on container operations.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Definition: cfl_types.h:946
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see AttributeVoid for public wrappers.
bool DoEqual(const AttributeCFlags &rOther) const
Test equality of configuration data.
void DoAssign(const AttributeCFlags &rSrcAttr)
Assignment method.
Faudes exception class.
Attribute for an event in the context of simulation.
Time::Type mExpiresAt
Time at which the recent schedule expires.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
Time::Type mScheduledFor
Next scheduled occurence of this event relative to current time.
SimStochasticEventAttribute mStochasticAttribute
Stochastic definition data
bool mPriority
Indicate precense of priority property.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
const SimStochasticEventAttribute & Stochastic(void) const
Get stochastic attribute.
std::string Str(void) const
Debug string, incl state.
SimPriorityEventAttribute mPriorityAttribute
Priority definition data
bool DoEqual(const SimEventAttribute &rOther) const
Test equality.
const SimPriorityEventAttribute & Priority(void) const
Get priority attribute.
bool IsPriority(void) const
Test for priority property.
bool IsStochastic(void) const
Test for stochastic property.
Time::Type mDelayFor
Amount of time to defer the event.
bool mStochastic
Indicate precense of stochastic behaviour.
static std::string TStr(Type type)
Convert type to string.
std::vector< Float > mParameter
Pdf parameters.
static std::string Str(Type time)
convert to string
A TokenReader reads sequential tokens from a file or string.
std::string FileLine(void) const
Return "filename:line".
bool Eos(const std::string &rLabel)
Peek a token and check whether it ends the specified section.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
double ReadFloat(void)
Read float token.
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
bool Get(Token &token)
Get next token.
bool Peek(Token &token)
Peek next token.
A TokenWriter writes sequential tokens to a file, a string or stdout.
void WriteFloat(const double &val)
Write float.
void WriteEnd(const std::string &rLabel)
Write end label.
void WriteInteger(Idx index)
Write non negative integer.
void WriteBegin(const std::string &rLabel)
Write begin label.
void WriteOption(const std::string &rOpt)
Write option (may not contain any "+")
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
const std::string & StringValue(void) const
Get string value of a name token.
Definition: cfl_token.cpp:177
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
const std::string & OptionValue(void) const
Get option value of a name token.
Definition: cfl_token.cpp:183
bool IsFloat(void) const
Test token Type.
Definition: cfl_token.cpp:233
bool IsOption(void) const
Test token Type.
Definition: cfl_token.cpp:238
faudes::Float FloatValue(void) const
Get float value of a numeric token.
Definition: cfl_token.cpp:172
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
libFAUDES resides within the namespace faudes.
double Float
Type definition for real type.
Eventsets with execution data for simulation.

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