hio_constraint.cpp
Go to the documentation of this file.
1/** @file hio_constraint.cpp Generator with I/O-constraint attributes */
2
3/* Hierarchical IO Systems Plug-In for FAU Discrete Event Systems Library (libfaudes)
4
5 Copyright (C) 2006 Sebastian Perk
6 Copyright (C) 2006 Thomas Moor
7 Copyright (C) 2006 Klaus Schmidt
8
9*/
10
11#include "hio_constraint.h"
12
13namespace faudes {
14
15// IsHioConstraintForm()
17 StateSet& rQY,
18 StateSet& rQU,
19 EventSet& rErrEvSet,
20 TransSet& rErrTrSet,
21 StateSet& rErrStSet,
22 std::string& rReportStr)
23 {
24 FD_DF("IsHioConstraintForm("<< rHioConstraint.Name() << ",...)");
25
26 // prepare results
27 rQY.Clear();
28 rQU.Clear();
29
30 rErrEvSet.Clear();
31 rErrEvSet.Name("rErrEvSet");
32
33 rErrTrSet.Clear();
34 rErrTrSet.Name("rErrTrSet");
35
36 rErrStSet.Clear();
37 rErrStSet.Name("rErrStSet");
38
39 // used to locally store error states/transitions on each condition
40 StateSet locErrStSet;
41 TransSet locErrTrSet;
42
43 rReportStr.clear();
44
45 // meant to be set false on violation of any condition:
46 bool finalResult = true;
47 // used to locally store result on each condition
48 bool localResult = true;
49
50 // helpers
51
52 EventSet y = rHioConstraint.YEvents();
53 EventSet u = rHioConstraint.UEvents();
54
55 StateSet initStates = rHioConstraint.InitStates();
56 StateSet accessibleStates = rHioConstraint.AccessibleSet();
57 StateSet deadEnds;
58
59 EventSet::Iterator evit;
60 StateSet::Iterator sit;
62
63 // Info string header
64 rReportStr.append("#########################################################\n");
65 rReportStr.append("########## IsHioConstraintForm("+rHioConstraint.Name()+",...) - test results:\n");
66
67 /**************************** Precondition: determinism ***********************/
68 // HioConstraint must be deterministic
69 if(!rHioConstraint.IsDeterministic()){
70 rReportStr.append("##### fail: generator is not deterministic!\n");
71 if(initStates.Size()>1) {
72 rErrStSet = initStates;
73 rReportStr.append("##### (amongst others, there is more than one initial state)\n");
74 }
75 finalResult = false;
76 }
77
78 rReportStr.append("#####\n");
79
80 // test all conditions verifying I/O-constraint form:
81
82 /**************************** Condition (i) ***********************/
83 localResult = true;
84 rReportStr.append("########## Condition (i):\n");
85
86 //YP, UP, YE, UE nonempty?
87 if (y.Empty()) {
88 rReportStr.append("##### fail: empty Y alphabet.\n");
89 localResult=false;
90 finalResult = false;
91 }
92 if (u.Empty()) {
93 rReportStr.append("##### fail: empty U alphabet.\n");
94 localResult=false;
95 finalResult = false;
96 }
97
98 // check for disjoint eventsets Y and U and for
99 // Y u U == Sigma, ie unique HioEventFlags.
100 // note: by construction, any event has the exclusive property U or Y.
101 // thus, condition (i) is always met at this point.
102
103 rReportStr.append("##### Condition (i) passed.\n");
104 rReportStr.append("#####\n");
105 /*************************** Condition (i) finished *****************************/
106
107
108 /*************************** Condition (ii) ***********************/
109 localResult = true;
110 rReportStr.append("########## Condition (ii):\n");
111
112 // check if in states QYpYe, QUp and QUe only Y-, UP- and UE-events are active, respectively.
113 for(sit = accessibleStates.Begin(); sit != accessibleStates.End(); ++sit) {
114
115 bool isY = false;
116 bool isU = false;
117 bool goodState = true;
118
119 EventSet activeEv = rHioConstraint.ActiveEventSet(*sit);
120
121 if(activeEv.Empty()) {
122 //dead ends violate condition (vii)
123 deadEnds.Insert(*sit);
124 }
125 else {
126
127 // get attribute of first event and compare with remaining events
128 evit = activeEv.Begin();
129 isY = rHioConstraint.IsY(*evit);
130 isU = rHioConstraint.IsU(*evit);
131
132 for(; evit != activeEv.End(); evit++) {
133 if( (isY && !rHioConstraint.IsY(*evit)) ||
134 (isU && !rHioConstraint.IsU(*evit))) {
135 goodState = false;
136 localResult = false;
137 finalResult = false;
138 // add state to error set, go to next state
139 locErrStSet.Insert(*sit);
140 rErrStSet.Insert(*sit);
141 break; // leave loop over active events
142 }
143 }
144
145 activeEv.Clear();
146
147 if(!goodState) continue; // if undecidable go on with next state
148
149 // set state attribute
150 if(isY) {
151 rQY.Insert(*sit);
152 rHioConstraint.SetQY(*sit);
153 }
154 else if(isU) {
155 rQU.Insert(*sit);
156 rHioConstraint.SetQU(*sit);
157 }
158 }
159 }
160
161 if(localResult) rReportStr.append("##### Condition (ii) passed.\n");
162 // In case of failing condition (ii) further inspection is omitted, as too many consecutive faults are expected.
163 else {
164 rReportStr.append("##### fail: found states with undecidable attribute:\n");
165 rReportStr.append(locErrStSet.ToString()+"\n");
166 locErrStSet.Clear();
167 rReportStr.append("##### Condition (ii) failed.\n");
168 rReportStr.append("########## Termination due to crucial failure. ##########\n");
169 rReportStr.append("###################### No success. ######################\n");
170 rReportStr.append("#########################################################\n");
171 return false;
172 }
173 rReportStr.append("#####\n");
174 /*************************** Condition (ii) finished ****************************/
175
176
177 /*************************** Condition (iii) **********************/
178 localResult = true;
179 rReportStr.append("########## Condition (iii):\n");
180
181 //check if the initial state is a QY-state
182 if(!(initStates <= rQY)) {
183 rReportStr.append("##### fail: some init state(s) is (are) not a QY-state:\n");
184 locErrStSet=initStates-rQY;
185 rReportStr.append(locErrStSet.ToString()+"\n");
186 rErrStSet.InsertSet(locErrStSet);
187 locErrStSet.Clear();
188 localResult = false;
189 finalResult = false;
190 }
191 if(localResult) rReportStr.append("##### Condition (iii) passed.\n");
192 else rReportStr.append("##### Condition (iii) failed.\n");
193 rReportStr.append("#####\n");
194
195 /*************************** Condition (iii) finished ***************************/
196
197
198 /*************************** Condition (iv) ***********************/
199 localResult = true;
200 rReportStr.append("########## Condition (iv):\n");
201
202 // Y-events have to lead to a QU-state
203 for(sit = rQY.Begin(); sit != rQY.End(); ++sit) {
204 for(tit = rHioConstraint.TransRelBegin(*sit); tit != rHioConstraint.TransRelEnd(*sit); ++tit) {
205 // Y-event to QU-state
206 if( (rHioConstraint.IsY(tit->Ev) && !rQU.Exists(tit->X2)) ) {
207 // add transition to error transition set
208 locErrTrSet.Insert(*tit);
209 rErrTrSet.Insert(*tit);
210 finalResult = false;
211 localResult = false;
212 }
213 }
214 }
215
216 if(localResult) rReportStr.append("##### Condition (iv) passed.\n");
217 else {
218 rReportStr.append("##### fail: found Y-transitions leading to wrong states:\n");
219 rReportStr.append(locErrTrSet.ToString()+"\n");
220 locErrTrSet.Clear();
221 rReportStr.append("##### Condition (iv) failed.\n");
222 }
223 rReportStr.append("#####\n");
224 /*************************** Condition (iv) finished ****************************/
225
226
227 /*************************** Condition (v) ************************/
228 localResult = true;
229 rReportStr.append("########## Condition (v):\n");
230
231 // U-events have to lead to a QY-state
232 for(sit = rQU.Begin(); sit != rQU.End(); ++sit) {
233 for(tit = rHioConstraint.TransRelBegin(*sit); tit != rHioConstraint.TransRelEnd(*sit); ++tit) {
234 if(!rQY.Exists(tit->X2)) {
235 locErrTrSet.Insert(*tit);
236 rErrTrSet.Insert(*tit);
237 finalResult = false;
238 localResult = false;
239 }
240 }
241 }
242
243 if(localResult) rReportStr.append("##### Condition (v) passed.\n");
244 else {
245 rReportStr.append("##### fail: found U-transitions leading to wrong states:\n");
246 rReportStr.append(locErrTrSet.ToString()+"\n");
247 locErrTrSet.Clear();
248 rReportStr.append("##### Condition (v) failed.\n");
249 }
250 rReportStr.append("#####\n");
251 /*************************** Condition (v) finished *****************************/
252
253
254 /*************************** Condition (vi) **********************/
255 localResult = true;
256 rReportStr.append("########## Condition (vi):\n");
257
258 // Y must be free in QY-states
259 for(sit = rQY.Begin(); sit != rQY.End(); ++sit) {
260
261 if(!(y <= rHioConstraint.ActiveEventSet(*sit))) {
262 locErrStSet.Insert(*sit);
263 rErrStSet.Insert(*sit);
264 finalResult = false;
265 localResult = false;
266 }
267 }
268
269 if(localResult) rReportStr.append("##### Condition (vi) passed.\n");
270 else {
271 rReportStr.append("##### fail: found QY-states with inactive Y-events:\n");
272 rReportStr.append(locErrStSet.ToString()+"\n");
273 locErrStSet.Clear();
274 rReportStr.append("##### Condition (vi) failed.\n");
275 }
276 rReportStr.append("#####\n");
277 /*************************** Condition (vi) finished ***************************/
278
279
280 /*************************** Condition (vii) ************************/
281 localResult = true;
282 rReportStr.append("########## Condition (vii):\n");
283
284 // found dead ends?
285 if(!deadEnds.Empty()) {
286 finalResult = false;
287 localResult = false;
288 rErrStSet.InsertSet(deadEnds);
289 rReportStr.append("##### fail: found dead ends:\n");
290 rReportStr.append(deadEnds.ToString()+"\n");
291 deadEnds.Clear();
292 rReportStr.append("##### Condition (vii) failed.\n");
293 }
294 rReportStr.append("##### Condition (vii) passed.\n");
295 /*************************** Condition (vii) finished *****************************/
296
297
298 /*************************** Condition (viii) ***********************/
299 localResult = true;
300 rReportStr.append("########## Condition (viii):\n");
301
302 // Qm==Q?
303 if(!(accessibleStates<=rHioConstraint.MarkedStates())) {
304 finalResult = false;
305 localResult = false;
306 }
307
308 if(localResult) rReportStr.append("##### Condition (viii) passed.\n");
309 else {
310 rReportStr.append("##### fail: not all accessible states are marked:\n");
311 locErrStSet=accessibleStates - rHioConstraint.MarkedStates();
312 rErrStSet.InsertSet(locErrStSet);
313 rReportStr.append(locErrStSet.ToString()+"\n");
314 locErrStSet.Clear();
315 rReportStr.append("##### Condition (viii) failed.\n");
316 }
317 rReportStr.append("#####\n");
318 /*************************** Condition (viii) finished ****************************/
319
320
321 /*************************** Condition (ix) ************************/
322 rReportStr.append("########## Condition (ix):\n");
323
324 // make accessible if necessary
325 if(!rHioConstraint.IsAccessible()) {
326 rHioConstraint.Accessible();
327 rReportStr.append("##### warning: non-accessible states have been removed.\n");
328 rReportStr.append("##### Condition (ix) repaired.\n");
329 }
330 else rReportStr.append("##### Condition (ix) passed.\n");
331 /*************************** Condition (ix) finished *****************************/
332
333
334
335 /*************************** Final Result ************************/
336
337 rReportStr.append("##################### Final result: #####################\n");
338 if(finalResult) {
339 rReportStr.append("############ Generator is in HioConstraintForm. ###########\n");
340 rReportStr.append("#########################################################\n");
341 return true;
342 }
343 else {
344 rReportStr.append("############## Generator is NOT in HioConstraintForm. ##############\n");
345 rReportStr.append("#########################################################\n");
346 return false;
347 }
348
349}// END OF IsHioConstraintForm()
350
351//IsHioConstraintForm wrapper functions
352bool IsHioConstraintForm(HioConstraint& rHioConstraint, std::string& rReportStr)
353{
354 StateSet rQY, rQU;
355 EventSet rErrEvSet;
356 TransSet rErrTrSet;
357 StateSet rErrStSet;
358
359 return IsHioConstraintForm(rHioConstraint, rQY, rQU, rErrEvSet, rErrTrSet, rErrStSet,rReportStr);
360}
361
363{
364 StateSet rQY, rQU;
365 EventSet rErrEvSet;
366 TransSet rErrTrSet;
367 StateSet rErrStSet;
368 std::string rReportStr;
369
370 return IsHioConstraintForm(rHioConstraint, rQY, rQU, rErrEvSet, rErrTrSet, rErrStSet, rReportStr);
371}
372
373// rti function interface
374void HioStatePartition(HioConstraint& rHioConstraint) {
375 IsHioConstraintForm(rHioConstraint);
376}
377
378
379
380} // end namespace
#define FD_DF(message)
const std::string & Name(void) const
bool IsU(Idx index) const
bool IsY(Idx index) const
EventSet UEvents(void) const
EventSet YEvents(void) const
bool Insert(const Transition &rTransition)
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
const StateSet & MarkedStates(void) const
EventSet ActiveEventSet(Idx x1) const
const StateSet & InitStates(void) const
TransSet::Iterator TransRelBegin(void) const
bool IsAccessible(void) const
StateSet AccessibleSet(void) const
TransSet::Iterator TransRelEnd(void) const
bool IsDeterministic(void) const
bool Empty(void) const
bool Exists(const T &rElem) const
virtual void Clear(void)
Iterator End(void) const
virtual void InsertSet(const TBaseSet &rOtherSet)
Iterator Begin(void) const
Idx Size(void) const
void HioStatePartition(HioConstraint &rHioConstraint)
bool IsHioConstraintForm(HioConstraint &rHioConstraint, StateSet &rQY, StateSet &rQU, EventSet &rErrEvSet, TransSet &rErrTrSet, StateSet &rErrStSet, std::string &rReportStr)

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