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
11namespace faudes {
12
13
14// faudes type std
15FAUDES_TYPE_IMPLEMENTATION(Void,SimEventAttribute,AttributeCFlags)
16
17
18// Assign my members
19void SimEventAttribute::DoAssign(const SimEventAttribute& rSrcAttr) {
20 // call base (incl. virtual clear)
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
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);
50void 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)
84void 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) {
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
206std::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)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition cfl_types.h:958
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
bool DoEqual(const AttributeCFlags &rOther) const
void DoAssign(const AttributeCFlags &rSrcAttr)
const SimPriorityEventAttribute & Priority(void) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
SimStochasticEventAttribute mStochasticAttribute
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
std::string Str(void) const
const SimStochasticEventAttribute & Stochastic(void) const
SimPriorityEventAttribute mPriorityAttribute
bool DoEqual(const SimEventAttribute &rOther) const
bool IsPriority(void) const
bool IsStochastic(void) const
static std::string TStr(Type type)
static std::string Str(Type time)
std::string FileLine(void) const
bool Eos(const std::string &rLabel)
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
bool Get(Token &token)
bool Peek(Token &token)
void WriteFloat(const double &val)
void WriteEnd(const std::string &rLabel)
void WriteInteger(Idx index)
void WriteBegin(const std::string &rLabel)
void WriteOption(const std::string &rOpt)
const std::string & StringValue(void) const
bool IsBegin(void) const
const std::string & OptionValue(void) const
bool IsFloat(void) const
bool IsOption(void) const
faudes::Float FloatValue(void) const
double Float

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen