hio_module.cpp
Go to the documentation of this file.
1 /** @file hio_module.cpp Class describing the I/O based hierarchy */
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_module.h"
12 
13 namespace faudes {
14 
15  // Constructor
17  }
18 
19 
20  // Copy constructor
21  HioModule::HioModule(const HioModule& rOtherHioModule) {
22  mOpConstr = rOtherHioModule.OpConstr();
23  mPlant = rOtherHioModule.Plant();
24  mController = rOtherHioModule.Controller();
25  mChildren = rOtherHioModule.Children();
26  mEnvironment = rOtherHioModule.Environment();
27  mEnvConstr = rOtherHioModule.EnvConstr();
28  TypeHioModule(rOtherHioModule.TypeHioModule());
29  mIndex = rOtherHioModule.Index();
30  mName = rOtherHioModule.Name();
31  Position(rOtherHioModule.Xpos(), rOtherHioModule.Ypos());
32  }
33 
34  //HioModule::Clear()
36  {
37  mEnvConstr.Clear();
38  mOpConstr.Clear();
40  mPlant.Clear();
41  mIndex = 0;
42  for (int i=0; i<5; i++)
43  mType[i] = 0;
44  mXpos = 0;
45  mYpos = 0;
46  mName = "";
47  mChildren.clear();
48  }
49 
50  // HioModule::Name()
51  std::string HioModule::Name() const {
52  return mName;
53  }
54 
55  // HioModule::Name(rName)
56  void HioModule::Name(const std::string& rName){
57  mName = rName;
58  }
59 
60  // HioModule::Index()
62  return mIndex;
63  }
64 
65  // HioModule::Index(Index)
66  void HioModule::Index(const Idx Index){
67  mIndex = Index;
68  }
69 
70  // HioModule::OpConstr(rOpConstr)
71  void HioModule::OpConstr(const HioConstraint& rOpConstr){
72  mOpConstr = rOpConstr;
73  }
74 
75  // HioModule::OpConstr()
77  return mOpConstr;
78  }
79 
80  // HioModule::Plant(HioPlant)
81  void HioModule::Plant(const HioPlant& rHioPlant){
82  mPlant = rHioPlant;
83  }
84 
85  // HioModule::Plant()
87  return mPlant;
88  }
89 
90  // HioModule::Controller(HioController)
91  void HioModule::Controller(const HioController& rHioController){
92  mController = rHioController;
93  }
94 
95  // HioModule::Controller()
97  return mController;
98  }
99 
100  // HioModule::Children(rChildren)
101  void HioModule::Children(const std::vector<HioModule*>& rChildren) {
102  mChildren = rChildren;
103  }
104 
105  // HioModule::Children
106  std::vector<HioModule*> HioModule::Children() const {
107  return mChildren;
108  }
109 
110  // HioModule::Environment(HioEnvironment)
111  void HioModule::Environment(const HioEnvironment& rHioEnvironment){
112  mEnvironment = rHioEnvironment;
113  }
114 
115  // HioModule::Environment()
117  return mEnvironment;
118  }
119 
120  // HioModule::EnvConstr(rEnvConstr)
121  void HioModule::EnvConstr(const HioConstraint& rEnvConstr){
122 
123  mEnvConstr = rEnvConstr;
124  }
125 
126  // HioModule::EnvConstr()
128  return mEnvConstr;
129  }
130 
131  // HioModule::InsChild(rChild)
133  mChildren.push_back(rChild);
134  }
135 
136  /////////////////////////////////////////////////////////////////////
137  // from here to end of file: design specific functions by M.Musunoi
138  // will be outsourced to something like hiodesign.cpp
139 
140  // function to set mXpos and mYpos of the HioModule
141  void HioModule::Position(const int Xpos, const int Ypos){
142 
143  mXpos = Xpos;
144  mYpos = Ypos;
145  }
146 
147  // function to set the type of HioModule
148  void HioModule::TypeHioModule(int type[5]){
149 
150  for (int i=0; i<=4; i++)
151  mType[i] = type[i];
152  }
153 
154 
155 
156  //ReadHioPlant: this function reads the models from the given library and
157  //creates a general IOModulX which can be afterwards personalised.
158  void HioModule::ReadHioPlant(const std::string path)
159  {
160 
163 
164  std::string myType;
165 
166  //read and set the IO Plant
167  std::string HioPlantFile = path+"plant.gen";
168  mPlant.Read(HioPlantFile.c_str());
169 
170  //searching for the token reader "Type", and set the type of the HioPlant
171  TokenReader tReader(HioPlantFile.c_str());
172  Token token;
173  token.SetString("Type");
174  tReader.ReadBegin("Type");
175  while(tReader.Peek(token)) {
176  // break on end
177  if (token.Type() == Token::End) {
178  break;
179  }
180  myType = tReader.ReadString();
181  continue;
182  }
183 
184  //set mType
185  for(int i=0 ;i<=4;i++)
186  {
187  char tmpChar = myType.at(i);
188  std::stringstream Str;
189  Str << tmpChar;
190  int d;
191  Str >> d;
192 
193  mType[i] = d;
194  }
195 
196  //read and set the Operator-Constraint
197  std::string LpFile = path+"constrP.gen";
198  mOpConstr.Read(LpFile.c_str());
199 
200 
201  //load and set the Environment-Constraint
202  std::string LeFile = path+"constrE.gen";
203  mEnvConstr.Read(LeFile.c_str());
204 
205  } //end of ReadHioPlant()
206 
207 
208  //loadLibEnv: this function loads the model of interaction of IO-Plants with
209  //the environment and creates a general IOEnvironment.
210  void HioModule::ReadHioEnv(const std::string path)
211 
212  {
213  std::string EnvFile = path+"environment.gen";
214  mEnvironment.Read(EnvFile.c_str());
215  }
216 
217 
218  //AdjusTimedGenerator: this function converts a generator by renaming all events from
219  //"CBx_..." to "CBi_...";
221  const int i,
222  Generator& rResGen)
223  {
224  EventSet newAlph;
225  TransSet::Iterator tit;
226  StateSet::Iterator sit;
227  EventSet::Iterator evit;
228  std::string toSeti = ToStringInteger(i);
229  std::string toSet = "CB"+toSeti+"_";
230 
231 
232  //check if generator not already in converted form; if already converted, return
233  //sperk: throw exception?
234  for (evit = rOldGen.AlphabetBegin(); evit != rOldGen.AlphabetEnd(); ++evit)
235  {
236 
237  std::string oldName = rOldGen.Alphabet().SymbolicName(*evit);
238  //int loc1 = oldName.find(toSet, 0);
239  //if( loc1 != std::string::npos )
240  if( oldName.find(toSet, 0) != std::string::npos )
241  {
242  std::cout<<"At least one event already converted";
243  rResGen = rOldGen;
244  return;
245  }
246  }
247 
248  // first state to be inserted in the new, empty rResult generator
249  int state = 1;
250 
251  //rename events an insert the resulting alphabet in rResult
252  AdjustAlphabet(rOldGen.Alphabet(), i, newAlph);
253  rResGen.InjectAlphabet(newAlph);
254 
255  //insert states in rResult;
256  for (sit = rOldGen.StatesBegin(); sit != rOldGen.StatesEnd(); ++sit)
257  {
258  rResGen.InsMarkedState(ToStringInteger(state));
259  //if actual state also init state then mark it as init state in rResult too;
260  if(rOldGen.ExistsInitState(state))
261  rResGen.SetInitState(ToStringInteger(state));
262 
263  state++;
264  }
265 
266  //iterate through all states
267  for (sit = rOldGen.StatesBegin(); sit != rOldGen.StatesEnd(); ++sit)
268  {
269  //iterate through all transitions of the actual state; rename the events
270  //of each transition and insert the new transition in rResult
271  for (tit = rOldGen.TransRelBegin(*sit); tit != rOldGen.TransRelEnd(*sit); ++tit)
272  {
273  std::string oldName = rOldGen.EventName(tit->Ev);
274  int loc1 = oldName.find("_", 0);
275  std::string newName = oldName.erase(0,loc1+1);
276  newName = toSet + oldName;
277 
278  Idx idx_event = rResGen.EventIndex(newName);
279  rResGen.SetTransition(tit->X1, idx_event, tit->X2);
280  }
281  }
282 
283  } //END ADJUSTGENERATOR
284 
285 
286  // AdjustHioPlant(): convenience function (derived from AdjusTimedGenerator())to
287  // allow also the conversion of HioPlants
289  const HioPlant& rOldHioPlant,
290  const int i,
291  HioPlant& rResGen)
292  {
293  EventSet newAlph;
294  EventSet::Iterator evit;
295  TransSet::Iterator tit;
296  StateSet::Iterator sit;
297  std::string toSeti = ToStringInteger(i);
298  std::string toSet = "CB"+toSeti+"_";
299 
300  //check if generator not already in converted form
301  for (evit = rOldHioPlant.AlphabetBegin(); evit != rOldHioPlant.AlphabetEnd(); ++evit)
302  {
303 
304  std::string oldName = rOldHioPlant.Alphabet().SymbolicName(*evit);
305  //int loc1 = oldName.find(toSet, 0);
306  //if( loc1 != std::string::npos )
307  if( oldName.find(toSet, 0) != std::string::npos )
308  {
309  std::cout<<"At least one event already converted";
310  rResGen = rOldHioPlant;
311  return;
312  }
313  }
314  // first state to be inserted in the new, empty rResult generator
315  int state = 1;
316 
317  //rename events by preserving the events attributes
318  //Yp-Events
319  AdjustAlphabet(rOldHioPlant.YpEvents(), i, newAlph);
320  for(evit = newAlph.Begin(); evit != newAlph.End(); ++evit)
321  rResGen.InsYpEvent(*evit);
322  newAlph.Clear();
323 
324  //Up-Events
325  AdjustAlphabet(rOldHioPlant.UpEvents(), i, newAlph);
326  for(evit = newAlph.Begin(); evit != newAlph.End(); ++evit)
327  rResGen.InsUpEvent(*evit);
328  newAlph.Clear();
329 
330  //Ye-Events
331  AdjustAlphabet(rOldHioPlant.YeEvents(), i, newAlph);
332  for(evit = newAlph.Begin(); evit != newAlph.End(); ++evit)
333  rResGen.InsYeEvent(*evit);
334  newAlph.Clear();
335 
336  //Ue-Events
337  AdjustAlphabet(rOldHioPlant.UeEvents(), i, newAlph);
338  for(evit = newAlph.Begin(); evit != newAlph.End(); ++evit)
339  rResGen.InsUeEvent(*evit);
340  newAlph.Clear();
341 
342  //insert states in rResult;
343  for (sit = rOldHioPlant.StatesBegin(); sit != rOldHioPlant.StatesEnd(); ++sit)
344  {
345  rResGen.InsMarkedState(ToStringInteger(state));
346  //if actual state also init state then mark it as init state in rResult too;
347  if(rOldHioPlant.ExistsInitState(state))
348  rResGen.SetInitState(ToStringInteger(state));
349 
350  state++;
351  }
352  //iterate through all states
353  for (sit = rOldHioPlant.StatesBegin(); sit != rOldHioPlant.StatesEnd(); ++sit)
354  {
355  //iterate through all transitions of the actual state; rename the events
356  //of each transition and insert the new transition in rResult
357  for (tit = rOldHioPlant.TransRelBegin(*sit); tit != rOldHioPlant.TransRelEnd(*sit); ++tit)
358  {
359  std::string oldName = rOldHioPlant.EventName(tit->Ev);
360  int loc1 = oldName.find("_", 0);
361  std::string newName = oldName.erase(0,loc1+1);
362  newName = toSet + oldName;
363 
364  Idx idx_event = rResGen.EventIndex(newName);
365  rResGen.SetTransition(tit->X1, idx_event, tit->X2);
366  }
367  }
368  } //End of AdjustHioPlant()
369 
370 
371  // AdjustAlph(): this function converts an alphabet by renaming all events from
372  // "CBx_..." to "CBi_...";
373  // Warning: This function does not preserves the attributes of the events!
375  const EventSet& rOldAlph,
376  const int i,
377  EventSet& rResAlph)
378  {
379  EventSet::Iterator evit;
380  std::string toSeti = ToStringInteger(i);
381  std::string toSet = "CB"+toSeti+"_";
382 
383  //check if alphabet not already in converted form
384  for (evit = rOldAlph.Begin(); evit != rOldAlph.End(); ++evit)
385  {
386  std::string oldName = rOldAlph.SymbolicName(*evit);
387  //int loc1 = oldName.find(toSet, 0);
388  //if( loc1 != std::string::npos )
389  if( oldName.find(toSet, 0) != std::string::npos )
390  {
391  std::cout<<"At least one event already converted";
392  rResAlph = rOldAlph;
393  return;
394  }
395  }
396 
397  //iterate through the alphabet and adjust every event
398  for (evit = rOldAlph.Begin(); evit != rOldAlph.End(); ++evit)
399  {
400  std::string oldName = rOldAlph.SymbolicName(*evit);
401  int loc1 = oldName.find("_", 0);
402  std::string newName1 = oldName.erase(0,loc1+1);
403  std::string newName = toSet + oldName;
404 
405  rResAlph.Insert(newName);
406 
407  }
408  } //End of AdjustAlphabet
409 
410 
411  // AdjustEnvironmet: This function adjusts the master copy (IOEnviromntX) to
412  // the two IO-Plants.
414  const HioEnvironment& rHioEnvX,
415  const HioModule* rHioModule1,
416  const HioModule* rHioModule2,
417  HioEnvironment& rResEnv)
418  {
419  EventSet tmpAlph;
420  EventSet::Iterator evit;
421  StateSet::Iterator sit;
422  TransSet::Iterator tit;
423 
424 
425 
426  tmpAlph = rHioEnvX.Alphabet();
427  int leftId, rightId; //
428  int state = 1;
429  // strings to replace the standard event names: CBx_, CBy_, CBxy_
430  std::string toRepl_left, toRepl_right, toRepl_ext;
431 
432  // check the relative position of the 2 HioModule to each other and prepare
433  // the strings to be set, according to the Id of each IOMOdule
434  if (rHioModule1->Xpos() <= rHioModule2->Xpos())
435  {
436  //HioModule1 at the left of HioModule2
437  leftId = rHioModule1->Index();
438  toRepl_left = "CB"+ToStringInteger(leftId)+"_";
439 
440  rightId = rHioModule2->Index();
441  toRepl_right = "CB"+ToStringInteger(rightId)+"_";
442 
443  toRepl_ext = "CB"+ToStringInteger(leftId)+
444  ToStringInteger(rightId)+"_";
445  }
446  else
447  {
448  //HioModule1 at the right of HioModule2
449  leftId = rHioModule2->Index();
450  toRepl_left = "CB"+ToStringInteger(leftId)+"_";
451 
452  rightId = rHioModule1->Index();
453  toRepl_right = "CB"+ToStringInteger(rightId)+"_";
454 
455  toRepl_ext = "CB"+ToStringInteger(leftId)+
456  ToStringInteger(rightId)+"_";
457  }
458 
459  //check if generator not already in converted form
460  for (evit = rHioEnvX.AlphabetBegin(); evit != rHioEnvX.AlphabetEnd(); ++evit)
461  {
462 
463  std::string oldName = rHioEnvX.Alphabet().SymbolicName(*evit);
464  //int loc1 = oldName.find(toRepl_ext, 0);
465  //if( loc1 != std::string::npos )
466  if( oldName.find(toRepl_ext, 0) != std::string::npos )
467  {
468  std::cout<<"At least one event already converted";
469  rResEnv = rHioEnvX;
470  return;
471  }
472  }
473 
474  //**********************Adjust the Alphabet****************
475  //iterate through all events and replace
476  // CBx_-events with toRepl_left
477  // CBy_-events with toRepl_right
478  // CBxy_-events with toRepl_ext
479  for (evit = tmpAlph.Begin(); evit != tmpAlph.End(); ++evit)
480  {
481  //get actual event name
482  std::string eventName = tmpAlph.SymbolicName(*evit);
483 
484  // actual event is a "left-Plant" event? (Ye or Ue)
485  std::string::size_type loc1 = eventName.find("CBx_", 0);
486  if (loc1 != std::string::npos)
487  {
488  eventName.erase(0, 4);
489  std::string newEvent = toRepl_left+eventName;
490  //std::string newEvent = eventName.replace(0,toRepl_left.size(), toRepl_left);
491  if(rHioEnvX.IsYe(*evit))
492  {
493  rResEnv.InsYeEvent(newEvent);
494  }
495  else
496  {
497  rResEnv.InsUeEvent(newEvent);
498  }
499  }
500  else
501  {
502  // actual event is a "right-Plant" event?
503  std::string::size_type loc2 = eventName.find("CBy_", 0);
504  if (loc2 != std::string::npos)
505  {
506  eventName.erase(0, 4);
507  std::string newEvent = toRepl_right+eventName;
508  if(rHioEnvX.IsYe(*evit))
509  {
510  rResEnv.InsYeEvent(newEvent);
511  }
512  else
513  {
514  rResEnv.InsUeEvent(newEvent);
515  }
516  }
517 
518  else
519  {
520  // actual event is a "external interaction" event? (YL or UL)
521  std::string::size_type loc3 = eventName.find("CBxy_", 0);
522  if (loc3 != std::string::npos)
523  {
524  eventName.erase(0, 5);
525  std::string newEvent = toRepl_ext+eventName;
526  if(rHioEnvX.IsYl(*evit))
527  {
528  rResEnv.InsYlEvent(newEvent);
529  }
530  else
531  {
532  rResEnv.InsUlEvent(newEvent);
533  }
534  }
535 
536  }
537  }
538  }//*************************** End Adjust Alphabet***************
539 
540  // insert states into result generator
541  for (sit = rHioEnvX.StatesBegin(); sit != rHioEnvX.StatesEnd(); ++sit)
542  {
543  rResEnv.InsMarkedState(ToStringInteger(state));
544  //if actual state also init state then mark it as init state in rResEnv too;
545  if(rHioEnvX.ExistsInitState(state))
546  rResEnv.SetInitState(ToStringInteger(state));
547 
548  state++;
549  } //End Insert States
550 
551 
552  //***************************Adjust Transitions************************
553  // iterate through all states and all transitions. For every trasition check the
554  // event name, and rename it as described in the sequence "Adjust Alphabet"
555  for (sit = rHioEnvX.StatesBegin(); sit != rHioEnvX.StatesEnd(); ++sit)
556  {
557  //iterate through all transitions of the actuall state;
558  for (tit = rHioEnvX.TransRelBegin(*sit); tit != rHioEnvX.TransRelEnd(*sit); ++tit)
559  {
560  std::string eventName = rHioEnvX.EventName(tit->Ev);
561 
562  // actual event is a "left-Plant" event?
563  std::string::size_type loc1 = eventName.find("CBx_", 0);
564  if (loc1 != std::string::npos)
565  {
566  eventName.erase(0, 4);
567  std::string newEvent = toRepl_left+eventName;
568  eventName = newEvent;
569  }
570  else
571  {
572  // actual event is a "right-Plant" event?
573  std::string::size_type loc2 = eventName.find("CBy_", 0);
574  if (loc2 != std::string::npos)
575  {
576  eventName.erase(0, 4);
577  std::string newEvent = toRepl_right+eventName;
578  eventName = newEvent;
579  }
580  else
581  {
582  // actual event is a "external interaction" event?
583  std::string::size_type loc3 = eventName.find("CBxy_", 0);
584  if (loc3 != std::string::npos)
585  {
586  eventName.erase(0, 5);
587  std::string newEvent = toRepl_ext+eventName;
588  eventName = newEvent;
589  }
590  }
591  }
592 
593  // insert transition into result
594  Idx idx_event = rResEnv.EventIndex(eventName);
595  rResEnv.SetTransition(tit->X1, idx_event, tit->X2);
596  } // end for-loop over transition
597  } // end for-loop over states
598 
599  } // end of AdjustHioEnvironment()
600 
601 
602  // AdjustHioController: This function adjust an already computed IOController to
603  // apply with the two IO-Plants (that enforces a well-defined specification).
605  const HioController& rHioController,
606  const HioModule* rHioModule1,
607  const HioModule* rHioModule2,
608  HioController& rResEnv)
609  {
610  EventSet tmpAlph;
611  EventSet::Iterator evit;
612  StateSet::Iterator sit;
613  TransSet::Iterator tit;
614 
615  tmpAlph = rHioController.Alphabet();
616  int leftId, rightId; //
617  int state = 1;
618 
619  // strings to replace the standard event names: CBx_, CBy_, CBxy_
620  std::string toRepl_left, toRepl_right, toRepl_ext;
621 
622 
623  // check the relative position of the 2 HioModule to each other and prepare
624  // the strings to be set, according to the Id of each IOMOdule
625  if (rHioModule1->Xpos() <= rHioModule2->Xpos())
626  {
627  //HioModule1 at the left of HioModule2
628  leftId = rHioModule1->Index();
629  toRepl_left = "CB"+ToStringInteger(leftId)+"_";
630 
631  rightId = rHioModule2->Index();
632  toRepl_right = "CB"+ToStringInteger(rightId)+"_";
633 
634  toRepl_ext = "CB"+ToStringInteger(leftId)+
635  ToStringInteger(rightId)+"_";
636  }
637  else
638  {
639  //HioModule1 at the right of HioModule2
640  leftId = rHioModule2->Index();
641  toRepl_left = "CB"+ToStringInteger(leftId)+"_";
642 
643  rightId = rHioModule1->Index();
644  toRepl_right = "CB"+ToStringInteger(rightId)+"_";
645 
646  toRepl_ext = "CB"+ToStringInteger(leftId)+
647  ToStringInteger(rightId)+"_";
648  }
649 
650  //check if generator not already in converted form
651  for (evit = rHioController.AlphabetBegin(); evit != rHioController.AlphabetEnd(); ++evit)
652  {
653 
654  std::string oldName = rHioController.Alphabet().SymbolicName(*evit);
655  //int loc1 = oldName.find(toRepl_ext, 0);
656  //if( loc1 != std::string::npos )
657  if( oldName.find(toRepl_ext, 0) != std::string::npos )
658  {
659  std::cout<<"At least one event already converted";
660  rResEnv = rHioController;
661  return;
662  }
663  }
664 
665  //**********************Adjust the Alphabet****************
666  //iterate thru all events and replace
667  // CBx_-events with toRepl_left
668  // CBy_-events with toRepl_right
669  // CBxy_-events with toRepl_ext
670  for (evit = tmpAlph.Begin(); evit != tmpAlph.End(); ++evit)
671  {
672  //get actual event name
673  std::string eventName = tmpAlph.SymbolicName(*evit);
674 
675  // actual event is a "left-Plant" event?
676  std::string::size_type loc1 = eventName.find("CBx_", 0);
677  if (loc1 != std::string::npos)
678  {
679  eventName.erase(0, 4);
680  std::string newEvent = toRepl_left+eventName;
681  rResEnv.InsEvent(newEvent);
682  }
683  else
684  {
685  // actual event is a "right-Plant" event?
686  std::string::size_type loc2 = eventName.find("CBy_", 0);
687  if (loc2 != std::string::npos)
688  {
689  eventName.erase(0, 4);
690  std::string newEvent = toRepl_right+eventName;
691  rResEnv.InsEvent(newEvent);
692  }
693  else
694  {
695  // actual event is a "external interaction" event?
696  std::string::size_type loc3 = eventName.find("CBxy_", 0);
697  if (loc3 != std::string::npos)
698  {
699  eventName.erase(0, 5);
700  std::string newEvent = toRepl_ext+eventName;
701  rResEnv.InsEvent(newEvent);
702  }
703  }
704  }
705  }//*************************** End Adjust Alphabet***************
706 
707  // insert states into result generator
708  for (sit = rHioController.StatesBegin(); sit != rHioController.StatesEnd(); ++sit)
709  {
710  rResEnv.InsMarkedState(ToStringInteger(state));
711  //if actual state also init state then mark it as init state in rResEnv too;
712  if(rHioController.ExistsInitState(state))
713  rResEnv.SetInitState(ToStringInteger(state));
714 
715  state++;
716  } //End Insert States
717 
718 
719  //***************************Adjust Transitions************************
720  // iterate through all states and all transitions. For every trasition check the
721  // event name, and rename it as described in the sequence "Adjust Alphabet"
722  for (sit = rHioController.StatesBegin(); sit != rHioController.StatesEnd(); ++sit)
723  {
724  //iterate through all transitions of the actuall state;
725  for (tit = rHioController.TransRelBegin(*sit); tit != rHioController.TransRelEnd(*sit); ++tit)
726  {
727  std::string eventName = rHioController.EventName(tit->Ev);
728 
729  // actual event is a "left-Plant" event?
730  std::string::size_type loc1 = eventName.find("CBx_", 0);
731  if (loc1 != std::string::npos)
732  {
733  eventName.erase(0, 4);
734  std::string newEvent = toRepl_left+eventName;
735  eventName = newEvent;
736  }
737  else
738  {
739  // actual event is a "right-Plant" event?
740  std::string::size_type loc2 = eventName.find("CBy_", 0);
741  if (loc2 != std::string::npos)
742  {
743  eventName.erase(0, 4);
744  std::string newEvent = toRepl_right+eventName;
745  eventName = newEvent;
746  }
747  else
748  {
749  // actual event is a "external interaction" event?
750  std::string::size_type loc3 = eventName.find("CBxy_", 0);
751  if (loc3 != std::string::npos)
752  {
753  eventName.erase(0, 5);
754  std::string newEvent = toRepl_ext+eventName;
755  eventName = newEvent;
756  }
757  }
758  }
759 
760  // insert transition into result
761  Idx idx_event = rResEnv.EventIndex(eventName);
762  rResEnv.SetTransition(tit->X1, idx_event, tit->X2);
763  } // end for-loop over transition
764  } // end for-loop over states
765 
766  } //End Adjust IOController
767 
768 
769  // RenameHioModule: this function personalises a HioModule by renaming the content
770  // of the single modules member
771  void HioModule::RenameHioModule(const int i)
772  {
773  HioPlant tmpHioPlant;
774  Generator tmpOpConstr, tmpEnvConstr;
775  HioEnvironment tmpHioEnv;
776 
777  //adjust the mPlant member
778  AdjustHioPlant(mPlant, i, tmpHioPlant);
779 
780  //adjust the constraints
781  AdjusTimedGenerator(mOpConstr, i, tmpOpConstr);
782  AdjusTimedGenerator(mEnvConstr, i, tmpEnvConstr);
783 
784  //set the members
785  mPlant = tmpHioPlant;
786  mOpConstr = tmpOpConstr;
787  mEnvConstr = tmpEnvConstr;
788 
789  //adjust the Id
790  mIndex = i;
791 
792  //adjust the name:
793  mName = "CB"+ToStringInteger(i);
794 
795  //check if also an environment is available, if so adjust it too
796  if(mChildren.size() != 0)
797  {
799  mEnvironment = tmpHioEnv;
800  }
801 
802  }// end of RenameHioModule()
803 
804 
805  // chooseSpec: this function searches through an apappropriate folder for available
806  // specifications.
807  std::vector<std::string> HioModule::ChooseSpec(
808  const std::string path)
809  {
810  int capacity = 0;
811  int size;
812  std::string loc_path = "";
813  std::vector<std::string> listSpec, tmpListSpec, pathList;
814  std::list<std::string>::iterator itstr;
815 
816  //check to max capacity
817  size = mChildren.size();
818  std::cout<<"Number of children: "<<size<<std::endl;
819  for(int i=0; i<size; i++)
820  {
821  //The "mType"-array stores at pos 0 the capacity of an plant model
822  capacity = mChildren[i]->TypeHioModule()[0] + capacity;
823  }
824 
825  //prepare the local path to read from
826  std::string cap = "SpecCB";
827  std::vector<std::string> allPath;
828  for (int i=1; i<=capacity;i++)
829  {
830  cap = cap + ToStringInteger(i);
831  loc_path = path+cap+"/";
832  allPath.push_back(loc_path);
833  }
834  //list the available specifications
835  for (int i=0; i<capacity;i++)
836  {
837  // e.g.: resultin string = ../Spec/SpecCB123/
838  loc_path = allPath[i];
839  std::cout<<"Final path: "<<loc_path<<std::endl;
840  //check folder for specification and show them to the user
841  tmpListSpec = ListFolderContent(loc_path.c_str());
842  int size = tmpListSpec.size();
843 
844  for(int i = 0; i<size; i++)
845  {
846  listSpec.push_back(tmpListSpec[i]);
847  std::string tmpPath;
848  tmpPath = loc_path+tmpListSpec[i]+"/";
849  pathList.push_back(tmpPath);
850  }
851  }
852 
853  std::cout<<"There are "<<listSpec.size()<<" spec. available"<<std::endl;
854  size = listSpec.size();
855  for(int i=0; i<size;i++)
856  {
857  std::cout<<"Option: "<<i+1<<":"<<listSpec[i]<<std::endl;
858  }
859  //delete....
860  //int choise=1;
861  //std::cin>>choise;
862 
863  //encode specification type to the user
864  //EncodeType(listSpec[choise-1].c_str());
865 
866  //loc_path = loc_path+listSpec[choise-1]+"/";
867 
868  //loc_path = pathList[choise-1];
869  //ReadHioPlant(loc_path.c_str());
870 
871  //std::cout<<"My type is: "<<mType[0]<<mType[1]<<mType[2]<<mType[3]<<mType[4]<<std::endl;
872 
873  //do this as a final step....
874  //RenameHioModule(mId);
875  return listSpec;
876 
877  }// end of chooseSpec()
878 
879  // function to compute the IOController
881 
882  // FindController: check if an IO-Controller is already available; if case
883  // of a positive result (print the IOController statistics) and inform the
884  // user about the found IO-Controller. The user can decide whether or not
885  // the found IO-Controller will be used, or to compute a new IO-Controller.
886  if(FindController())
887  {
888  HioController tmpHioController;
889  std::string loc_path, choice;
890 
891  loc_path = MyPath()+"ioController.gen";
892  tmpHioController.Read(loc_path.c_str());
893  tmpHioController.SWrite();
894  std::cout<<"Controller found..! Accept(Y)? / New controller(N)?"<<std::endl;
895  std::cin>>choice;
896 
897  if(choice == "y" || choice == "Y")
898  {
899  mController = tmpHioController;
900  return;
901  }
902 
903  }
904  else
905  {
906  std::cout<<"Controller NOT found..!"<<std::endl;
907  }
908  Generator IOShufflemin, IOShuffle;
909  std::cout.flush()<<"Starting IOShuffle...1"<<std::endl;
910  HioShuffle_Musunoi(mChildren[0]->Plant(), mChildren[1]->Plant(), 1, IOShufflemin);
911 
912  std::cout.flush()<<" ...done!"<<std::endl;
913  StateMin(IOShufflemin, IOShuffle);
914 
915  //Start parallel composition with environment and load the local constraints
916  Generator ioShCB12parEnv, locConstr;
917 
918  Parallel(IOShuffle, mEnvironment, ioShCB12parEnv);
919  //remove generator that are not in use anymore
920  IOShuffle.Clear();
921 
922  Generator tmp1, tmp2; // generator for intermediate result
923  Parallel(mChildren[0]->OpConstr(), mChildren[0]->EnvConstr(), tmp1);
924  Parallel(mChildren[1]->OpConstr(), mChildren[1]->EnvConstr(), tmp2);
925  Parallel(tmp1, tmp2, locConstr);
926 
927  //remove generator that are not in use anymore
928  tmp1.Clear();
929  tmp2.Clear();
930 
931 
932  //Start HIO_SYNTHESIS
933 
934  Generator extConstr;
935 
936  //external constraints
937  Parallel(mOpConstr, mEnvConstr, extConstr);
938 
939  std::cout<<"**********************//////\\\\\\*******************"<<std::endl;
940  std::cout<<"Everything went fine so far...startig HIO_SYNTHESIS..."<<std::endl;
941  std::cout<<"**********************\\\\\\//////*******************"<<std::endl;
942 
943  //temp generators and event-sets for intermediate results
944  Generator tmpController, tmpHioGen;
945  EventSet Yp, Up, Yc, Uc, Ye, Ue;
946 
947  Yp = (mChildren[0]->Plant().YpEvents()+mChildren[1]->Plant().YpEvents());
948  Up = (mChildren[0]->Plant().UpEvents()+mChildren[1]->Plant().UpEvents());
949  Yc = (mPlant.YpEvents());
950  Uc = (mPlant.UpEvents());
951  Ye = (mPlant.YeEvents());
952  Ue = (mPlant.UeEvents());
953 
954  tmpHioGen.Assign(mPlant);
955 
956  //start the hio-synthesis
957  HioSynth_Musunoi(ioShCB12parEnv, mPlant, extConstr, locConstr, Yp, Up, tmpController);
958 
959  mController = tmpController;
960 
961 
962  EventSet::Iterator evit;
963  // As the result of the controller synthesis is a genarator, we set the
964  // event properties in order to obtain a HioController
965  for(evit = Yc.Begin(); evit != Yc.End(); ++evit)
966  mController.SetYc(*evit);
967 
968  for(evit = Uc.Begin(); evit != Uc.End(); ++evit)
969  mController.SetUc(*evit);
970 
971  Yp.DWrite();
972  for(evit = Yp.Begin(); evit != Yp.End(); ++evit)
973  mController.SetYp(*evit);
974 
975  for(evit = Up.Begin(); evit != Up.End(); ++evit)
976  mController.SetUp(*evit);
977 
978  std::cout.flush()<<"...Done"<<std::endl;
979 
980  std::string filename = "Controller"+ToStringInteger(mIndex)+".gen";
981  mController.Write(filename.c_str());
982 
983 
984  } //End of Compute();
985 
986 
987  //FindController(): this function searches in the folder of a choosen
988  //specification for an already computed IO-controller which enforces this
989  //specification (sought: "ioController.gen")
991  {
992 
993  //the path where to look up for the sought IO-Controller is based on the
994  //type of the specification
995  std::vector<std::string> folderContent;
996  std::string loc_path;
997 
998  //find the local path
999  loc_path = MyPath();
1000  folderContent = ListFolderContent(loc_path.c_str());
1001  int size = folderContent.size();
1002 
1003  for(int i=0; i<size; i++)
1004  if (folderContent[i]== "ioController.gen")
1005  return true;
1006 
1007  return false;
1008  } //End of FindController()
1009 
1010 
1011  // Save: this function saves the computed controller in the same folder with
1012  // the specification that this controller enforces
1014  {
1015  std::string loc_path;
1016  loc_path = MyPath();
1017  loc_path = loc_path+"ioController.gen";
1018 
1019  mController.Write(loc_path.c_str());
1020  } //End of SaveController()
1021 
1022 
1023  //MyPath: based on the type of the HioModule, this is a convenience function to
1024  // establish the local path where to Write/Read from.
1025  std::string HioModule::MyPath()
1026  {
1027  int capacity = mType[0];
1028  std::vector<std::string> folderContent;
1029  std::string cap, loc_path, sub_folder;
1030 
1031 
1032  for (int i=1; i<=capacity; i++)
1033  {
1034  cap = cap + ToStringInteger(i);
1035  }
1036 
1037  for (int i=0; i<5;i++)
1038  {
1039  sub_folder = sub_folder+ToStringInteger(mType[i]);
1040  }
1041 
1042  //path to search
1043  loc_path = "Data/Spec/SpecCB"+cap+"/"+sub_folder+"/";
1044  return loc_path;
1045  } //end MyPath()
1046 
1047 
1048  /**********************************************
1049  **********************************************
1050  *
1051  * functions to call properties of the HioModule
1052  **********************************************
1053  ***********************************************/
1054 
1055  // function to call the x-Positon of the HioModule
1056  int HioModule::Xpos() const {
1057 
1058  return mXpos;
1059  }
1060 
1061 
1062  // function to call the y-Positon of the HioModule
1063  int HioModule::Ypos() const {
1064 
1065  return mYpos;
1066  }
1067 
1068  // function to call the type of the HioModule
1070 
1071  int* type = new int[5];
1072  for (int i=0; i<=4; i++)
1073  type[i] = mType[i];
1074 
1075  return type;
1076  }
1077 
1078 
1079  // function to encode to Type of the HioModule
1080  void HioModule::EncodeType(const std::string type) {
1081 
1082  std::cout<<"***********Capacity: "<<type.at(0)<<"******"<<std::endl;
1083  std::cout<<"*Take from left: "<<type.at(1)<<"* "<<" *Take from right: "<<type.at(2)<<"*"<<std::endl;
1084  std::cout<<"*Deliver to left: "<<type.at(3)<<"* "<<" *Deliver to right: "<<type.at(4)<<"*"<<std::endl;
1085 
1086  }
1087 
1088  /*******************************************************************************
1089  ***************************END OF IOMODULE CLASS DEFINITION********************
1090  ******************************************************************************/
1091 
1092 
1093  // GroupHioModules: This function groups two or more HioModules to a new HioModule.
1095  const std::vector<HioModule*>& rChildren,
1096  HioModule& rParentModule)
1097  {
1098  int size = rChildren.size();
1099  float Id =0;
1100  for (int i =0; i < size; i++)
1101  {
1102  rParentModule.InsChild(rChildren[i]);
1103  std::cout<<"insert #"<<i<<"- ModuleID: "<<rChildren[i]->Index();
1104  // Id is composed of children Id's
1105  Id = pow(10, size-i-1)*rChildren[i]->Index()+Id;
1106  std::cout<<".."<<Id<<std::endl;
1107  }
1108  std::cout<<"Id set!"<<std::endl;
1109  //read the environment describing the interaction between the grouped components
1110  HioEnvironment HioEnv("Data/envCBxy.gen");
1111 
1112  //set the new Id of the module, and adjust the environment
1113  int intId = int(Id);
1114  rParentModule.Environment(HioEnv);
1115  rParentModule.RenameHioModule(intId);
1116 
1117  }// end of GroupHioModule()
1118 
1119 
1120  //CreateSpec()
1121  void CreateSpec(int mType[5], HioPlant& rHioSpec, Generator& constrP, Generator& constrE)
1122  {
1123 
1124  // initiate several variables; variables to store information about the number
1125  // of the take and deliver actions and last known state.
1126  int loaded, fl, fr, tol, tor, i_lastState, index;
1127  std::string s_lastQy, s_lastQup, s_lastQue, s_lastState, s_lastQy_stby, s_newQy_stby;
1128  std::string s_lastQupFL, s_lastQupFR, s_lastQup2L, s_lastQup2R, s_newQy_FR, s_newQy_FL, s_newQy_2L, s_newQy_2R;
1129 
1130  s_lastQup = s_lastQupFL = s_lastQupFR = s_newQy_stby = "ErrQy";
1131  fl=fr=tol=tor=i_lastState=index=loaded=0;
1132 
1133  //Insert alphabet
1134  rHioSpec.InsYpEvent("CBx_free");
1135  rHioSpec.InsYpEvent("CBx_busy");
1136  rHioSpec.InsUpEvent("CBx_stby");
1137  rHioSpec.InsUpEvent("CBx_FL");
1138  rHioSpec.InsUpEvent("CBx_FR");
1139  rHioSpec.InsUpEvent("CBx_2L");
1140  rHioSpec.InsUpEvent("CBx_2R");
1141  rHioSpec.InsYeEvent("CBx_req_fl");
1142  rHioSpec.InsYeEvent("CBx_req_fr");
1143  rHioSpec.InsYeEvent("CBx_wpar_fl");
1144  rHioSpec.InsYeEvent("CBx_wpar_fr");
1145  rHioSpec.InsYeEvent("CBx_wpar_tl");
1146  rHioSpec.InsYeEvent("CBx_wpar_tr");
1147  rHioSpec.InsUeEvent("CBx_pack");
1148  rHioSpec.InsUeEvent("CBx_nack");
1149 
1150  //Insert error state
1151  rHioSpec.InsMarkedState("ErrQy");
1152 
1153  //1. Create init state and the first transitions; in order to save the last added
1154  // state and/or transition, set the respective variable ("s_lastQup", "i_lastState")
1155  rHioSpec.InsInitState("1");
1156  rHioSpec.SetMarkedState("1");
1157  rHioSpec.InsMarkedState("2");
1158  rHioSpec.SetTransition("1", "CBx_free", "2");
1159  s_lastQup = "2";
1160  rHioSpec.SetTransition("2", "CBx_stby", "1");
1161  i_lastState = 2;
1162 
1163  /*************** Interpretation of mType[] *******
1164  ************* Capacity: mType[0] *********
1165  ************* Take from left: mType[1] *********
1166  ************* Take from right: mType[2] *********
1167  ************* Deliver to left: mType[3] *********
1168  ************* Deliver to left: mType[4] *********
1169  ************************************************/
1170 
1171 
1172  //2. so called "Qy_stby" - states are of states were we decied if an other
1173  // "Take from..." or "Deliver to..." - cycle must be added to the specification.
1174  // This are also states where the specification branch out, so it is important
1175  // to keep this state in order to implement all transitions starting here.
1176 
1177  // "index" - stores the information about the capacity, i.e. how many times we
1178  // need to add the "Take from..." "Deliver from" cycle
1179  for(int i=0; i<mType[0]; i++)
1180  {
1181  s_lastQy_stby = s_newQy_stby;
1182  index++;
1183 
1184  //if no piece loaded yet, deliver actions would lead to an Error state
1185  if(loaded == 0)
1186  {
1187  rHioSpec.SetTransition(s_lastQup, "CBx_2L", "ErrQy");
1188  s_lastQup2L = "ErrQy";
1189  rHioSpec.SetTransition(s_lastQup, "CBx_2R", "ErrQy");
1190  s_lastQup2R = "ErrQy";
1191  }
1192 
1193  // the value of "fl" holds how many "Take from left"-cycles we already implemented
1194  // in the specification. If the fl < requested "Take from left"- operations,
1195  // implement an other one.
1196  if(fl<mType[1])
1197  {
1198  // if index = 1 then we are in the first implementation cycle
1199  // so need to insert a new state. (in the next cycles, this
1200  // state will have be already inserted -> see "else" statement)
1201  if(!(index > 1))
1202  {
1203  s_lastState = ToStringInteger(i_lastState+1);
1204  rHioSpec.InsMarkedState(s_lastState);
1205  }
1206  else
1207  {
1208  // hold that the last inserted state is "Qy"-state that
1209  // we arrive through a "Take from" - transition
1210  s_lastState = s_newQy_FL;
1211  }
1212 
1213  //insert the corresponding "Take from" - transition
1214  rHioSpec.SetTransition(s_lastQup, "CBx_FL", s_lastState);
1215  s_lastQy = s_lastState;
1216  i_lastState++;
1217 
1218  //insert the corresponding "request from" - transition;
1219  //therefor we first need to insert a new state
1220  s_lastState = ToStringInteger(i_lastState+1);
1221  rHioSpec.InsMarkedState(s_lastState);
1222  rHioSpec.SetTransition(s_lastQy, "CBx_req_fl", s_lastState);
1223  s_lastQue = s_lastState;
1224  i_lastState++;
1225 
1226  //insert the corresponding "acknowledge" - transition
1227  //therefor we first need to insert a new state
1228  s_lastState = ToStringInteger(i_lastState+1);
1229  rHioSpec.InsMarkedState(s_lastState);
1230  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastState);
1231  s_lastQy = s_lastState;
1232  i_lastState++;
1233 
1234  //Ue must be free -> insert transition to error-state
1235  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1236 
1237  //insert the corresponding "busy" - transition
1238  //therefor we first need to insert a new state
1239  s_lastState = ToStringInteger(i_lastState+1);
1240  rHioSpec.InsMarkedState(s_lastState);
1241  rHioSpec.SetTransition(s_lastQy, "CBx_busy", s_lastState);
1242  s_lastQupFL = s_lastState;
1243  i_lastState++;
1244 
1245  //update the status of the loaded number of pieces
1246  loaded = index;
1247  //update the number of implemented "Take from Left" - cycles
1248  fl++;
1249 
1250  }
1251  //Up must be free -> insert transition to error-state;
1252  else
1253  {
1254  rHioSpec.SetTransition(s_lastQup, "CBx_FL", "ErrQy");
1255  s_lastQupFL = "ErrQy";
1256  }
1257 
1258 
1259  //as "Take from left" or "Take from right" are simetrical, the implementation
1260  //is also the same as above
1261  // the value of "fr" holds how many "Take from right"-cycles we already implemented
1262  // in the specification. If the fr < requested "Take from right"- operations,
1263  // implement an other one.
1264  if(fr<mType[2])
1265  {
1266  // if index = 1 then we are in the first implementation cycle
1267  // so need to insert a new state. (in the next cycles, this
1268  // state will have be already inserted -> see "else" statement)
1269  if(!(index > 1))
1270  {
1271  s_lastState = ToStringInteger(i_lastState+1);
1272  rHioSpec.InsMarkedState(s_lastState);
1273  }
1274  else
1275  {
1276  // hold that the last inserted state is "Qy"-state that
1277  // we arrive through a "Take from" - transition
1278  s_lastState = s_newQy_FR;
1279  }
1280 
1281  //insert the corresponding "Take from" - transition
1282  rHioSpec.SetTransition(s_lastQup, "CBx_FR", s_lastState);
1283  s_lastQy = s_lastState;
1284  i_lastState++;
1285 
1286  //insert the corresponding "request from" - transition;
1287  //therefor we first need to insert a new state
1288  s_lastState = ToStringInteger(i_lastState+1);
1289  rHioSpec.InsMarkedState(s_lastState);
1290  rHioSpec.SetTransition(s_lastQy, "CBx_req_fr", s_lastState);
1291  s_lastQue = s_lastState;
1292  i_lastState++;
1293 
1294  //insert the corresponding "acknowledge" - transition
1295  //therefor we first need to insert a new state
1296  s_lastState = ToStringInteger(i_lastState+1);
1297  rHioSpec.InsMarkedState(s_lastState);
1298  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastState);
1299  s_lastQy = s_lastState;
1300  i_lastState++;
1301 
1302  //Ue must be free -> insert transition to error-state
1303  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1304 
1305  //insert the corresponding "busy" - transition
1306  //therefor we first need to insert a new state
1307  s_lastState = ToStringInteger(i_lastState+1);
1308  rHioSpec.InsMarkedState(s_lastState);
1309  rHioSpec.SetTransition(s_lastQy, "CBx_busy", s_lastState);
1310  s_lastQupFR = s_lastState;
1311  i_lastState++;
1312 
1313  //update the status of the loaded number of pieces
1314  loaded = index;
1315  //update the number of implemented "Take from Right" - cycles
1316  fr++;
1317  }
1318  //Up must be free -> insert transition to error-state;
1319  else
1320  {
1321  rHioSpec.SetTransition(s_lastQup, "CBx_FR", "ErrQy");
1322  s_lastQupFR = "ErrQy";
1323  }
1324 
1325  // as far as the last QupFL or QupFR did not lead to an error state (i.e. the
1326  // requested number of "Take from..." achieved) insert a new stbyState in order
1327  // to start the new cycle of "Take from..."
1328  if((s_lastQupFL != "ErrQy") ||(s_lastQupFR != "ErrQy"))
1329  {
1330  s_lastState = ToStringInteger(i_lastState+1);
1331  rHioSpec.InsMarkedState(s_lastState);
1332  s_newQy_stby = s_lastState;
1333  i_lastState++;
1334 
1335  }
1336 
1337  //here is the standby case handeled, if before a "Take from left" - command occured
1338  if(s_lastQupFL != "ErrQy")
1339  {
1340  // insert the stby transition
1341  s_lastState = ToStringInteger(i_lastState+1);
1342  rHioSpec.InsMarkedState(s_lastState);
1343  rHioSpec.SetTransition(s_lastQupFL, "CBx_stby", s_lastState);
1344  s_lastQy = s_lastState;
1345  i_lastState++;
1346 
1347  // insert the corresponding environment transition
1348  s_lastState = ToStringInteger(i_lastState+1);
1349  rHioSpec.InsMarkedState(s_lastState);
1350  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState);
1351  s_lastQue = s_lastState;
1352  i_lastState++;
1353 
1354  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_stby);
1355  //Ue must be free -> insert transition to error-state
1356  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1357 
1358  }
1359 
1360  //here is the standby case handeled, if before a "Take from right" - command occured
1361  if(s_lastQupFR != "ErrQy")
1362  {
1363  // insert the stby transition
1364  s_lastState = ToStringInteger(i_lastState+1);
1365  rHioSpec.InsMarkedState(s_lastState);
1366  rHioSpec.SetTransition(s_lastQupFR, "CBx_stby", s_lastState);
1367  s_lastQy = s_lastState;
1368  i_lastState++;
1369 
1370  // insert the corresponding environment transition
1371  s_lastState = ToStringInteger(i_lastState+1);
1372  rHioSpec.InsMarkedState(s_lastState);
1373  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState);
1374  s_lastQue = s_lastState;
1375  i_lastState++;
1376 
1377  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_stby);
1378  //Ue must be free -> insert transition to error-state
1379  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1380  }
1381 
1382  //setup the stanby-loop
1383  if((s_lastQupFL != "ErrQy") ||(s_lastQupFR != "ErrQy"))
1384  {
1385  s_lastState = ToStringInteger(i_lastState+1);
1386  rHioSpec.InsMarkedState(s_lastState);
1387  rHioSpec.SetTransition(s_newQy_stby, "CBx_busy", s_lastState);
1388  s_lastQup = s_lastState;
1389  i_lastState++;
1390  rHioSpec.SetTransition(s_lastState, "CBx_stby", s_newQy_stby);
1391  }
1392 
1393 
1394 
1395  //insert shared 2L-state if the number of "Deliver to Left" transitions is not
1396  //already acheived. By shared we mean the "Deliver to Left" transition
1397  //starting from the stby state, where no communication with the environment occurs
1398  if(tol<mType[3])
1399  {
1400  s_lastState = ToStringInteger(i_lastState+1);
1401  rHioSpec.InsMarkedState(s_lastState);
1402  s_newQy_2L = s_lastState;
1403  i_lastState++;
1404  }
1405  else tol++;
1406 
1407  //insert 'shared' 2R-state if the number of "Deliver to Right" transitions is not
1408  //already acheived; By shared we mean the "Deliver to Right" transition
1409  //starting from the stby state, where no communication with the environment occurs;
1410  if(tor<mType[4])
1411  {
1412  s_lastState = ToStringInteger(i_lastState+1);
1413  rHioSpec.InsMarkedState(s_lastState);
1414  s_newQy_2R = s_lastState;
1415  i_lastState++;
1416  }
1417  else tor++;
1418 
1419  // if at least one piece is available (fl or fr != 0) continue with the
1420  // implementation of the 2L action
1421  if(tol<mType[3] && (fl !=0 ||fr !=0))
1422  {
1423  // if the last FL led to an Error State, then don't implement
1424  // the "Deliver to..." action (as this would start from an
1425  // Error State - ErrQy)
1426  if(s_lastQupFL != "ErrQy")
1427  {
1428  //insert the corresponding "Deliver to..." - transition
1429  s_lastState = ToStringInteger(i_lastState+1);
1430  rHioSpec.InsMarkedState(s_lastState);
1431  rHioSpec.SetTransition(s_lastQupFL, "CBx_2L", s_lastState);
1432  s_lastQy = s_lastState;
1433  i_lastState++;
1434 
1435  //insert the corresponding "request to..." - transition
1436  s_lastState = ToStringInteger(i_lastState+1);
1437  rHioSpec.InsMarkedState(s_lastState);
1438  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState);
1439  s_lastQue = s_lastState;
1440  i_lastState++;
1441 
1442  //Enivronment acknowledge
1443  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2L);
1444  //Ue must be free -> insert transition to error-state
1445  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1446  }
1447 
1448  // if the last FR led to an Error State, then don't implement
1449  // the "Deliver to..." action (as this would start from an
1450  // Error State - ErrQy)
1451  if(s_lastQupFR != "ErrQy")
1452  {
1453  //insert the corresponding "Deliver to..." - transition
1454  s_lastState = ToStringInteger(i_lastState+1);
1455  rHioSpec.InsMarkedState(s_lastState);
1456  rHioSpec.SetTransition(s_lastQupFR, "CBx_2L", s_lastState);
1457  s_lastQy = s_lastState;
1458  i_lastState++;
1459 
1460  //insert the corresponding "request to..." - transition
1461  s_lastState = ToStringInteger(i_lastState+1);
1462  rHioSpec.InsMarkedState(s_lastState);
1463  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState);
1464  s_lastQue = s_lastState;
1465  i_lastState++;
1466 
1467  //Enivronment acknowledge
1468  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2L);
1469  //Ue must be free -> insert transition to error-state
1470  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1471 
1472 
1473  }
1474  // Both deliver actions (2L, 2R) contiue on
1475  // the same path
1476  // Environment receieved the piece
1477  s_lastState = ToStringInteger(i_lastState+1);
1478  rHioSpec.InsMarkedState(s_lastState);
1479  rHioSpec.SetTransition(s_newQy_2L, "CBx_wpar_tl", s_lastState);
1480  s_lastQue = s_lastState;
1481  i_lastState++;
1482 
1483  if(loaded ==1)
1484  {
1485  //up to here only one piece loaded -> go back to init state
1486  rHioSpec.SetTransition(s_lastQue, "CBx_pack", "1");
1487  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1488  }
1489  else
1490  {
1491  //if more then one piece loaded go to the last stby state
1492  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastQy_stby);
1493  //Ue must be free -> insert transition to error-state
1494  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1495  }
1496 
1497  //increase number of delivered pieces
1498  tol++;
1499 
1500  }
1501 
1502  // Uc must be free: if last Qup was an Error state, still insert the "Deliver to..."
1503  // action leading also to an Error state
1504  else
1505  {
1506  if(s_lastQupFL != "ErrQy")
1507  {
1508  rHioSpec.SetTransition(s_lastQupFL, "CBx_2L", "ErrQy");
1509  }
1510  if(s_lastQupFR != "ErrQy")
1511  {
1512  rHioSpec.SetTransition(s_lastQupFR, "CBx_2L", "ErrQy");
1513  }
1514  }
1515 
1516  // if at least one piece is available (fl or fr != 0) continue with the
1517  // implementation of the 2R action
1518  if(tor<mType[4] && (fl !=0 ||fr !=0))
1519  {
1520  // if the last FL led to an Error State, then don't implement
1521  // the "Deliver to..." action (as this would start from an
1522  // Error State - ErrQy)
1523  if(s_lastQupFL != "ErrQy")
1524  {
1525  //insert the corresponding "Deliver to..." - transition
1526  s_lastState = ToStringInteger(i_lastState+1);
1527  rHioSpec.InsMarkedState(s_lastState);
1528  rHioSpec.SetTransition(s_lastQupFL, "CBx_2R", s_lastState);
1529  s_lastQy = s_lastState;
1530  i_lastState++;
1531 
1532  //insert the corresponding "request to..." - transition
1533  s_lastState = ToStringInteger(i_lastState+1);
1534  rHioSpec.InsMarkedState(s_lastState);
1535  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState);
1536  s_lastQue = s_lastState;
1537  i_lastState++;
1538 
1539  //Enivronment acknowledge
1540  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2R);
1541  //Ue must be free -> insert transition to error-state
1542  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1543 
1544  }
1545 
1546  // if the last FR led to an Error State, then don't implement
1547  // the "Deliver to..." action (as this would start from an
1548  // Error State - ErrQy)
1549  if(s_lastQupFR != "ErrQy")
1550  {
1551  //insert the corresponding "Deliver to..." - transition
1552  s_lastState = ToStringInteger(i_lastState+1);
1553  rHioSpec.InsMarkedState(s_lastState);
1554  rHioSpec.SetTransition(s_lastQupFR, "CBx_2R", s_lastState);
1555  s_lastQy = s_lastState;
1556  i_lastState++;
1557 
1558  //insert the corresponding "request to..." - transition
1559  s_lastState = ToStringInteger(i_lastState+1);
1560  rHioSpec.InsMarkedState(s_lastState);
1561  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState);
1562  s_lastQue = s_lastState;
1563  i_lastState++;
1564 
1565  //Enivronment acknowledge
1566  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2R);
1567  //Ue must be free -> insert transition to error-state
1568  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1569 
1570  }
1571  // Both deliver actions (2L, 2R) contiue on
1572  // the same path
1573  // Environment receieved the piece
1574  s_lastState = ToStringInteger(i_lastState+1);
1575  rHioSpec.InsMarkedState(s_lastState);
1576  rHioSpec.SetTransition(s_newQy_2R, "CBx_wpar_tr", s_lastState);
1577  s_lastQue = s_lastState;
1578  i_lastState++;
1579 
1580  if(loaded ==1)
1581  {
1582  //up to here only one piece loaded -> go back to init state
1583  rHioSpec.SetTransition(s_lastQue, "CBx_pack", "1");
1584  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1585  }
1586  //if more then one piece loaded go to the last stby state
1587  else
1588  {
1589  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastQy_stby);
1590  //Ue must be free -> insert transition to error-state
1591  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1592  }
1593 
1594  // increase number of delivered pieces
1595  tor++;
1596 
1597  }
1598  // Uc must be free: if last Qup was an Error state, still insert the "Deliver to..."
1599  // action leading also to an Error state
1600  else
1601  {
1602 
1603  if(s_lastQupFL != "ErrQy")
1604  {
1605  rHioSpec.SetTransition(s_lastQupFL, "CBx_2R", "ErrQy");
1606  }
1607  if(s_lastQupFR != "ErrQy")
1608  {
1609  rHioSpec.SetTransition(s_lastQupFR, "CBx_2R", "ErrQy");
1610  }
1611  }
1612 
1613  //insert the next FL action after an FL or FR action already occured;
1614  if(fl<mType[1])
1615  {
1616  s_lastState = ToStringInteger(i_lastState+1);
1617  rHioSpec.InsMarkedState(s_lastState);
1618  s_newQy_FL = s_lastState;
1619  i_lastState++;
1620  }
1621 
1622  //insert the next FL action after an FL or FR action already occured;
1623  if(fr<mType[2])
1624  {
1625  s_lastState = ToStringInteger(i_lastState+1);
1626  rHioSpec.InsMarkedState(s_lastState);
1627  s_newQy_FR = s_lastState;
1628  i_lastState++;
1629  }
1630 
1631  // if last action was a FL, implement the corresponding environment events (wpar_fl)
1632  // before continue with the next take from action
1633  if((s_lastQupFL != "ErrQy") && fl <mType[1])
1634 
1635  {
1636  //insert the "Take from..." transition
1637  s_lastState = ToStringInteger(i_lastState+1);
1638  rHioSpec.InsMarkedState(s_lastState);
1639  rHioSpec.SetTransition(s_lastQupFL, "CBx_FL", s_lastState);
1640  s_lastQy = s_lastState;
1641  i_lastState++;
1642 
1643  //insert the environment transition
1644  s_lastState = ToStringInteger(i_lastState+1);
1645  rHioSpec.InsMarkedState(s_lastState);
1646  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState);
1647  s_lastQue = s_lastState;
1648  i_lastState++;
1649 
1650  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FL);
1651  //Ue must be free -> insert transition to error-state
1652  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1653 
1654  }
1655  //Up must be free -> insert transition to error-state;
1656  else
1657  if(fl<mType[1])
1658  {
1659  rHioSpec.SetTransition(s_lastQupFL, "CBx_FL", "ErrQy");
1660  }
1661  // if last action was a FL, implement the corresponding environment events (wpar_fl)
1662  // before continue with the next take from action
1663  if((s_lastQupFL != "ErrQy") && fr <mType[2])
1664 
1665  {
1666  //insert the "Take from..." transition
1667  s_lastState = ToStringInteger(i_lastState+1);
1668  rHioSpec.InsMarkedState(s_lastState);
1669  rHioSpec.SetTransition(s_lastQupFL, "CBx_FR", s_lastState);
1670  s_lastQy = s_lastState;
1671  i_lastState++;
1672 
1673  //insert the environment transition
1674  s_lastState = ToStringInteger(i_lastState+1);
1675  rHioSpec.InsMarkedState(s_lastState);
1676  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState);
1677  s_lastQue = s_lastState;
1678  i_lastState++;
1679 
1680  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FR);
1681  //Ue must be free -> insert transition to error-state
1682  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1683 
1684  }
1685  //Up must be free -> insert transition to error-state;
1686  else
1687  if(fl<mType[1])
1688  {
1689  rHioSpec.SetTransition(s_lastQupFL, "CBx_FR", "ErrQy");
1690  }
1691 
1692 
1693  // if last action was a FR, implement the corresponding environment events (wpar_fl)
1694  // before continue with the next take from action
1695  if((s_lastQupFR != "ErrQy") && fl <mType[1])
1696 
1697  {
1698  //insert the "Take from..." transition
1699  s_lastState = ToStringInteger(i_lastState+1);
1700  rHioSpec.InsMarkedState(s_lastState);
1701  rHioSpec.SetTransition(s_lastQupFR, "CBx_FL", s_lastState);
1702  s_lastQy = s_lastState;
1703  i_lastState++;
1704 
1705  //insert the environment transition
1706  s_lastState = ToStringInteger(i_lastState+1);
1707  rHioSpec.InsMarkedState(s_lastState);
1708  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState);
1709  s_lastQue = s_lastState;
1710  i_lastState++;
1711 
1712  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FL);
1713  //Ue must be free -> insert transition to error-state
1714  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1715 
1716  }
1717  //Up must be free -> insert transition to error-state;
1718  else
1719  if (fr<mType[2])
1720  {
1721  rHioSpec.SetTransition(s_lastQupFR, "CBx_FL", "ErrQy");
1722  }
1723 
1724  // if last action was a FR, implement the corresponding environment events (wpar_fl)
1725  // before continue with the next take from action
1726  if((s_lastQupFR != "ErrQy") && fr <mType[2])
1727 
1728  {
1729  //insert the "Take from..." transition
1730  s_lastState = ToStringInteger(i_lastState+1);
1731  rHioSpec.InsMarkedState(s_lastState);
1732  rHioSpec.SetTransition(s_lastQupFR, "CBx_FR", s_lastState);
1733  s_lastQy = s_lastState;
1734  i_lastState++;
1735 
1736  //insert the environment transition
1737  s_lastState = ToStringInteger(i_lastState+1);
1738  rHioSpec.InsMarkedState(s_lastState);
1739  rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState);
1740  s_lastQue = s_lastState;
1741  i_lastState++;
1742 
1743  rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FR);
1744  //Ue must be free -> insert transition to error-state
1745  rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy");
1746  }
1747  //Up must be free -> insert transition to error-state;
1748  else
1749  if (fr<mType[2])
1750  {
1751  rHioSpec.SetTransition(s_lastQupFR, "CBx_FR", "ErrQy");
1752  }
1753 
1754 
1755 
1756  // insert the remaining "Deliver to..." transition;
1757  if(tol <= mType[3])
1758  rHioSpec.SetTransition(s_lastQup, "CBx_2L", s_newQy_2L);
1759  else
1760  // Up must be free -> insert transition to error-state;
1761  rHioSpec.SetTransition(s_lastQup, "CBx_2L", "ErrQy");
1762 
1763  // insert the remaining "Deliver to..." transition;
1764  if(tor <= mType[4])
1765  rHioSpec.SetTransition(s_lastQup, "CBx_2R", s_newQy_2R);
1766  else
1767  // Up must be free -> insert transition to error-state;
1768  rHioSpec.SetTransition(s_lastQup, "CBx_2R", "ErrQy");
1769 
1770  // finaly, if the numer of maximal capacity is achieved, insert remaining transition
1771  // in order to ensure the I/O plant format of the specification;
1772  if(index == mType[0])
1773  {
1774  if(s_lastQup != "ErrQy")
1775  {
1776  rHioSpec.SetTransition(s_lastQup, "CBx_FR", "ErrQy");
1777  rHioSpec.SetTransition(s_lastQup, "CBx_FL", "ErrQy");
1778  }
1779 
1780  if(s_lastQupFL != "ErrQy")
1781  {
1782  rHioSpec.SetTransition(s_lastQupFL, "CBx_FL", "ErrQy");
1783  rHioSpec.SetTransition(s_lastQupFL, "CBx_FR", "ErrQy");
1784  }
1785 
1786  if(s_lastQupFR != "ErrQy")
1787  {
1788  rHioSpec.SetTransition(s_lastQupFR, "CBx_FR", "ErrQy");
1789  rHioSpec.SetTransition(s_lastQupFR, "CBx_FL", "ErrQy");
1790  }
1791 
1792  rHioSpec.SWrite();
1793 
1794  // for the creaded specification create now also the constraints which describe
1795  // the condition of completeness and Yp-liveness
1796  CreateConstraint(mType, constrP, constrE);
1797 
1798  }// end if
1799 
1800  }// end for-loop: see comment at begin of the (main)loop ->
1801  // "index" - stores the information about the capacity, i.e. how many
1802  // times we need to add the "Take from..." "Deliver from" cycle
1803 
1804  }// end createSpec()
1805 
1806 
1807  // This function creates constraints which describe the condition of completeness
1808  // and Yp-liveness of a Specification. The implementation follows the same algorithm
1809  // as the CreateSpec() function, and has the same limitation: it is only for use
1810  // with a specific model
1811  void CreateConstraint(int mType[5], Generator& constrP, Generator& constrE)
1812  {
1813 
1814  int i_lastState, fl, fr, tol, tor;
1815  i_lastState = fl = fr = tol = tor = 0;
1816 
1817  std::string s_lastState, s_lastQup, s_lastQy, s_newQy, s_return;
1818  s_lastState = s_lastQup = s_lastQy = s_newQy = s_return = "";
1819 
1820  // the environment constraint constrE: this is an automata with one state,
1821  // one event and no transitions
1822  constrE.InsEvent("CBx_nack");
1823  constrE.InsInitState("1");
1824  constrE.SetMarkedState("1");
1825 
1826  // the operator constraint constrP
1827  constrP.InsEvent("CBx_free");
1828  constrP.InsEvent("CBx_busy");
1829  constrP.InsEvent("CBx_stby");
1830  constrP.InsEvent("CBx_FL");
1831  constrP.InsEvent("CBx_FR");
1832  constrP.InsEvent("CBx_2L");
1833  constrP.InsEvent("CBx_2R");
1834 
1835  // insert the states and transitions that are independent of the type of the
1836  // constraint
1837  constrP.InsInitState("1");
1838  constrP.SetMarkedState("1");
1839  s_return = "1";
1840  s_lastQy = "1";
1841  constrP.InsMarkedState("2");
1842  constrP.SetTransition("1", "CBx_free", "2");
1843  constrP.SetTransition("1", "CBx_busy", "2");
1844  i_lastState = 2;
1845  s_lastQup = "2";
1846 
1847  // start the main loop
1848  for (int i=0; i<mType[0]; i++)
1849  {
1850 
1851  //insert shared state Qy
1852  if(fl<mType[1] || fr<mType[2])
1853  {
1854  s_lastState = ToStringInteger(i_lastState+1);
1855  constrP.InsMarkedState(s_lastState);
1856  s_newQy = s_lastState;
1857  constrP.SetTransition(s_lastQup, "CBx_stby", s_lastQy);
1858  i_lastState++;
1859 
1860  }
1861  // insert "Take from left" transition if number of needed transitions not
1862  // already achieved
1863  if(fl<mType[1])
1864  {
1865  constrP.SetTransition(s_lastQup, "CBx_FL", s_newQy);
1866  fl++;
1867  }
1868 
1869  // insert "Take from right" transition if number of needed transitions not
1870  // already achieved
1871  if(fr<mType[2])
1872  {
1873  constrP.SetTransition(s_lastQup, "CBx_FR", s_newQy);
1874  fr++;
1875  }
1876  // i>0 only after we implemented at least one "Take from..." action; if i==0
1877  // "Deliver to..." action will be not implemented, as a deliver action is not
1878  // possible yet
1879  if(i>0)
1880  {
1881  //insert 2L-Trans
1882  if(tol<mType[3])
1883  {
1884  // insert corresponding "Deliver to..." transition
1885  // and increase the number of implemented "Deliver
1886  // to..." transitions
1887  constrP.SetTransition(s_lastQup, "CBx_2L", s_return);
1888  tol++;
1889  }
1890 
1891  //insert 2R-Trans
1892  if(tor<mType[4])
1893  {
1894  // insert corresponding "Deliver to..." transition
1895  // and increase the number of implemented "Deliver
1896  // to..." transitions
1897  constrP.SetTransition(s_lastQup, "CBx_2R", s_return);
1898  tor++;
1899  }
1900 
1901  // store the last state
1902  s_return = s_lastQy;
1903  }
1904 
1905  // implement stby loop
1906  s_lastState = ToStringInteger(i_lastState+1);
1907  constrP.InsMarkedState(s_lastState);
1908  constrP.SetTransition(s_newQy, "CBx_free", s_lastState);
1909  constrP.SetTransition(s_newQy, "CBx_busy", s_lastState);
1910  constrP.SetTransition(s_lastState, "CBx_stby", s_newQy);
1911  s_lastQup = s_lastState;
1912  i_lastState++;
1913 
1914  // as i starts at 0, check if the limit is achieved and implemet the remaining
1915  // "Deliver to..." transitions
1916  if(i+1 == mType[0])
1917  {
1918  if(tol<mType[3])
1919  {
1920  constrP.SetTransition(s_lastQup, "CBx_2L", s_return);
1921  tol++;
1922  }
1923 
1924  if(tor<mType[4])
1925  {
1926  constrP.SetTransition(s_lastQup, "CBx_2R", s_return);
1927  tor++;
1928  }
1929  }
1930  // store the last state
1931  s_lastQy = s_newQy;
1932 
1933  }//end for-loop - see comment at begin of the loop ->
1934  // "index" - stores the information about the capacity, i.e. how many
1935  // times we need to add the "Take from..." "Deliver from" cycle
1936 
1937 
1938  }// End create Constraint
1939 
1940 } // end namespace faudes*******end namespace faudes********end namespace faudes
1941 
1942 /********************************END*******************************************/

libFAUDES 2.26g --- 2015.08.17 --- c++ api documentaion by doxygen