hio_environment.cpp
Go to the documentation of this file.
1 /** @file hio_environment.cpp Generator with I/O-environment 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_environment.h"
12 
13 namespace faudes {
14 
15 // IsHioEnvironmentForm()
16 bool IsHioEnvironmentForm(HioEnvironment& rHioEnvironment,
17  StateSet& rQYe,
18  StateSet& rQUe,
19  StateSet& rQUl,
20  StateSet& rQYlUe,
21  EventSet& rErrEvSet,
22  TransSet& rErrTrSet,
23  StateSet& rErrStSet,
24  std::string& rReportStr)
25  {
26  FD_DF("IsHioEnvironmentForm("<< rHioEnvironment.Name() << ",...)");
27 
28  // prepare results
29  rQYe.Clear();
30  rQUe.Clear();
31  rQUl.Clear();
32  rQYlUe.Clear();
33 
34  rErrEvSet.Clear();
35  rErrEvSet.Name("rErrEvSet");
36 
37  rErrTrSet.Clear();
38  rErrTrSet.Name("rErrTrSet");
39 
40  rErrStSet.Clear();
41  rErrStSet.Name("rErrStSet");
42 
43  // used to locally store error states/transitions on each condition
44  StateSet locErrStSet;
45  TransSet locErrTrSet;
46 
47  rReportStr.clear();
48 
49  // meant to be set false on violation of any condition:
50  bool finalResult = true;
51  // used to locally store result on each condition
52  bool localResult = true;
53 
54  // helpers
55 
56  EventSet ye = rHioEnvironment.YeEvents();
57  EventSet ue = rHioEnvironment.UeEvents();
58  EventSet yl = rHioEnvironment.YlEvents();
59  EventSet ul = rHioEnvironment.UlEvents();
60 
61  StateSet initStates = rHioEnvironment.InitStates();
62  StateSet accessibleStates = rHioEnvironment.AccessibleSet();
63  StateSet deadEnds;
64 
65  EventSet::Iterator evit;
66  StateSet::Iterator sit;
68 
69  // Info string header
70  rReportStr.append("#########################################################\n");
71  rReportStr.append("########## IsHioEnvironmentForm("+rHioEnvironment.Name()+",...) - test results:\n");
72 
73  /**************************** Precondition: determinism ***********************/
74  // HioEnvironment must be deterministic
75  if(!rHioEnvironment.IsDeterministic()){
76  rReportStr.append("##### fail: generator is not deterministic!\n");
77  if(initStates.Size()>1) {
78  rErrStSet = initStates;
79  rReportStr.append("##### (amongst others, there is more than one initial state)\n");
80  }
81  finalResult = false;
82  }
83 
84 
85  rReportStr.append("#####\n");
86 
87  // test all conditions verifying I/O-environment form:
88 
89  /**************************** Condition (i) ***********************/
90  localResult = true;
91  rReportStr.append("########## Condition (i):\n");
92 
93  //YE, UE, YL, UL nonempty?
94  if (ye.Empty()) {
95  rReportStr.append("##### fail: empty YE alphabet.\n");
96  localResult=false;
97  finalResult = false;
98  }
99  if (ue.Empty()) {
100  rReportStr.append("##### fail: empty UE alphabet.\n");
101  localResult=false;
102  finalResult = false;
103  }
104  if (yl.Empty()) {
105  rReportStr.append("##### fail: empty YL alphabet.\n");
106  localResult=false;
107  finalResult = false;
108  }
109  if (ul.Empty()) {
110  rReportStr.append("##### fail: empty UL alphabet.\n");
111  localResult=false;
112  finalResult = false;
113  }
114 
115  // check for disjoint eventsets YE, YL, UE, UL and for
116  // YE u YL u UE u UL == Sigma, ie unique HioEventFlags.
117  // note: testing disjoint E- and L-Alphabet is sufficient
118  // as properties U and Y are exclusive by construltion.
119 
120  rErrEvSet=(rHioEnvironment.EEvents()*rHioEnvironment.LEvents()) + (rHioEnvironment.Alphabet()-rHioEnvironment.EEvents()-rHioEnvironment.LEvents());
121 
122  // In case of failing condition (i) further inspection is omitted, as too many consecutive faults are expected.
123  if(!rErrEvSet.Empty()){
124  rReportStr.append("##### fail: found events with missing or ambiguous attribute:\n");
125  rReportStr.append(rErrEvSet.ToString()+"\n");
126  rReportStr.append("##### Condition (i) failed.\n");
127  rReportStr.append("########## Termination due to crucial failure. ##########\n");
128  rReportStr.append("#########################################################\n");
129  return false;
130  }
131  if(localResult) rReportStr.append("##### Condition (i) passed.\n");
132  else rReportStr.append("##### Condition (i) failed.\n");
133  rReportStr.append("#####\n");
134  /*************************** Condition (i) finished *****************************/
135 
136 
137  /*************************** Condition (ii) ***********************/
138  localResult = true;
139  rReportStr.append("########## Condition (ii):\n");
140 
141  // Check if in states QUl, QYlUe, QUe and QYe only UL-, YL-/UE-, UE and YE-events are active, respectively.
142  // Also, dead ends are stored for condition (xi)
143  for(sit = accessibleStates.Begin(); sit != accessibleStates.End(); ++sit) {
144 
145  bool isUl = false;
146  bool isYlUe = false;
147  bool isUe = false;
148  bool isYe = false;
149  bool goodState = true;
150 
151  EventSet activeEv = rHioEnvironment.ActiveEventSet(*sit);
152 
153  if(activeEv.Empty()) {
154  //dead ends violate condition (xi)
155  deadEnds.Insert(*sit);
156  }
157  else {
158 
159  // get attribute of first event and compare with remaining events
160  evit = activeEv.Begin();
161  isUl = rHioEnvironment.IsUl(*evit);
162  isYlUe = rHioEnvironment.IsYl(*evit); // YlEvents can only be active in YlUe states
163  isUe = rHioEnvironment.IsUe(*evit); // is reset (and YlUe is set) in case YlEvent is found in activeEv
164  isYe = rHioEnvironment.IsYe(*evit);
165 
166  for(; evit != activeEv.End(); evit++) {
167  if( (isUl && !rHioEnvironment.IsUl(*evit)) ||
168  ((isYlUe||isUe) && (!rHioEnvironment.IsYl(*evit) && (!rHioEnvironment.IsUe(*evit)))) ||
169  (isYe && !rHioEnvironment.IsYe(*evit)) ){
170  goodState = false;
171  localResult = false;
172  finalResult = false;
173  // add state to error set, go to next state
174  locErrStSet.Insert(*sit);
175  rErrStSet.Insert(*sit);
176  break; // leave loop over active events
177  }
178  if(isUe && rHioEnvironment.IsYl(*evit)) {
179  isYlUe = true;
180  isUe = false;
181  }
182  }
183 
184  activeEv.Clear();
185 
186  if(!goodState) continue; // if undecidable go on with next state
187 
188  // set state attribute
189  if(isUl) {
190  rQUl.Insert(*sit);
191  rHioEnvironment.SetQUl(*sit);
192  }
193  else if(isYlUe) {
194  rQYlUe.Insert(*sit);
195  rHioEnvironment.SetQYlUe(*sit);
196  }
197  else if(isUe) {
198  rQUe.Insert(*sit);
199  rHioEnvironment.SetQUe(*sit);
200  }
201  else if(isYe){
202  rQYe.Insert(*sit);
203  rHioEnvironment.SetQYe(*sit);
204  }
205  }
206  }
207 
208  if(localResult) rReportStr.append("##### Condition (ii) passed.\n");
209  // In case of failing condition (ii) further inspection is omitted, as too many consecutive faults are expected.
210  else {
211  rReportStr.append("##### fail: found states with undecidable attribute:\n");
212  rReportStr.append(locErrStSet.ToString()+"\n");
213  locErrStSet.Clear();
214  rReportStr.append("##### Condition (ii) failed.\n");
215  rReportStr.append("########## Termination due to crulial failure. ##########\n");
216  rReportStr.append("###################### No sulcess. ######################\n");
217  rReportStr.append("#########################################################\n");
218  return false;
219  }
220  rReportStr.append("#####\n");
221  /*************************** Condition (ii) finished ****************************/
222 
223 
224  /*************************** Condition (iii) **********************/
225  localResult = true;
226  rReportStr.append("########## Condition (iii):\n");
227 
228  //check if the initial state is a QYe-state
229  if(!(initStates <= rQYe)) {
230  rReportStr.append("##### fail: some init state(s) is (are) not a QYe-state:\n");
231  locErrStSet=initStates-rQYe;
232  rReportStr.append(locErrStSet.ToString()+"\n");
233  rErrStSet.InsertSet(locErrStSet);
234  locErrStSet.Clear();
235  localResult = false;
236  finalResult = false;
237  }
238  if(localResult) rReportStr.append("##### Condition (iii) passed.\n");
239  else rReportStr.append("##### Condition (iii) failed.\n");
240  rReportStr.append("#####\n");
241 
242  /*************************** Condition (iii) finished ***************************/
243 
244 
245  /*************************** Condition (iv) ***********************/
246  localResult = true;
247  rReportStr.append("########## Condition (iv):\n");
248 
249  // YE-events have to lead to a QYlUe or a QUe-state
250  for(sit = rQYe.Begin(); sit != rQYe.End(); ++sit) {
251  for(tit = rHioEnvironment.TransRelBegin(*sit); tit != rHioEnvironment.TransRelEnd(*sit); ++tit) {
252  // YE-event to QYlUe or QUe-state
253  if ( !( rQYlUe.Exists(tit->X2) || rQUe.Exists(tit->X2) ) ) {
254  // add transition to error transition set
255  rErrTrSet.Insert(*tit);
256  locErrTrSet.Insert(*tit);
257  finalResult = false;
258  localResult = false;
259  }
260  }
261  }
262 
263  if(localResult) rReportStr.append("##### Condition (iv) passed.\n");
264  else {
265  rReportStr.append("##### fail: found YE-transitions leading to wrong states:\n");
266  rReportStr.append(locErrTrSet.ToString()+"\n");
267  locErrTrSet.Clear();
268  rReportStr.append("##### Condition (iv) failed.\n");
269  }
270  rReportStr.append("#####\n");
271  /*************************** Condition (iv) finished ****************************/
272 
273 
274  /*************************** Condition (v) ************************/
275  localResult = true;
276  rReportStr.append("########## Condition (v):\n");
277 
278  // UE-events have to lead to a QYe-state
279  for(sit = rQUe.Begin(); sit != rQUe.End(); ++sit) {
280  for(tit = rHioEnvironment.TransRelBegin(*sit); tit != rHioEnvironment.TransRelEnd(*sit); ++tit) {
281  if(!rQYe.Exists(tit->X2)) {
282  rErrTrSet.Insert(*tit);
283  locErrTrSet.Insert(*tit);
284  finalResult = false;
285  localResult = false;
286  }
287  }
288  }
289 
290  if(localResult) rReportStr.append("##### Condition (v) passed.\n");
291  else {
292  rReportStr.append("##### fail: found UE-transitions leading to wrong states:\n");
293  rReportStr.append(locErrTrSet.ToString()+"\n");
294  locErrTrSet.Clear();
295  rReportStr.append("##### Condition (v) failed.\n");
296  }
297  rReportStr.append("#####\n");
298  /*************************** Condition (v) finished *****************************/
299 
300 
301  /*************************** Condition (vi) ***********************/
302  localResult = true;
303  rReportStr.append("########## Condition (vi):\n");
304 
305  // From QYlUe states, UE-events have to lead to a QYe-state and YL-events
306  // have to lead to a UL-state
307  for(sit = rQYlUe.Begin(); sit != rQYlUe.End(); ++sit) {
308  for(tit = rHioEnvironment.TransRelBegin(*sit); tit != rHioEnvironment.TransRelEnd(*sit); ++tit) {
309 
310  if( (rHioEnvironment.IsUe(tit->Ev) && !rQYe.Exists(tit->X2)) ||
311  (rHioEnvironment.IsYl(tit->Ev) && !rQUl.Exists(tit->X2)) ){
312  locErrTrSet.Insert(*tit);
313  rErrTrSet.Insert(*tit);
314  finalResult = false;
315  localResult = false;
316  }
317  }
318  }
319 
320  if(localResult) rReportStr.append("##### Condition (vi) passed.\n");
321  else {
322  rReportStr.append("##### fail: found YL- or UE-transitions leading to wrong states:\n");
323  rReportStr.append(locErrTrSet.ToString()+"\n");
324  locErrTrSet.Clear();
325  rReportStr.append("##### Condition (vi) failed.\n");
326  }
327  rReportStr.append("#####\n");
328  /*************************** Condition (vi) finished ****************************/
329 
330 
331  /*************************** Condition (vii) ************************/
332  localResult = true;
333  rReportStr.append("########## Condition (vii):\n");
334 
335  // UL-events have to lead to a QUe-state
336  for(sit = rQUl.Begin(); sit != rQUl.End(); ++sit) {
337  for(tit = rHioEnvironment.TransRelBegin(*sit); tit != rHioEnvironment.TransRelEnd(*sit); ++tit) {
338  if(!rQUe.Exists(tit->X2)) {
339  locErrTrSet.Insert(*tit);
340  rErrTrSet.Insert(*tit);
341  finalResult = false;
342  localResult = false;
343  }
344  }
345  }
346 
347  if(localResult) rReportStr.append("##### Condition (vii) passed.\n");
348  else {
349  rReportStr.append("##### fail: found UL-transitions leading to wrong states, see rErrTrSet:\n");
350  rReportStr.append(locErrTrSet.ToString()+"\n");
351  locErrTrSet.Clear();
352  rReportStr.append("##### Condition (vii) failed.\n");
353  }
354  rReportStr.append("#####\n");
355  /*************************** Condition (vii) finished *****************************/
356 
357 
358  /*************************** Condition (viii) **********************/
359  localResult = true;
360  rReportStr.append("########## Condition (viii):\n");
361 
362  // UL must be free in QUl-states
363  for(sit = rQUl.Begin(); sit != rQUl.End(); ++sit) {
364 
365  if(!(ul <= rHioEnvironment.ActiveEventSet(*sit))) {
366  locErrStSet.Insert(*sit);
367  rErrStSet.Insert(*sit);
368  finalResult = false;
369  localResult = false;
370  }
371  }
372 
373  if(localResult) rReportStr.append("##### Condition (viii) passed.\n");
374  else {
375  rReportStr.append("##### fail: found QUl-states with inactive UL-events:\n");
376  rReportStr.append(locErrStSet.ToString()+"\n");
377  locErrStSet.Clear();
378  rReportStr.append("##### Condition (viii) failed.\n");
379  }
380  rReportStr.append("#####\n");
381  /*************************** Condition (viii) finished ***************************/
382 
383 
384  /*************************** Condition (ix) **********************/
385  localResult = true;
386  rReportStr.append("########## Condition (ix):\n");
387 
388  // YE must be free in QYe-states
389  for(sit = rQYe.Begin(); sit != rQYe.End(); ++sit) {
390 
391  if(!(ye <= rHioEnvironment.ActiveEventSet(*sit))) {
392  locErrStSet.Insert(*sit);
393  rErrStSet.Insert(*sit);
394  finalResult = false;
395  localResult = false;
396  }
397  }
398 
399  if(localResult) rReportStr.append("##### Condition (ix) passed.\n");
400  else {
401  rReportStr.append("##### fail: found QYe-states with inactive YE-events:\n");
402  rReportStr.append(locErrStSet.ToString()+"\n");
403  locErrStSet.Clear();
404  rReportStr.append("##### Condition (ix) failed.\n");
405  }
406  rReportStr.append("#####\n");
407  /*************************** Condition (ix) finished ***************************/
408 
409 
410  /*************************** Condition (x) ***********************/
411  localResult = true;
412  rReportStr.append("########## Condition (x):\n");
413 
414  // Qm==Q?
415  if(!(accessibleStates<=rHioEnvironment.MarkedStates())) {
416  finalResult = false;
417  localResult = false;
418  }
419 
420  if(localResult) rReportStr.append("##### Condition (x) passed.\n");
421  else {
422  rReportStr.append("##### fail: not all accessible states are marked, see rErrStSet:\n");
423  locErrStSet= accessibleStates - rHioEnvironment.MarkedStates();
424  rErrStSet.InsertSet(locErrStSet);
425  rReportStr.append(locErrStSet.ToString()+"\n");
426  locErrStSet.Clear();
427  rReportStr.append("##### Condition (x) failed.\n");
428  }
429  rReportStr.append("#####\n");
430  /*************************** Condition (x) finished ****************************/
431 
432 
433  /*************************** Condition (xi) ************************/
434  localResult = true;
435  rReportStr.append("########## Condition (xi):\n");
436 
437  // found dead ends?
438  if(!deadEnds.Empty()) {
439  finalResult = false;
440  localResult = false;
441  rErrStSet.InsertSet(deadEnds);
442  rReportStr.append("##### fail: found dead ends:\n");
443  rReportStr.append(deadEnds.ToString()+"\n");
444  deadEnds.Clear();
445  rReportStr.append("##### Condition (xi) failed.\n");
446  }
447  rReportStr.append("##### Condition (xi) passed.\n");
448  /*************************** Condition (xi) finished *****************************/
449 
450 
451  /*************************** Condition (xii) ************************/
452  rReportStr.append("########## Condition (xii):\n");
453 
454  // make accessible if necessary
455  if(!rHioEnvironment.IsAccessible()) {
456  rHioEnvironment.Accessible();
457  rReportStr.append("##### warning: non-accessible states have been removed.\n");
458  rReportStr.append("##### Condition (xii) repaired.\n");
459  }
460  else rReportStr.append("##### Condition (xii) passed.\n");
461  /*************************** Condition (xii) finished *****************************/
462 
463 
464 
465  /*************************** Final result ****************************/
466  rReportStr.append("##################### Final result: #####################\n");
467  if(finalResult) {
468  rReportStr.append("######### Generator is in HioEnvironmentForm. #########\n");
469  rReportStr.append("#########################################################\n");
470  return true;
471  }
472  else {
473  rReportStr.append("########### Generator is NOT in HioEnvironmentForm. ###########\n");
474  rReportStr.append("#########################################################\n");
475  return false;
476  }
477 
478 }// END OF IsHioEnvironmentForm()
479 
480 
481 //IsHioEnvironmentForm wrapper functions
482 bool IsHioEnvironmentForm(HioEnvironment& rHioEnvironment,std::string& rReportStr)
483 {
484  StateSet QYe, QUe, QUl, QYlUe;
485  EventSet ErrEvSet;
486  TransSet ErrTrSet;
487  StateSet ErrStSet;
488 
489  return IsHioEnvironmentForm(rHioEnvironment, QYe, QUe, QUl, QYlUe, ErrEvSet, ErrTrSet, ErrStSet, rReportStr);
490 }
491 
492 // rti function interface
493 bool IsHioEnvironmentForm(HioEnvironment& rHioEnvironment)
494 {
495  StateSet QYe, QUe, QUl, QYlUe;
496  EventSet ErrEvSet;
497  TransSet ErrTrSet;
498  StateSet ErrStSet;
499  std::string ReportStr;
500 
501  return IsHioEnvironmentForm(rHioEnvironment, QYe, QUe, QUl, QYlUe, ErrEvSet, ErrTrSet, ErrStSet, ReportStr);
502 }
503 
504 // rti function interface
505 void HioStatePartition(HioEnvironment& rHioEnvironment) {
506  IsHioEnvironmentForm(rHioEnvironment);
507 }
508 
509 
510 } // end namespace
#define FD_DF(message)
EventSet UeEvents(void) const
bool IsUl(Idx index) const
EventSet YeEvents(void) const
bool IsYe(Idx index) const
EventSet LEvents(void) const
bool IsYl(Idx index) const
EventSet UlEvents(void) const
bool IsUe(Idx index) const
EventSet YlEvents(void) const
EventSet EEvents(void) const
bool Insert(const Transition &rTransition)
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Definition: cfl_transset.h:273
const TaEventSet< EventAttr > & Alphabet(void) const
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Definition: cfl_types.cpp:170
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
void Name(const std::string &rName)
TransSet::Iterator TransRelEnd(void) const
bool IsDeterministic(void) const
bool Empty(void) const
Definition: cfl_baseset.h:1841
bool Exists(const T &rElem) const
Definition: cfl_baseset.h:2132
virtual void Clear(void)
Definition: cfl_baseset.h:1919
Iterator End(void) const
Definition: cfl_baseset.h:1913
virtual void InsertSet(const TBaseSet &rOtherSet)
Definition: cfl_baseset.h:2004
Iterator Begin(void) const
Definition: cfl_baseset.h:1908
const std::string & Name(void) const
Definition: cfl_baseset.h:1772
Idx Size(void) const
Definition: cfl_baseset.h:1836
void HioStatePartition(HioConstraint &rHioConstraint)
bool IsHioEnvironmentForm(HioEnvironment &rHioEnvironment, StateSet &rQYe, StateSet &rQUe, StateSet &rQUl, StateSet &rQYlUe, EventSet &rErrEvSet, TransSet &rErrTrSet, StateSet &rErrStSet, std::string &rReportStr)

libFAUDES 2.33c --- 2025.05.15 --- c++ api documentaion by doxygen