hio_module.cppGo to the documentation of this file.00001 /** @file hio_module.cpp Class describing the I/O based hierarchy */ 00002 00003 /* Hierarchical IO Systems Plug-In for FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2006 Sebastian Perk 00006 Copyright (C) 2006 Thomas Moor 00007 Copyright (C) 2006 Klaus Schmidt 00008 00009 */ 00010 00011 #include "hio_module.h" 00012 00013 namespace faudes { 00014 00015 // Constructor 00016 HioModule::HioModule(void){ 00017 } 00018 00019 00020 // Copy constructor 00021 HioModule::HioModule(const HioModule& rOtherHioModule) { 00022 mOpConstr = rOtherHioModule.OpConstr(); 00023 mPlant = rOtherHioModule.Plant(); 00024 mController = rOtherHioModule.Controller(); 00025 mChildren = rOtherHioModule.Children(); 00026 mEnvironment = rOtherHioModule.Environment(); 00027 mEnvConstr = rOtherHioModule.EnvConstr(); 00028 TypeHioModule(rOtherHioModule.TypeHioModule()); 00029 mIndex = rOtherHioModule.Index(); 00030 mName = rOtherHioModule.Name(); 00031 Position(rOtherHioModule.Xpos(), rOtherHioModule.Ypos()); 00032 } 00033 00034 //HioModule::Clear() 00035 void HioModule::Clear() 00036 { 00037 mEnvConstr.Clear(); 00038 mOpConstr.Clear(); 00039 mController.Clear(); 00040 mPlant.Clear(); 00041 mIndex = 0; 00042 for (int i=0; i<5; i++) 00043 mType[i] = 0; 00044 mXpos = 0; 00045 mYpos = 0; 00046 mName = ""; 00047 mChildren.clear(); 00048 } 00049 00050 // HioModule::Name() 00051 std::string HioModule::Name() const { 00052 return mName; 00053 } 00054 00055 // HioModule::Name(rName) 00056 void HioModule::Name(const std::string& rName){ 00057 mName = rName; 00058 } 00059 00060 // HioModule::Index() 00061 Idx HioModule::Index() const { 00062 return mIndex; 00063 } 00064 00065 // HioModule::Index(Index) 00066 void HioModule::Index(const Idx Index){ 00067 mIndex = Index; 00068 } 00069 00070 // HioModule::OpConstr(rOpConstr) 00071 void HioModule::OpConstr(const HioConstraint& rOpConstr){ 00072 mOpConstr = rOpConstr; 00073 } 00074 00075 // HioModule::OpConstr() 00076 HioConstraint HioModule::OpConstr() const { 00077 return mOpConstr; 00078 } 00079 00080 // HioModule::Plant(HioPlant) 00081 void HioModule::Plant(const HioPlant& rHioPlant){ 00082 mPlant = rHioPlant; 00083 } 00084 00085 // HioModule::Plant() 00086 HioPlant HioModule::Plant() const { 00087 return mPlant; 00088 } 00089 00090 // HioModule::Controller(HioController) 00091 void HioModule::Controller(const HioController& rHioController){ 00092 mController = rHioController; 00093 } 00094 00095 // HioModule::Controller() 00096 HioController HioModule::Controller() const { 00097 return mController; 00098 } 00099 00100 // HioModule::Children(rChildren) 00101 void HioModule::Children(const std::vector<HioModule*>& rChildren) { 00102 mChildren = rChildren; 00103 } 00104 00105 // HioModule::Children 00106 std::vector<HioModule*> HioModule::Children() const { 00107 return mChildren; 00108 } 00109 00110 // HioModule::Environment(HioEnvironment) 00111 void HioModule::Environment(const HioEnvironment& rHioEnvironment){ 00112 mEnvironment = rHioEnvironment; 00113 } 00114 00115 // HioModule::Environment() 00116 HioEnvironment HioModule::Environment() const { 00117 return mEnvironment; 00118 } 00119 00120 // HioModule::EnvConstr(rEnvConstr) 00121 void HioModule::EnvConstr(const HioConstraint& rEnvConstr){ 00122 00123 mEnvConstr = rEnvConstr; 00124 } 00125 00126 // HioModule::EnvConstr() 00127 HioConstraint HioModule::EnvConstr() const { 00128 return mEnvConstr; 00129 } 00130 00131 // HioModule::InsChild(rChild) 00132 void HioModule::InsChild(HioModule* rChild){ 00133 mChildren.push_back(rChild); 00134 } 00135 00136 ///////////////////////////////////////////////////////////////////// 00137 // from here to end of file: design specific functions by M.Musunoi 00138 // will be outsourced to something like hiodesign.cpp 00139 00140 // function to set mXpos and mYpos of the HioModule 00141 void HioModule::Position(const int Xpos, const int Ypos){ 00142 00143 mXpos = Xpos; 00144 mYpos = Ypos; 00145 } 00146 00147 // function to set the type of HioModule 00148 void HioModule::TypeHioModule(int type[5]){ 00149 00150 for (int i=0; i<=4; i++) 00151 mType[i] = type[i]; 00152 } 00153 00154 00155 00156 //ReadHioPlant: this function reads the models from the given library and 00157 //creates a general IOModulX which can be afterwards personalised. 00158 void HioModule::ReadHioPlant(const std::string path) 00159 { 00160 00161 Generator OpConstr; 00162 Generator EnvConstr; 00163 00164 std::string myType; 00165 00166 //read and set the IO Plant 00167 std::string HioPlantFile = path+"plant.gen"; 00168 mPlant.Read(HioPlantFile.c_str()); 00169 00170 //searching for the token reader "Type", and set the type of the HioPlant 00171 TokenReader tReader(HioPlantFile.c_str()); 00172 Token token; 00173 token.SetString("Type"); 00174 tReader.ReadBegin("Type"); 00175 while(tReader.Peek(token)) { 00176 // break on end 00177 if (token.Type() == Token::End) { 00178 break; 00179 } 00180 myType = tReader.ReadString(); 00181 continue; 00182 } 00183 00184 //set mType 00185 for(int i=0 ;i<=4;i++) 00186 { 00187 char tmpChar = myType.at(i); 00188 std::stringstream Str; 00189 Str << tmpChar; 00190 int d; 00191 Str >> d; 00192 00193 mType[i] = d; 00194 } 00195 00196 //read and set the Operator-Constraint 00197 std::string LpFile = path+"constrP.gen"; 00198 mOpConstr.Read(LpFile.c_str()); 00199 00200 00201 //load and set the Environment-Constraint 00202 std::string LeFile = path+"constrE.gen"; 00203 mEnvConstr.Read(LeFile.c_str()); 00204 00205 } //end of ReadHioPlant() 00206 00207 00208 //loadLibEnv: this function loads the model of interaction of IO-Plants with 00209 //the environment and creates a general IOEnvironment. 00210 void HioModule::ReadHioEnv(const std::string path) 00211 00212 { 00213 std::string EnvFile = path+"environment.gen"; 00214 mEnvironment.Read(EnvFile.c_str()); 00215 } 00216 00217 00218 //AdjusTimedGenerator: this function converts a generator by renaming all events from 00219 //"CBx_..." to "CBi_..."; 00220 void HioModule::AdjusTimedGenerator(const Generator& rOldGen, 00221 const int i, 00222 Generator& rResGen) 00223 { 00224 EventSet newAlph; 00225 TransSet::Iterator tit; 00226 StateSet::Iterator sit; 00227 EventSet::Iterator evit; 00228 std::string toSeti = ToStringInteger(i); 00229 std::string toSet = "CB"+toSeti+"_"; 00230 00231 00232 //check if generator not already in converted form; if already converted, return 00233 //sperk: throw exception? 00234 for (evit = rOldGen.AlphabetBegin(); evit != rOldGen.AlphabetEnd(); ++evit) 00235 { 00236 00237 std::string oldName = rOldGen.Alphabet().SymbolicName(*evit); 00238 //int loc1 = oldName.find(toSet, 0); 00239 //if( loc1 != std::string::npos ) 00240 if( oldName.find(toSet, 0) != std::string::npos ) 00241 { 00242 std::cout<<"At least one event already converted"; 00243 rResGen = rOldGen; 00244 return; 00245 } 00246 } 00247 00248 // first state to be inserted in the new, empty rResult generator 00249 int state = 1; 00250 00251 //rename events an insert the resulting alphabet in rResult 00252 AdjustAlphabet(rOldGen.Alphabet(), i, newAlph); 00253 rResGen.InjectAlphabet(newAlph); 00254 00255 //insert states in rResult; 00256 for (sit = rOldGen.StatesBegin(); sit != rOldGen.StatesEnd(); ++sit) 00257 { 00258 rResGen.InsMarkedState(ToStringInteger(state)); 00259 //if actual state also init state then mark it as init state in rResult too; 00260 if(rOldGen.ExistsInitState(state)) 00261 rResGen.SetInitState(ToStringInteger(state)); 00262 00263 state++; 00264 } 00265 00266 //iterate through all states 00267 for (sit = rOldGen.StatesBegin(); sit != rOldGen.StatesEnd(); ++sit) 00268 { 00269 //iterate through all transitions of the actual state; rename the events 00270 //of each transition and insert the new transition in rResult 00271 for (tit = rOldGen.TransRelBegin(*sit); tit != rOldGen.TransRelEnd(*sit); ++tit) 00272 { 00273 std::string oldName = rOldGen.EventName(tit->Ev); 00274 int loc1 = oldName.find("_", 0); 00275 std::string newName = oldName.erase(0,loc1+1); 00276 newName = toSet + oldName; 00277 00278 Idx idx_event = rResGen.EventIndex(newName); 00279 rResGen.SetTransition(tit->X1, idx_event, tit->X2); 00280 } 00281 } 00282 00283 } //END ADJUSTGENERATOR 00284 00285 00286 // AdjustHioPlant(): convenience function (derived from AdjusTimedGenerator())to 00287 // allow also the conversion of HioPlants 00288 void HioModule::AdjustHioPlant( 00289 const HioPlant& rOldHioPlant, 00290 const int i, 00291 HioPlant& rResGen) 00292 { 00293 EventSet newAlph; 00294 EventSet::Iterator evit; 00295 TransSet::Iterator tit; 00296 StateSet::Iterator sit; 00297 std::string toSeti = ToStringInteger(i); 00298 std::string toSet = "CB"+toSeti+"_"; 00299 00300 //check if generator not already in converted form 00301 for (evit = rOldHioPlant.AlphabetBegin(); evit != rOldHioPlant.AlphabetEnd(); ++evit) 00302 { 00303 00304 std::string oldName = rOldHioPlant.Alphabet().SymbolicName(*evit); 00305 //int loc1 = oldName.find(toSet, 0); 00306 //if( loc1 != std::string::npos ) 00307 if( oldName.find(toSet, 0) != std::string::npos ) 00308 { 00309 std::cout<<"At least one event already converted"; 00310 rResGen = rOldHioPlant; 00311 return; 00312 } 00313 } 00314 // first state to be inserted in the new, empty rResult generator 00315 int state = 1; 00316 00317 //rename events by preserving the events attributes 00318 //Yp-Events 00319 AdjustAlphabet(rOldHioPlant.YpEvents(), i, newAlph); 00320 for(evit = newAlph.Begin(); evit != newAlph.End(); ++evit) 00321 rResGen.InsYpEvent(*evit); 00322 newAlph.Clear(); 00323 00324 //Up-Events 00325 AdjustAlphabet(rOldHioPlant.UpEvents(), i, newAlph); 00326 for(evit = newAlph.Begin(); evit != newAlph.End(); ++evit) 00327 rResGen.InsUpEvent(*evit); 00328 newAlph.Clear(); 00329 00330 //Ye-Events 00331 AdjustAlphabet(rOldHioPlant.YeEvents(), i, newAlph); 00332 for(evit = newAlph.Begin(); evit != newAlph.End(); ++evit) 00333 rResGen.InsYeEvent(*evit); 00334 newAlph.Clear(); 00335 00336 //Ue-Events 00337 AdjustAlphabet(rOldHioPlant.UeEvents(), i, newAlph); 00338 for(evit = newAlph.Begin(); evit != newAlph.End(); ++evit) 00339 rResGen.InsUeEvent(*evit); 00340 newAlph.Clear(); 00341 00342 //insert states in rResult; 00343 for (sit = rOldHioPlant.StatesBegin(); sit != rOldHioPlant.StatesEnd(); ++sit) 00344 { 00345 rResGen.InsMarkedState(ToStringInteger(state)); 00346 //if actual state also init state then mark it as init state in rResult too; 00347 if(rOldHioPlant.ExistsInitState(state)) 00348 rResGen.SetInitState(ToStringInteger(state)); 00349 00350 state++; 00351 } 00352 //iterate through all states 00353 for (sit = rOldHioPlant.StatesBegin(); sit != rOldHioPlant.StatesEnd(); ++sit) 00354 { 00355 //iterate through all transitions of the actual state; rename the events 00356 //of each transition and insert the new transition in rResult 00357 for (tit = rOldHioPlant.TransRelBegin(*sit); tit != rOldHioPlant.TransRelEnd(*sit); ++tit) 00358 { 00359 std::string oldName = rOldHioPlant.EventName(tit->Ev); 00360 int loc1 = oldName.find("_", 0); 00361 std::string newName = oldName.erase(0,loc1+1); 00362 newName = toSet + oldName; 00363 00364 Idx idx_event = rResGen.EventIndex(newName); 00365 rResGen.SetTransition(tit->X1, idx_event, tit->X2); 00366 } 00367 } 00368 } //End of AdjustHioPlant() 00369 00370 00371 // AdjustAlph(): this function converts an alphabet by renaming all events from 00372 // "CBx_..." to "CBi_..."; 00373 // Warning: This function does not preserves the attributes of the events! 00374 void HioModule::AdjustAlphabet( 00375 const EventSet& rOldAlph, 00376 const int i, 00377 EventSet& rResAlph) 00378 { 00379 EventSet::Iterator evit; 00380 std::string toSeti = ToStringInteger(i); 00381 std::string toSet = "CB"+toSeti+"_"; 00382 00383 //check if alphabet not already in converted form 00384 for (evit = rOldAlph.Begin(); evit != rOldAlph.End(); ++evit) 00385 { 00386 std::string oldName = rOldAlph.SymbolicName(*evit); 00387 //int loc1 = oldName.find(toSet, 0); 00388 //if( loc1 != std::string::npos ) 00389 if( oldName.find(toSet, 0) != std::string::npos ) 00390 { 00391 std::cout<<"At least one event already converted"; 00392 rResAlph = rOldAlph; 00393 return; 00394 } 00395 } 00396 00397 //iterate through the alphabet and adjust every event 00398 for (evit = rOldAlph.Begin(); evit != rOldAlph.End(); ++evit) 00399 { 00400 std::string oldName = rOldAlph.SymbolicName(*evit); 00401 int loc1 = oldName.find("_", 0); 00402 std::string newName1 = oldName.erase(0,loc1+1); 00403 std::string newName = toSet + oldName; 00404 00405 rResAlph.Insert(newName); 00406 00407 } 00408 } //End of AdjustAlphabet 00409 00410 00411 // AdjustEnvironmet: This function adjusts the master copy (IOEnviromntX) to 00412 // the two IO-Plants. 00413 void HioModule::AdjustHioEnvironment( 00414 const HioEnvironment& rHioEnvX, 00415 const HioModule* rHioModule1, 00416 const HioModule* rHioModule2, 00417 HioEnvironment& rResEnv) 00418 { 00419 EventSet tmpAlph; 00420 EventSet::Iterator evit; 00421 StateSet::Iterator sit; 00422 TransSet::Iterator tit; 00423 00424 00425 00426 tmpAlph = rHioEnvX.Alphabet(); 00427 int leftId, rightId; // 00428 int state = 1; 00429 // strings to replace the standard event names: CBx_, CBy_, CBxy_ 00430 std::string toRepl_left, toRepl_right, toRepl_ext; 00431 00432 // check the relative position of the 2 HioModule to each other and prepare 00433 // the strings to be set, according to the Id of each IOMOdule 00434 if (rHioModule1->Xpos() <= rHioModule2->Xpos()) 00435 { 00436 //HioModule1 at the left of HioModule2 00437 leftId = rHioModule1->Index(); 00438 toRepl_left = "CB"+ToStringInteger(leftId)+"_"; 00439 00440 rightId = rHioModule2->Index(); 00441 toRepl_right = "CB"+ToStringInteger(rightId)+"_"; 00442 00443 toRepl_ext = "CB"+ToStringInteger(leftId)+ 00444 ToStringInteger(rightId)+"_"; 00445 } 00446 else 00447 { 00448 //HioModule1 at the right of HioModule2 00449 leftId = rHioModule2->Index(); 00450 toRepl_left = "CB"+ToStringInteger(leftId)+"_"; 00451 00452 rightId = rHioModule1->Index(); 00453 toRepl_right = "CB"+ToStringInteger(rightId)+"_"; 00454 00455 toRepl_ext = "CB"+ToStringInteger(leftId)+ 00456 ToStringInteger(rightId)+"_"; 00457 } 00458 00459 //check if generator not already in converted form 00460 for (evit = rHioEnvX.AlphabetBegin(); evit != rHioEnvX.AlphabetEnd(); ++evit) 00461 { 00462 00463 std::string oldName = rHioEnvX.Alphabet().SymbolicName(*evit); 00464 //int loc1 = oldName.find(toRepl_ext, 0); 00465 //if( loc1 != std::string::npos ) 00466 if( oldName.find(toRepl_ext, 0) != std::string::npos ) 00467 { 00468 std::cout<<"At least one event already converted"; 00469 rResEnv = rHioEnvX; 00470 return; 00471 } 00472 } 00473 00474 //**********************Adjust the Alphabet**************** 00475 //iterate through all events and replace 00476 // CBx_-events with toRepl_left 00477 // CBy_-events with toRepl_right 00478 // CBxy_-events with toRepl_ext 00479 for (evit = tmpAlph.Begin(); evit != tmpAlph.End(); ++evit) 00480 { 00481 //get actual event name 00482 std::string eventName = tmpAlph.SymbolicName(*evit); 00483 00484 // actual event is a "left-Plant" event? (Ye or Ue) 00485 std::string::size_type loc1 = eventName.find("CBx_", 0); 00486 if (loc1 != std::string::npos) 00487 { 00488 eventName.erase(0, 4); 00489 std::string newEvent = toRepl_left+eventName; 00490 //std::string newEvent = eventName.replace(0,toRepl_left.size(), toRepl_left); 00491 if(rHioEnvX.IsYe(*evit)) 00492 { 00493 rResEnv.InsYeEvent(newEvent); 00494 } 00495 else 00496 { 00497 rResEnv.InsUeEvent(newEvent); 00498 } 00499 } 00500 else 00501 { 00502 // actual event is a "right-Plant" event? 00503 std::string::size_type loc2 = eventName.find("CBy_", 0); 00504 if (loc2 != std::string::npos) 00505 { 00506 eventName.erase(0, 4); 00507 std::string newEvent = toRepl_right+eventName; 00508 if(rHioEnvX.IsYe(*evit)) 00509 { 00510 rResEnv.InsYeEvent(newEvent); 00511 } 00512 else 00513 { 00514 rResEnv.InsUeEvent(newEvent); 00515 } 00516 } 00517 00518 else 00519 { 00520 // actual event is a "external interaction" event? (YL or UL) 00521 std::string::size_type loc3 = eventName.find("CBxy_", 0); 00522 if (loc3 != std::string::npos) 00523 { 00524 eventName.erase(0, 5); 00525 std::string newEvent = toRepl_ext+eventName; 00526 if(rHioEnvX.IsYl(*evit)) 00527 { 00528 rResEnv.InsYlEvent(newEvent); 00529 } 00530 else 00531 { 00532 rResEnv.InsUlEvent(newEvent); 00533 } 00534 } 00535 00536 } 00537 } 00538 }//*************************** End Adjust Alphabet*************** 00539 00540 // insert states into result generator 00541 for (sit = rHioEnvX.StatesBegin(); sit != rHioEnvX.StatesEnd(); ++sit) 00542 { 00543 rResEnv.InsMarkedState(ToStringInteger(state)); 00544 //if actual state also init state then mark it as init state in rResEnv too; 00545 if(rHioEnvX.ExistsInitState(state)) 00546 rResEnv.SetInitState(ToStringInteger(state)); 00547 00548 state++; 00549 } //End Insert States 00550 00551 00552 //***************************Adjust Transitions************************ 00553 // iterate through all states and all transitions. For every trasition check the 00554 // event name, and rename it as described in the sequence "Adjust Alphabet" 00555 for (sit = rHioEnvX.StatesBegin(); sit != rHioEnvX.StatesEnd(); ++sit) 00556 { 00557 //iterate through all transitions of the actuall state; 00558 for (tit = rHioEnvX.TransRelBegin(*sit); tit != rHioEnvX.TransRelEnd(*sit); ++tit) 00559 { 00560 std::string eventName = rHioEnvX.EventName(tit->Ev); 00561 00562 // actual event is a "left-Plant" event? 00563 std::string::size_type loc1 = eventName.find("CBx_", 0); 00564 if (loc1 != std::string::npos) 00565 { 00566 eventName.erase(0, 4); 00567 std::string newEvent = toRepl_left+eventName; 00568 eventName = newEvent; 00569 } 00570 else 00571 { 00572 // actual event is a "right-Plant" event? 00573 std::string::size_type loc2 = eventName.find("CBy_", 0); 00574 if (loc2 != std::string::npos) 00575 { 00576 eventName.erase(0, 4); 00577 std::string newEvent = toRepl_right+eventName; 00578 eventName = newEvent; 00579 } 00580 else 00581 { 00582 // actual event is a "external interaction" event? 00583 std::string::size_type loc3 = eventName.find("CBxy_", 0); 00584 if (loc3 != std::string::npos) 00585 { 00586 eventName.erase(0, 5); 00587 std::string newEvent = toRepl_ext+eventName; 00588 eventName = newEvent; 00589 } 00590 } 00591 } 00592 00593 // insert transition into result 00594 Idx idx_event = rResEnv.EventIndex(eventName); 00595 rResEnv.SetTransition(tit->X1, idx_event, tit->X2); 00596 } // end for-loop over transition 00597 } // end for-loop over states 00598 00599 } // end of AdjustHioEnvironment() 00600 00601 00602 // AdjustHioController: This function adjust an already computed IOController to 00603 // apply with the two IO-Plants (that enforces a well-defined specification). 00604 void AdjustHioController( 00605 const HioController& rHioController, 00606 const HioModule* rHioModule1, 00607 const HioModule* rHioModule2, 00608 HioController& rResEnv) 00609 { 00610 EventSet tmpAlph; 00611 EventSet::Iterator evit; 00612 StateSet::Iterator sit; 00613 TransSet::Iterator tit; 00614 00615 tmpAlph = rHioController.Alphabet(); 00616 int leftId, rightId; // 00617 int state = 1; 00618 00619 // strings to replace the standard event names: CBx_, CBy_, CBxy_ 00620 std::string toRepl_left, toRepl_right, toRepl_ext; 00621 00622 00623 // check the relative position of the 2 HioModule to each other and prepare 00624 // the strings to be set, according to the Id of each IOMOdule 00625 if (rHioModule1->Xpos() <= rHioModule2->Xpos()) 00626 { 00627 //HioModule1 at the left of HioModule2 00628 leftId = rHioModule1->Index(); 00629 toRepl_left = "CB"+ToStringInteger(leftId)+"_"; 00630 00631 rightId = rHioModule2->Index(); 00632 toRepl_right = "CB"+ToStringInteger(rightId)+"_"; 00633 00634 toRepl_ext = "CB"+ToStringInteger(leftId)+ 00635 ToStringInteger(rightId)+"_"; 00636 } 00637 else 00638 { 00639 //HioModule1 at the right of HioModule2 00640 leftId = rHioModule2->Index(); 00641 toRepl_left = "CB"+ToStringInteger(leftId)+"_"; 00642 00643 rightId = rHioModule1->Index(); 00644 toRepl_right = "CB"+ToStringInteger(rightId)+"_"; 00645 00646 toRepl_ext = "CB"+ToStringInteger(leftId)+ 00647 ToStringInteger(rightId)+"_"; 00648 } 00649 00650 //check if generator not already in converted form 00651 for (evit = rHioController.AlphabetBegin(); evit != rHioController.AlphabetEnd(); ++evit) 00652 { 00653 00654 std::string oldName = rHioController.Alphabet().SymbolicName(*evit); 00655 //int loc1 = oldName.find(toRepl_ext, 0); 00656 //if( loc1 != std::string::npos ) 00657 if( oldName.find(toRepl_ext, 0) != std::string::npos ) 00658 { 00659 std::cout<<"At least one event already converted"; 00660 rResEnv = rHioController; 00661 return; 00662 } 00663 } 00664 00665 //**********************Adjust the Alphabet**************** 00666 //iterate thru all events and replace 00667 // CBx_-events with toRepl_left 00668 // CBy_-events with toRepl_right 00669 // CBxy_-events with toRepl_ext 00670 for (evit = tmpAlph.Begin(); evit != tmpAlph.End(); ++evit) 00671 { 00672 //get actual event name 00673 std::string eventName = tmpAlph.SymbolicName(*evit); 00674 00675 // actual event is a "left-Plant" event? 00676 std::string::size_type loc1 = eventName.find("CBx_", 0); 00677 if (loc1 != std::string::npos) 00678 { 00679 eventName.erase(0, 4); 00680 std::string newEvent = toRepl_left+eventName; 00681 rResEnv.InsEvent(newEvent); 00682 } 00683 else 00684 { 00685 // actual event is a "right-Plant" event? 00686 std::string::size_type loc2 = eventName.find("CBy_", 0); 00687 if (loc2 != std::string::npos) 00688 { 00689 eventName.erase(0, 4); 00690 std::string newEvent = toRepl_right+eventName; 00691 rResEnv.InsEvent(newEvent); 00692 } 00693 else 00694 { 00695 // actual event is a "external interaction" event? 00696 std::string::size_type loc3 = eventName.find("CBxy_", 0); 00697 if (loc3 != std::string::npos) 00698 { 00699 eventName.erase(0, 5); 00700 std::string newEvent = toRepl_ext+eventName; 00701 rResEnv.InsEvent(newEvent); 00702 } 00703 } 00704 } 00705 }//*************************** End Adjust Alphabet*************** 00706 00707 // insert states into result generator 00708 for (sit = rHioController.StatesBegin(); sit != rHioController.StatesEnd(); ++sit) 00709 { 00710 rResEnv.InsMarkedState(ToStringInteger(state)); 00711 //if actual state also init state then mark it as init state in rResEnv too; 00712 if(rHioController.ExistsInitState(state)) 00713 rResEnv.SetInitState(ToStringInteger(state)); 00714 00715 state++; 00716 } //End Insert States 00717 00718 00719 //***************************Adjust Transitions************************ 00720 // iterate through all states and all transitions. For every trasition check the 00721 // event name, and rename it as described in the sequence "Adjust Alphabet" 00722 for (sit = rHioController.StatesBegin(); sit != rHioController.StatesEnd(); ++sit) 00723 { 00724 //iterate through all transitions of the actuall state; 00725 for (tit = rHioController.TransRelBegin(*sit); tit != rHioController.TransRelEnd(*sit); ++tit) 00726 { 00727 std::string eventName = rHioController.EventName(tit->Ev); 00728 00729 // actual event is a "left-Plant" event? 00730 std::string::size_type loc1 = eventName.find("CBx_", 0); 00731 if (loc1 != std::string::npos) 00732 { 00733 eventName.erase(0, 4); 00734 std::string newEvent = toRepl_left+eventName; 00735 eventName = newEvent; 00736 } 00737 else 00738 { 00739 // actual event is a "right-Plant" event? 00740 std::string::size_type loc2 = eventName.find("CBy_", 0); 00741 if (loc2 != std::string::npos) 00742 { 00743 eventName.erase(0, 4); 00744 std::string newEvent = toRepl_right+eventName; 00745 eventName = newEvent; 00746 } 00747 else 00748 { 00749 // actual event is a "external interaction" event? 00750 std::string::size_type loc3 = eventName.find("CBxy_", 0); 00751 if (loc3 != std::string::npos) 00752 { 00753 eventName.erase(0, 5); 00754 std::string newEvent = toRepl_ext+eventName; 00755 eventName = newEvent; 00756 } 00757 } 00758 } 00759 00760 // insert transition into result 00761 Idx idx_event = rResEnv.EventIndex(eventName); 00762 rResEnv.SetTransition(tit->X1, idx_event, tit->X2); 00763 } // end for-loop over transition 00764 } // end for-loop over states 00765 00766 } //End Adjust IOController 00767 00768 00769 // RenameHioModule: this function personalises a HioModule by renaming the content 00770 // of the single modules member 00771 void HioModule::RenameHioModule(const int i) 00772 { 00773 HioPlant tmpHioPlant; 00774 Generator tmpOpConstr, tmpEnvConstr; 00775 HioEnvironment tmpHioEnv; 00776 00777 //adjust the mPlant member 00778 AdjustHioPlant(mPlant, i, tmpHioPlant); 00779 00780 //adjust the constraints 00781 AdjusTimedGenerator(mOpConstr, i, tmpOpConstr); 00782 AdjusTimedGenerator(mEnvConstr, i, tmpEnvConstr); 00783 00784 //set the members 00785 mPlant = tmpHioPlant; 00786 mOpConstr = tmpOpConstr; 00787 mEnvConstr = tmpEnvConstr; 00788 00789 //adjust the Id 00790 mIndex = i; 00791 00792 //adjust the name: 00793 mName = "CB"+ToStringInteger(i); 00794 00795 //check if also an environment is available, if so adjust it too 00796 if(mChildren.size() != 0) 00797 { 00798 AdjustHioEnvironment(mEnvironment, mChildren[0], mChildren[1], tmpHioEnv); 00799 mEnvironment = tmpHioEnv; 00800 } 00801 00802 }// end of RenameHioModule() 00803 00804 00805 // chooseSpec: this function searches through an apappropriate folder for available 00806 // specifications. 00807 std::vector<std::string> HioModule::ChooseSpec( 00808 const std::string path) 00809 { 00810 int capacity = 0; 00811 int size; 00812 std::string loc_path = ""; 00813 std::vector<std::string> listSpec, tmpListSpec, pathList; 00814 std::list<std::string>::iterator itstr; 00815 00816 //check to max capacity 00817 size = mChildren.size(); 00818 std::cout<<"Number of children: "<<size<<std::endl; 00819 for(int i=0; i<size; i++) 00820 { 00821 //The "mType"-array stores at pos 0 the capacity of an plant model 00822 capacity = mChildren[i]->TypeHioModule()[0] + capacity; 00823 } 00824 00825 //prepare the local path to read from 00826 std::string cap = "SpecCB"; 00827 std::vector<std::string> allPath; 00828 for (int i=1; i<=capacity;i++) 00829 { 00830 cap = cap + ToStringInteger(i); 00831 loc_path = path+cap+"/"; 00832 allPath.push_back(loc_path); 00833 } 00834 //list the available specifications 00835 for (int i=0; i<capacity;i++) 00836 { 00837 // e.g.: resultin string = ../Spec/SpecCB123/ 00838 loc_path = allPath[i]; 00839 std::cout<<"Final path: "<<loc_path<<std::endl; 00840 //check folder for specification and show them to the user 00841 tmpListSpec = ListFolderContent(loc_path.c_str()); 00842 int size = tmpListSpec.size(); 00843 00844 for(int i = 0; i<size; i++) 00845 { 00846 listSpec.push_back(tmpListSpec[i]); 00847 std::string tmpPath; 00848 tmpPath = loc_path+tmpListSpec[i]+"/"; 00849 pathList.push_back(tmpPath); 00850 } 00851 } 00852 00853 std::cout<<"There are "<<listSpec.size()<<" spec. available"<<std::endl; 00854 size = listSpec.size(); 00855 for(int i=0; i<size;i++) 00856 { 00857 std::cout<<"Option: "<<i+1<<":"<<listSpec[i]<<std::endl; 00858 } 00859 //delete.... 00860 //int choise=1; 00861 //std::cin>>choise; 00862 00863 //encode specification type to the user 00864 //EncodeType(listSpec[choise-1].c_str()); 00865 00866 //loc_path = loc_path+listSpec[choise-1]+"/"; 00867 00868 //loc_path = pathList[choise-1]; 00869 //ReadHioPlant(loc_path.c_str()); 00870 00871 //std::cout<<"My type is: "<<mType[0]<<mType[1]<<mType[2]<<mType[3]<<mType[4]<<std::endl; 00872 00873 //do this as a final step.... 00874 //RenameHioModule(mId); 00875 return listSpec; 00876 00877 }// end of chooseSpec() 00878 00879 // function to compute the IOController 00880 void HioModule::Compute() { 00881 00882 // FindController: check if an IO-Controller is already available; if case 00883 // of a positive result (print the IOController statistics) and inform the 00884 // user about the found IO-Controller. The user can decide whether or not 00885 // the found IO-Controller will be used, or to compute a new IO-Controller. 00886 if(FindController()) 00887 { 00888 HioController tmpHioController; 00889 std::string loc_path, choice; 00890 00891 loc_path = MyPath()+"ioController.gen"; 00892 tmpHioController.Read(loc_path.c_str()); 00893 tmpHioController.SWrite(); 00894 std::cout<<"Controller found..! Accept(Y)? / New controller(N)?"<<std::endl; 00895 std::cin>>choice; 00896 00897 if(choice == "y" || choice == "Y") 00898 { 00899 mController = tmpHioController; 00900 return; 00901 } 00902 00903 } 00904 else 00905 { 00906 std::cout<<"Controller NOT found..!"<<std::endl; 00907 } 00908 Generator IOShufflemin, IOShuffle; 00909 std::cout.flush()<<"Starting IOShuffle...1"<<std::endl; 00910 HioShuffle_Musunoi(mChildren[0]->Plant(), mChildren[1]->Plant(), 1, IOShufflemin); 00911 00912 std::cout.flush()<<" ...done!"<<std::endl; 00913 StateMin(IOShufflemin, IOShuffle); 00914 00915 //Start parallel composition with environment and load the local constraints 00916 Generator ioShCB12parEnv, locConstr; 00917 00918 Parallel(IOShuffle, mEnvironment, ioShCB12parEnv); 00919 //remove generator that are not in use anymore 00920 IOShuffle.Clear(); 00921 00922 Generator tmp1, tmp2; // generator for intermediate result 00923 Parallel(mChildren[0]->OpConstr(), mChildren[0]->EnvConstr(), tmp1); 00924 Parallel(mChildren[1]->OpConstr(), mChildren[1]->EnvConstr(), tmp2); 00925 Parallel(tmp1, tmp2, locConstr); 00926 00927 //remove generator that are not in use anymore 00928 tmp1.Clear(); 00929 tmp2.Clear(); 00930 00931 00932 //Start HIO_SYNTHESIS 00933 00934 Generator extConstr; 00935 00936 //external constraints 00937 Parallel(mOpConstr, mEnvConstr, extConstr); 00938 00939 std::cout<<"**********************//////\\\\\\*******************"<<std::endl; 00940 std::cout<<"Everything went fine so far...startig HIO_SYNTHESIS..."<<std::endl; 00941 std::cout<<"**********************\\\\\\//////*******************"<<std::endl; 00942 00943 //temp generators and event-sets for intermediate results 00944 Generator tmpController, tmpHioGen; 00945 EventSet Yp, Up, Yc, Uc, Ye, Ue; 00946 00947 Yp = (mChildren[0]->Plant().YpEvents()+mChildren[1]->Plant().YpEvents()); 00948 Up = (mChildren[0]->Plant().UpEvents()+mChildren[1]->Plant().UpEvents()); 00949 Yc = (mPlant.YpEvents()); 00950 Uc = (mPlant.UpEvents()); 00951 Ye = (mPlant.YeEvents()); 00952 Ue = (mPlant.UeEvents()); 00953 00954 tmpHioGen.Assign(mPlant); 00955 00956 //start the hio-synthesis 00957 HioSynth_Musunoi(ioShCB12parEnv, mPlant, extConstr, locConstr, Yp, Up, tmpController); 00958 00959 mController = tmpController; 00960 00961 00962 EventSet::Iterator evit; 00963 // As the result of the controller synthesis is a genarator, we set the 00964 // event properties in order to obtain a HioController 00965 for(evit = Yc.Begin(); evit != Yc.End(); ++evit) 00966 mController.SetYc(*evit); 00967 00968 for(evit = Uc.Begin(); evit != Uc.End(); ++evit) 00969 mController.SetUc(*evit); 00970 00971 Yp.DWrite(); 00972 for(evit = Yp.Begin(); evit != Yp.End(); ++evit) 00973 mController.SetYp(*evit); 00974 00975 for(evit = Up.Begin(); evit != Up.End(); ++evit) 00976 mController.SetUp(*evit); 00977 00978 std::cout.flush()<<"...Done"<<std::endl; 00979 00980 std::string filename = "Controller"+ToStringInteger(mIndex)+".gen"; 00981 mController.Write(filename.c_str()); 00982 00983 00984 } //End of Compute(); 00985 00986 00987 //FindController(): this function searches in the folder of a choosen 00988 //specification for an already computed IO-controller which enforces this 00989 //specification (sought: "ioController.gen") 00990 bool HioModule::FindController() 00991 { 00992 00993 //the path where to look up for the sought IO-Controller is based on the 00994 //type of the specification 00995 std::vector<std::string> folderContent; 00996 std::string loc_path; 00997 00998 //find the local path 00999 loc_path = MyPath(); 01000 folderContent = ListFolderContent(loc_path.c_str()); 01001 int size = folderContent.size(); 01002 01003 for(int i=0; i<size; i++) 01004 if (folderContent[i]== "ioController.gen") 01005 return true; 01006 01007 return false; 01008 } //End of FindController() 01009 01010 01011 // Save: this function saves the computed controller in the same folder with 01012 // the specification that this controller enforces 01013 void HioModule::SaveController() 01014 { 01015 std::string loc_path; 01016 loc_path = MyPath(); 01017 loc_path = loc_path+"ioController.gen"; 01018 01019 mController.Write(loc_path.c_str()); 01020 } //End of SaveController() 01021 01022 01023 //MyPath: based on the type of the HioModule, this is a convenience function to 01024 // establish the local path where to Write/Read from. 01025 std::string HioModule::MyPath() 01026 { 01027 int capacity = mType[0]; 01028 std::vector<std::string> folderContent; 01029 std::string cap, loc_path, sub_folder; 01030 01031 01032 for (int i=1; i<=capacity; i++) 01033 { 01034 cap = cap + ToStringInteger(i); 01035 } 01036 01037 for (int i=0; i<5;i++) 01038 { 01039 sub_folder = sub_folder+ToStringInteger(mType[i]); 01040 } 01041 01042 //path to search 01043 loc_path = "Data/Spec/SpecCB"+cap+"/"+sub_folder+"/"; 01044 return loc_path; 01045 } //end MyPath() 01046 01047 01048 /********************************************** 01049 ********************************************** 01050 * 01051 * functions to call properties of the HioModule 01052 ********************************************** 01053 ***********************************************/ 01054 01055 // function to call the x-Positon of the HioModule 01056 int HioModule::Xpos() const { 01057 01058 return mXpos; 01059 } 01060 01061 01062 // function to call the y-Positon of the HioModule 01063 int HioModule::Ypos() const { 01064 01065 return mYpos; 01066 } 01067 01068 // function to call the type of the HioModule 01069 int* HioModule::TypeHioModule() const { 01070 01071 int* type = new int[5]; 01072 for (int i=0; i<=4; i++) 01073 type[i] = mType[i]; 01074 01075 return type; 01076 } 01077 01078 01079 // function to encode to Type of the HioModule 01080 void HioModule::EncodeType(const std::string type) { 01081 01082 std::cout<<"***********Capacity: "<<type.at(0)<<"******"<<std::endl; 01083 std::cout<<"*Take from left: "<<type.at(1)<<"* "<<" *Take from right: "<<type.at(2)<<"*"<<std::endl; 01084 std::cout<<"*Deliver to left: "<<type.at(3)<<"* "<<" *Deliver to right: "<<type.at(4)<<"*"<<std::endl; 01085 01086 } 01087 01088 /******************************************************************************* 01089 ***************************END OF IOMODULE CLASS DEFINITION******************** 01090 ******************************************************************************/ 01091 01092 01093 // GroupHioModules: This function groups two or more HioModules to a new HioModule. 01094 void GroupHioModules( 01095 const std::vector<HioModule*>& rChildren, 01096 HioModule& rParentModule) 01097 { 01098 int size = rChildren.size(); 01099 float Id =0; 01100 for (int i =0; i < size; i++) 01101 { 01102 rParentModule.InsChild(rChildren[i]); 01103 std::cout<<"insert #"<<i<<"- ModuleID: "<<rChildren[i]->Index(); 01104 // Id is composed of children Id's 01105 Id = pow(10, size-i-1)*rChildren[i]->Index()+Id; 01106 std::cout<<".."<<Id<<std::endl; 01107 } 01108 std::cout<<"Id set!"<<std::endl; 01109 //read the environment describing the interaction between the grouped components 01110 HioEnvironment HioEnv("Data/envCBxy.gen"); 01111 01112 //set the new Id of the module, and adjust the environment 01113 int intId = int(Id); 01114 rParentModule.Environment(HioEnv); 01115 rParentModule.RenameHioModule(intId); 01116 01117 }// end of GroupHioModule() 01118 01119 01120 //CreateSpec() 01121 void CreateSpec(int mType[5], HioPlant& rHioSpec, Generator& constrP, Generator& constrE) 01122 { 01123 01124 // initiate several variables; variables to store information about the number 01125 // of the take and deliver actions and last known state. 01126 int loaded, fl, fr, tol, tor, i_lastState, index; 01127 std::string s_lastQy, s_lastQup, s_lastQue, s_lastState, s_lastQy_stby, s_newQy_stby; 01128 std::string s_lastQupFL, s_lastQupFR, s_lastQup2L, s_lastQup2R, s_newQy_FR, s_newQy_FL, s_newQy_2L, s_newQy_2R; 01129 01130 s_lastQup = s_lastQupFL = s_lastQupFR = s_newQy_stby = "ErrQy"; 01131 fl=fr=tol=tor=i_lastState=index=loaded=0; 01132 01133 //Insert alphabet 01134 rHioSpec.InsYpEvent("CBx_free"); 01135 rHioSpec.InsYpEvent("CBx_busy"); 01136 rHioSpec.InsUpEvent("CBx_stby"); 01137 rHioSpec.InsUpEvent("CBx_FL"); 01138 rHioSpec.InsUpEvent("CBx_FR"); 01139 rHioSpec.InsUpEvent("CBx_2L"); 01140 rHioSpec.InsUpEvent("CBx_2R"); 01141 rHioSpec.InsYeEvent("CBx_req_fl"); 01142 rHioSpec.InsYeEvent("CBx_req_fr"); 01143 rHioSpec.InsYeEvent("CBx_wpar_fl"); 01144 rHioSpec.InsYeEvent("CBx_wpar_fr"); 01145 rHioSpec.InsYeEvent("CBx_wpar_tl"); 01146 rHioSpec.InsYeEvent("CBx_wpar_tr"); 01147 rHioSpec.InsUeEvent("CBx_pack"); 01148 rHioSpec.InsUeEvent("CBx_nack"); 01149 01150 //Insert error state 01151 rHioSpec.InsMarkedState("ErrQy"); 01152 01153 //1. Create init state and the first transitions; in order to save the last added 01154 // state and/or transition, set the respective variable ("s_lastQup", "i_lastState") 01155 rHioSpec.InsInitState("1"); 01156 rHioSpec.SetMarkedState("1"); 01157 rHioSpec.InsMarkedState("2"); 01158 rHioSpec.SetTransition("1", "CBx_free", "2"); 01159 s_lastQup = "2"; 01160 rHioSpec.SetTransition("2", "CBx_stby", "1"); 01161 i_lastState = 2; 01162 01163 /*************** Interpretation of mType[] ******* 01164 ************* Capacity: mType[0] ********* 01165 ************* Take from left: mType[1] ********* 01166 ************* Take from right: mType[2] ********* 01167 ************* Deliver to left: mType[3] ********* 01168 ************* Deliver to left: mType[4] ********* 01169 ************************************************/ 01170 01171 01172 //2. so called "Qy_stby" - states are of states were we decied if an other 01173 // "Take from..." or "Deliver to..." - cycle must be added to the specification. 01174 // This are also states where the specification branch out, so it is important 01175 // to keep this state in order to implement all transitions starting here. 01176 01177 // "index" - stores the information about the capacity, i.e. how many times we 01178 // need to add the "Take from..." "Deliver from" cycle 01179 for(int i=0; i<mType[0]; i++) 01180 { 01181 s_lastQy_stby = s_newQy_stby; 01182 index++; 01183 01184 //if no piece loaded yet, deliver actions would lead to an Error state 01185 if(loaded == 0) 01186 { 01187 rHioSpec.SetTransition(s_lastQup, "CBx_2L", "ErrQy"); 01188 s_lastQup2L = "ErrQy"; 01189 rHioSpec.SetTransition(s_lastQup, "CBx_2R", "ErrQy"); 01190 s_lastQup2R = "ErrQy"; 01191 } 01192 01193 // the value of "fl" holds how many "Take from left"-cycles we already implemented 01194 // in the specification. If the fl < requested "Take from left"- operations, 01195 // implement an other one. 01196 if(fl<mType[1]) 01197 { 01198 // if index = 1 then we are in the first implementation cycle 01199 // so need to insert a new state. (in the next cycles, this 01200 // state will have be already inserted -> see "else" statement) 01201 if(!(index > 1)) 01202 { 01203 s_lastState = ToStringInteger(i_lastState+1); 01204 rHioSpec.InsMarkedState(s_lastState); 01205 } 01206 else 01207 { 01208 // hold that the last inserted state is "Qy"-state that 01209 // we arrive through a "Take from" - transition 01210 s_lastState = s_newQy_FL; 01211 } 01212 01213 //insert the corresponding "Take from" - transition 01214 rHioSpec.SetTransition(s_lastQup, "CBx_FL", s_lastState); 01215 s_lastQy = s_lastState; 01216 i_lastState++; 01217 01218 //insert the corresponding "request from" - transition; 01219 //therefor we first need to insert a new state 01220 s_lastState = ToStringInteger(i_lastState+1); 01221 rHioSpec.InsMarkedState(s_lastState); 01222 rHioSpec.SetTransition(s_lastQy, "CBx_req_fl", s_lastState); 01223 s_lastQue = s_lastState; 01224 i_lastState++; 01225 01226 //insert the corresponding "acknowledge" - transition 01227 //therefor we first need to insert a new state 01228 s_lastState = ToStringInteger(i_lastState+1); 01229 rHioSpec.InsMarkedState(s_lastState); 01230 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastState); 01231 s_lastQy = s_lastState; 01232 i_lastState++; 01233 01234 //Ue must be free -> insert transition to error-state 01235 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01236 01237 //insert the corresponding "busy" - transition 01238 //therefor we first need to insert a new state 01239 s_lastState = ToStringInteger(i_lastState+1); 01240 rHioSpec.InsMarkedState(s_lastState); 01241 rHioSpec.SetTransition(s_lastQy, "CBx_busy", s_lastState); 01242 s_lastQupFL = s_lastState; 01243 i_lastState++; 01244 01245 //update the status of the loaded number of pieces 01246 loaded = index; 01247 //update the number of implemented "Take from Left" - cycles 01248 fl++; 01249 01250 } 01251 //Up must be free -> insert transition to error-state; 01252 else 01253 { 01254 rHioSpec.SetTransition(s_lastQup, "CBx_FL", "ErrQy"); 01255 s_lastQupFL = "ErrQy"; 01256 } 01257 01258 01259 //as "Take from left" or "Take from right" are simetrical, the implementation 01260 //is also the same as above 01261 // the value of "fr" holds how many "Take from right"-cycles we already implemented 01262 // in the specification. If the fr < requested "Take from right"- operations, 01263 // implement an other one. 01264 if(fr<mType[2]) 01265 { 01266 // if index = 1 then we are in the first implementation cycle 01267 // so need to insert a new state. (in the next cycles, this 01268 // state will have be already inserted -> see "else" statement) 01269 if(!(index > 1)) 01270 { 01271 s_lastState = ToStringInteger(i_lastState+1); 01272 rHioSpec.InsMarkedState(s_lastState); 01273 } 01274 else 01275 { 01276 // hold that the last inserted state is "Qy"-state that 01277 // we arrive through a "Take from" - transition 01278 s_lastState = s_newQy_FR; 01279 } 01280 01281 //insert the corresponding "Take from" - transition 01282 rHioSpec.SetTransition(s_lastQup, "CBx_FR", s_lastState); 01283 s_lastQy = s_lastState; 01284 i_lastState++; 01285 01286 //insert the corresponding "request from" - transition; 01287 //therefor we first need to insert a new state 01288 s_lastState = ToStringInteger(i_lastState+1); 01289 rHioSpec.InsMarkedState(s_lastState); 01290 rHioSpec.SetTransition(s_lastQy, "CBx_req_fr", s_lastState); 01291 s_lastQue = s_lastState; 01292 i_lastState++; 01293 01294 //insert the corresponding "acknowledge" - transition 01295 //therefor we first need to insert a new state 01296 s_lastState = ToStringInteger(i_lastState+1); 01297 rHioSpec.InsMarkedState(s_lastState); 01298 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastState); 01299 s_lastQy = s_lastState; 01300 i_lastState++; 01301 01302 //Ue must be free -> insert transition to error-state 01303 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01304 01305 //insert the corresponding "busy" - transition 01306 //therefor we first need to insert a new state 01307 s_lastState = ToStringInteger(i_lastState+1); 01308 rHioSpec.InsMarkedState(s_lastState); 01309 rHioSpec.SetTransition(s_lastQy, "CBx_busy", s_lastState); 01310 s_lastQupFR = s_lastState; 01311 i_lastState++; 01312 01313 //update the status of the loaded number of pieces 01314 loaded = index; 01315 //update the number of implemented "Take from Right" - cycles 01316 fr++; 01317 } 01318 //Up must be free -> insert transition to error-state; 01319 else 01320 { 01321 rHioSpec.SetTransition(s_lastQup, "CBx_FR", "ErrQy"); 01322 s_lastQupFR = "ErrQy"; 01323 } 01324 01325 // as far as the last QupFL or QupFR did not lead to an error state (i.e. the 01326 // requested number of "Take from..." achieved) insert a new stbyState in order 01327 // to start the new cycle of "Take from..." 01328 if((s_lastQupFL != "ErrQy") ||(s_lastQupFR != "ErrQy")) 01329 { 01330 s_lastState = ToStringInteger(i_lastState+1); 01331 rHioSpec.InsMarkedState(s_lastState); 01332 s_newQy_stby = s_lastState; 01333 i_lastState++; 01334 01335 } 01336 01337 //here is the standby case handeled, if before a "Take from left" - command occured 01338 if(s_lastQupFL != "ErrQy") 01339 { 01340 // insert the stby transition 01341 s_lastState = ToStringInteger(i_lastState+1); 01342 rHioSpec.InsMarkedState(s_lastState); 01343 rHioSpec.SetTransition(s_lastQupFL, "CBx_stby", s_lastState); 01344 s_lastQy = s_lastState; 01345 i_lastState++; 01346 01347 // insert the corresponding environment transition 01348 s_lastState = ToStringInteger(i_lastState+1); 01349 rHioSpec.InsMarkedState(s_lastState); 01350 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01351 s_lastQue = s_lastState; 01352 i_lastState++; 01353 01354 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_stby); 01355 //Ue must be free -> insert transition to error-state 01356 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01357 01358 } 01359 01360 //here is the standby case handeled, if before a "Take from right" - command occured 01361 if(s_lastQupFR != "ErrQy") 01362 { 01363 // insert the stby transition 01364 s_lastState = ToStringInteger(i_lastState+1); 01365 rHioSpec.InsMarkedState(s_lastState); 01366 rHioSpec.SetTransition(s_lastQupFR, "CBx_stby", s_lastState); 01367 s_lastQy = s_lastState; 01368 i_lastState++; 01369 01370 // insert the corresponding environment transition 01371 s_lastState = ToStringInteger(i_lastState+1); 01372 rHioSpec.InsMarkedState(s_lastState); 01373 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01374 s_lastQue = s_lastState; 01375 i_lastState++; 01376 01377 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_stby); 01378 //Ue must be free -> insert transition to error-state 01379 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01380 } 01381 01382 //setup the stanby-loop 01383 if((s_lastQupFL != "ErrQy") ||(s_lastQupFR != "ErrQy")) 01384 { 01385 s_lastState = ToStringInteger(i_lastState+1); 01386 rHioSpec.InsMarkedState(s_lastState); 01387 rHioSpec.SetTransition(s_newQy_stby, "CBx_busy", s_lastState); 01388 s_lastQup = s_lastState; 01389 i_lastState++; 01390 rHioSpec.SetTransition(s_lastState, "CBx_stby", s_newQy_stby); 01391 } 01392 01393 01394 01395 //insert shared 2L-state if the number of "Deliver to Left" transitions is not 01396 //already acheived. By shared we mean the "Deliver to Left" transition 01397 //starting from the stby state, where no communication with the environment occurs 01398 if(tol<mType[3]) 01399 { 01400 s_lastState = ToStringInteger(i_lastState+1); 01401 rHioSpec.InsMarkedState(s_lastState); 01402 s_newQy_2L = s_lastState; 01403 i_lastState++; 01404 } 01405 else tol++; 01406 01407 //insert 'shared' 2R-state if the number of "Deliver to Right" transitions is not 01408 //already acheived; By shared we mean the "Deliver to Right" transition 01409 //starting from the stby state, where no communication with the environment occurs; 01410 if(tor<mType[4]) 01411 { 01412 s_lastState = ToStringInteger(i_lastState+1); 01413 rHioSpec.InsMarkedState(s_lastState); 01414 s_newQy_2R = s_lastState; 01415 i_lastState++; 01416 } 01417 else tor++; 01418 01419 // if at least one piece is available (fl or fr != 0) continue with the 01420 // implementation of the 2L action 01421 if(tol<mType[3] && (fl !=0 ||fr !=0)) 01422 { 01423 // if the last FL led to an Error State, then don't implement 01424 // the "Deliver to..." action (as this would start from an 01425 // Error State - ErrQy) 01426 if(s_lastQupFL != "ErrQy") 01427 { 01428 //insert the corresponding "Deliver to..." - transition 01429 s_lastState = ToStringInteger(i_lastState+1); 01430 rHioSpec.InsMarkedState(s_lastState); 01431 rHioSpec.SetTransition(s_lastQupFL, "CBx_2L", s_lastState); 01432 s_lastQy = s_lastState; 01433 i_lastState++; 01434 01435 //insert the corresponding "request to..." - transition 01436 s_lastState = ToStringInteger(i_lastState+1); 01437 rHioSpec.InsMarkedState(s_lastState); 01438 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01439 s_lastQue = s_lastState; 01440 i_lastState++; 01441 01442 //Enivronment acknowledge 01443 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2L); 01444 //Ue must be free -> insert transition to error-state 01445 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01446 } 01447 01448 // if the last FR led to an Error State, then don't implement 01449 // the "Deliver to..." action (as this would start from an 01450 // Error State - ErrQy) 01451 if(s_lastQupFR != "ErrQy") 01452 { 01453 //insert the corresponding "Deliver to..." - transition 01454 s_lastState = ToStringInteger(i_lastState+1); 01455 rHioSpec.InsMarkedState(s_lastState); 01456 rHioSpec.SetTransition(s_lastQupFR, "CBx_2L", s_lastState); 01457 s_lastQy = s_lastState; 01458 i_lastState++; 01459 01460 //insert the corresponding "request to..." - transition 01461 s_lastState = ToStringInteger(i_lastState+1); 01462 rHioSpec.InsMarkedState(s_lastState); 01463 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01464 s_lastQue = s_lastState; 01465 i_lastState++; 01466 01467 //Enivronment acknowledge 01468 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2L); 01469 //Ue must be free -> insert transition to error-state 01470 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01471 01472 01473 } 01474 // Both deliver actions (2L, 2R) contiue on 01475 // the same path 01476 // Environment receieved the piece 01477 s_lastState = ToStringInteger(i_lastState+1); 01478 rHioSpec.InsMarkedState(s_lastState); 01479 rHioSpec.SetTransition(s_newQy_2L, "CBx_wpar_tl", s_lastState); 01480 s_lastQue = s_lastState; 01481 i_lastState++; 01482 01483 if(loaded ==1) 01484 { 01485 //up to here only one piece loaded -> go back to init state 01486 rHioSpec.SetTransition(s_lastQue, "CBx_pack", "1"); 01487 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01488 } 01489 else 01490 { 01491 //if more then one piece loaded go to the last stby state 01492 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastQy_stby); 01493 //Ue must be free -> insert transition to error-state 01494 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01495 } 01496 01497 //increase number of delivered pieces 01498 tol++; 01499 01500 } 01501 01502 // Uc must be free: if last Qup was an Error state, still insert the "Deliver to..." 01503 // action leading also to an Error state 01504 else 01505 { 01506 if(s_lastQupFL != "ErrQy") 01507 { 01508 rHioSpec.SetTransition(s_lastQupFL, "CBx_2L", "ErrQy"); 01509 } 01510 if(s_lastQupFR != "ErrQy") 01511 { 01512 rHioSpec.SetTransition(s_lastQupFR, "CBx_2L", "ErrQy"); 01513 } 01514 } 01515 01516 // if at least one piece is available (fl or fr != 0) continue with the 01517 // implementation of the 2R action 01518 if(tor<mType[4] && (fl !=0 ||fr !=0)) 01519 { 01520 // if the last FL led to an Error State, then don't implement 01521 // the "Deliver to..." action (as this would start from an 01522 // Error State - ErrQy) 01523 if(s_lastQupFL != "ErrQy") 01524 { 01525 //insert the corresponding "Deliver to..." - transition 01526 s_lastState = ToStringInteger(i_lastState+1); 01527 rHioSpec.InsMarkedState(s_lastState); 01528 rHioSpec.SetTransition(s_lastQupFL, "CBx_2R", s_lastState); 01529 s_lastQy = s_lastState; 01530 i_lastState++; 01531 01532 //insert the corresponding "request to..." - transition 01533 s_lastState = ToStringInteger(i_lastState+1); 01534 rHioSpec.InsMarkedState(s_lastState); 01535 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01536 s_lastQue = s_lastState; 01537 i_lastState++; 01538 01539 //Enivronment acknowledge 01540 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2R); 01541 //Ue must be free -> insert transition to error-state 01542 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01543 01544 } 01545 01546 // if the last FR led to an Error State, then don't implement 01547 // the "Deliver to..." action (as this would start from an 01548 // Error State - ErrQy) 01549 if(s_lastQupFR != "ErrQy") 01550 { 01551 //insert the corresponding "Deliver to..." - transition 01552 s_lastState = ToStringInteger(i_lastState+1); 01553 rHioSpec.InsMarkedState(s_lastState); 01554 rHioSpec.SetTransition(s_lastQupFR, "CBx_2R", s_lastState); 01555 s_lastQy = s_lastState; 01556 i_lastState++; 01557 01558 //insert the corresponding "request to..." - transition 01559 s_lastState = ToStringInteger(i_lastState+1); 01560 rHioSpec.InsMarkedState(s_lastState); 01561 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01562 s_lastQue = s_lastState; 01563 i_lastState++; 01564 01565 //Enivronment acknowledge 01566 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2R); 01567 //Ue must be free -> insert transition to error-state 01568 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01569 01570 } 01571 // Both deliver actions (2L, 2R) contiue on 01572 // the same path 01573 // Environment receieved the piece 01574 s_lastState = ToStringInteger(i_lastState+1); 01575 rHioSpec.InsMarkedState(s_lastState); 01576 rHioSpec.SetTransition(s_newQy_2R, "CBx_wpar_tr", s_lastState); 01577 s_lastQue = s_lastState; 01578 i_lastState++; 01579 01580 if(loaded ==1) 01581 { 01582 //up to here only one piece loaded -> go back to init state 01583 rHioSpec.SetTransition(s_lastQue, "CBx_pack", "1"); 01584 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01585 } 01586 //if more then one piece loaded go to the last stby state 01587 else 01588 { 01589 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastQy_stby); 01590 //Ue must be free -> insert transition to error-state 01591 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01592 } 01593 01594 // increase number of delivered pieces 01595 tor++; 01596 01597 } 01598 // Uc must be free: if last Qup was an Error state, still insert the "Deliver to..." 01599 // action leading also to an Error state 01600 else 01601 { 01602 01603 if(s_lastQupFL != "ErrQy") 01604 { 01605 rHioSpec.SetTransition(s_lastQupFL, "CBx_2R", "ErrQy"); 01606 } 01607 if(s_lastQupFR != "ErrQy") 01608 { 01609 rHioSpec.SetTransition(s_lastQupFR, "CBx_2R", "ErrQy"); 01610 } 01611 } 01612 01613 //insert the next FL action after an FL or FR action already occured; 01614 if(fl<mType[1]) 01615 { 01616 s_lastState = ToStringInteger(i_lastState+1); 01617 rHioSpec.InsMarkedState(s_lastState); 01618 s_newQy_FL = s_lastState; 01619 i_lastState++; 01620 } 01621 01622 //insert the next FL action after an FL or FR action already occured; 01623 if(fr<mType[2]) 01624 { 01625 s_lastState = ToStringInteger(i_lastState+1); 01626 rHioSpec.InsMarkedState(s_lastState); 01627 s_newQy_FR = s_lastState; 01628 i_lastState++; 01629 } 01630 01631 // if last action was a FL, implement the corresponding environment events (wpar_fl) 01632 // before continue with the next take from action 01633 if((s_lastQupFL != "ErrQy") && fl <mType[1]) 01634 01635 { 01636 //insert the "Take from..." transition 01637 s_lastState = ToStringInteger(i_lastState+1); 01638 rHioSpec.InsMarkedState(s_lastState); 01639 rHioSpec.SetTransition(s_lastQupFL, "CBx_FL", s_lastState); 01640 s_lastQy = s_lastState; 01641 i_lastState++; 01642 01643 //insert the environment transition 01644 s_lastState = ToStringInteger(i_lastState+1); 01645 rHioSpec.InsMarkedState(s_lastState); 01646 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01647 s_lastQue = s_lastState; 01648 i_lastState++; 01649 01650 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FL); 01651 //Ue must be free -> insert transition to error-state 01652 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01653 01654 } 01655 //Up must be free -> insert transition to error-state; 01656 else 01657 if(fl<mType[1]) 01658 { 01659 rHioSpec.SetTransition(s_lastQupFL, "CBx_FL", "ErrQy"); 01660 } 01661 // if last action was a FL, implement the corresponding environment events (wpar_fl) 01662 // before continue with the next take from action 01663 if((s_lastQupFL != "ErrQy") && fr <mType[2]) 01664 01665 { 01666 //insert the "Take from..." transition 01667 s_lastState = ToStringInteger(i_lastState+1); 01668 rHioSpec.InsMarkedState(s_lastState); 01669 rHioSpec.SetTransition(s_lastQupFL, "CBx_FR", s_lastState); 01670 s_lastQy = s_lastState; 01671 i_lastState++; 01672 01673 //insert the environment transition 01674 s_lastState = ToStringInteger(i_lastState+1); 01675 rHioSpec.InsMarkedState(s_lastState); 01676 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01677 s_lastQue = s_lastState; 01678 i_lastState++; 01679 01680 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FR); 01681 //Ue must be free -> insert transition to error-state 01682 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01683 01684 } 01685 //Up must be free -> insert transition to error-state; 01686 else 01687 if(fl<mType[1]) 01688 { 01689 rHioSpec.SetTransition(s_lastQupFL, "CBx_FR", "ErrQy"); 01690 } 01691 01692 01693 // if last action was a FR, implement the corresponding environment events (wpar_fl) 01694 // before continue with the next take from action 01695 if((s_lastQupFR != "ErrQy") && fl <mType[1]) 01696 01697 { 01698 //insert the "Take from..." transition 01699 s_lastState = ToStringInteger(i_lastState+1); 01700 rHioSpec.InsMarkedState(s_lastState); 01701 rHioSpec.SetTransition(s_lastQupFR, "CBx_FL", s_lastState); 01702 s_lastQy = s_lastState; 01703 i_lastState++; 01704 01705 //insert the environment transition 01706 s_lastState = ToStringInteger(i_lastState+1); 01707 rHioSpec.InsMarkedState(s_lastState); 01708 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01709 s_lastQue = s_lastState; 01710 i_lastState++; 01711 01712 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FL); 01713 //Ue must be free -> insert transition to error-state 01714 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01715 01716 } 01717 //Up must be free -> insert transition to error-state; 01718 else 01719 if (fr<mType[2]) 01720 { 01721 rHioSpec.SetTransition(s_lastQupFR, "CBx_FL", "ErrQy"); 01722 } 01723 01724 // if last action was a FR, implement the corresponding environment events (wpar_fl) 01725 // before continue with the next take from action 01726 if((s_lastQupFR != "ErrQy") && fr <mType[2]) 01727 01728 { 01729 //insert the "Take from..." transition 01730 s_lastState = ToStringInteger(i_lastState+1); 01731 rHioSpec.InsMarkedState(s_lastState); 01732 rHioSpec.SetTransition(s_lastQupFR, "CBx_FR", s_lastState); 01733 s_lastQy = s_lastState; 01734 i_lastState++; 01735 01736 //insert the environment transition 01737 s_lastState = ToStringInteger(i_lastState+1); 01738 rHioSpec.InsMarkedState(s_lastState); 01739 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01740 s_lastQue = s_lastState; 01741 i_lastState++; 01742 01743 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FR); 01744 //Ue must be free -> insert transition to error-state 01745 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01746 } 01747 //Up must be free -> insert transition to error-state; 01748 else 01749 if (fr<mType[2]) 01750 { 01751 rHioSpec.SetTransition(s_lastQupFR, "CBx_FR", "ErrQy"); 01752 } 01753 01754 01755 01756 // insert the remaining "Deliver to..." transition; 01757 if(tol <= mType[3]) 01758 rHioSpec.SetTransition(s_lastQup, "CBx_2L", s_newQy_2L); 01759 else 01760 // Up must be free -> insert transition to error-state; 01761 rHioSpec.SetTransition(s_lastQup, "CBx_2L", "ErrQy"); 01762 01763 // insert the remaining "Deliver to..." transition; 01764 if(tor <= mType[4]) 01765 rHioSpec.SetTransition(s_lastQup, "CBx_2R", s_newQy_2R); 01766 else 01767 // Up must be free -> insert transition to error-state; 01768 rHioSpec.SetTransition(s_lastQup, "CBx_2R", "ErrQy"); 01769 01770 // finaly, if the numer of maximal capacity is achieved, insert remaining transition 01771 // in order to ensure the I/O plant format of the specification; 01772 if(index == mType[0]) 01773 { 01774 if(s_lastQup != "ErrQy") 01775 { 01776 rHioSpec.SetTransition(s_lastQup, "CBx_FR", "ErrQy"); 01777 rHioSpec.SetTransition(s_lastQup, "CBx_FL", "ErrQy"); 01778 } 01779 01780 if(s_lastQupFL != "ErrQy") 01781 { 01782 rHioSpec.SetTransition(s_lastQupFL, "CBx_FL", "ErrQy"); 01783 rHioSpec.SetTransition(s_lastQupFL, "CBx_FR", "ErrQy"); 01784 } 01785 01786 if(s_lastQupFR != "ErrQy") 01787 { 01788 rHioSpec.SetTransition(s_lastQupFR, "CBx_FR", "ErrQy"); 01789 rHioSpec.SetTransition(s_lastQupFR, "CBx_FL", "ErrQy"); 01790 } 01791 01792 rHioSpec.SWrite(); 01793 01794 // for the creaded specification create now also the constraints which describe 01795 // the condition of completeness and Yp-liveness 01796 CreateConstraint(mType, constrP, constrE); 01797 01798 }// end if 01799 01800 }// end for-loop: see comment at begin of the (main)loop -> 01801 // "index" - stores the information about the capacity, i.e. how many 01802 // times we need to add the "Take from..." "Deliver from" cycle 01803 01804 }// end createSpec() 01805 01806 01807 // This function creates constraints which describe the condition of completeness 01808 // and Yp-liveness of a Specification. The implementation follows the same algorithm 01809 // as the CreateSpec() function, and has the same limitation: it is only for use 01810 // with a specific model 01811 void CreateConstraint(int mType[5], Generator& constrP, Generator& constrE) 01812 { 01813 01814 int i_lastState, fl, fr, tol, tor; 01815 i_lastState = fl = fr = tol = tor = 0; 01816 01817 std::string s_lastState, s_lastQup, s_lastQy, s_newQy, s_return; 01818 s_lastState = s_lastQup = s_lastQy = s_newQy = s_return = ""; 01819 01820 // the environment constraint constrE: this is an automata with one state, 01821 // one event and no transitions 01822 constrE.InsEvent("CBx_nack"); 01823 constrE.InsInitState("1"); 01824 constrE.SetMarkedState("1"); 01825 01826 // the operator constraint constrP 01827 constrP.InsEvent("CBx_free"); 01828 constrP.InsEvent("CBx_busy"); 01829 constrP.InsEvent("CBx_stby"); 01830 constrP.InsEvent("CBx_FL"); 01831 constrP.InsEvent("CBx_FR"); 01832 constrP.InsEvent("CBx_2L"); 01833 constrP.InsEvent("CBx_2R"); 01834 01835 // insert the states and transitions that are independent of the type of the 01836 // constraint 01837 constrP.InsInitState("1"); 01838 constrP.SetMarkedState("1"); 01839 s_return = "1"; 01840 s_lastQy = "1"; 01841 constrP.InsMarkedState("2"); 01842 constrP.SetTransition("1", "CBx_free", "2"); 01843 constrP.SetTransition("1", "CBx_busy", "2"); 01844 i_lastState = 2; 01845 s_lastQup = "2"; 01846 01847 // start the main loop 01848 for (int i=0; i<mType[0]; i++) 01849 { 01850 01851 //insert shared state Qy 01852 if(fl<mType[1] || fr<mType[2]) 01853 { 01854 s_lastState = ToStringInteger(i_lastState+1); 01855 constrP.InsMarkedState(s_lastState); 01856 s_newQy = s_lastState; 01857 constrP.SetTransition(s_lastQup, "CBx_stby", s_lastQy); 01858 i_lastState++; 01859 01860 } 01861 // insert "Take from left" transition if number of needed transitions not 01862 // already achieved 01863 if(fl<mType[1]) 01864 { 01865 constrP.SetTransition(s_lastQup, "CBx_FL", s_newQy); 01866 fl++; 01867 } 01868 01869 // insert "Take from right" transition if number of needed transitions not 01870 // already achieved 01871 if(fr<mType[2]) 01872 { 01873 constrP.SetTransition(s_lastQup, "CBx_FR", s_newQy); 01874 fr++; 01875 } 01876 // i>0 only after we implemented at least one "Take from..." action; if i==0 01877 // "Deliver to..." action will be not implemented, as a deliver action is not 01878 // possible yet 01879 if(i>0) 01880 { 01881 //insert 2L-Trans 01882 if(tol<mType[3]) 01883 { 01884 // insert corresponding "Deliver to..." transition 01885 // and increase the number of implemented "Deliver 01886 // to..." transitions 01887 constrP.SetTransition(s_lastQup, "CBx_2L", s_return); 01888 tol++; 01889 } 01890 01891 //insert 2R-Trans 01892 if(tor<mType[4]) 01893 { 01894 // insert corresponding "Deliver to..." transition 01895 // and increase the number of implemented "Deliver 01896 // to..." transitions 01897 constrP.SetTransition(s_lastQup, "CBx_2R", s_return); 01898 tor++; 01899 } 01900 01901 // store the last state 01902 s_return = s_lastQy; 01903 } 01904 01905 // implement stby loop 01906 s_lastState = ToStringInteger(i_lastState+1); 01907 constrP.InsMarkedState(s_lastState); 01908 constrP.SetTransition(s_newQy, "CBx_free", s_lastState); 01909 constrP.SetTransition(s_newQy, "CBx_busy", s_lastState); 01910 constrP.SetTransition(s_lastState, "CBx_stby", s_newQy); 01911 s_lastQup = s_lastState; 01912 i_lastState++; 01913 01914 // as i starts at 0, check if the limit is achieved and implemet the remaining 01915 // "Deliver to..." transitions 01916 if(i+1 == mType[0]) 01917 { 01918 if(tol<mType[3]) 01919 { 01920 constrP.SetTransition(s_lastQup, "CBx_2L", s_return); 01921 tol++; 01922 } 01923 01924 if(tor<mType[4]) 01925 { 01926 constrP.SetTransition(s_lastQup, "CBx_2R", s_return); 01927 tor++; 01928 } 01929 } 01930 // store the last state 01931 s_lastQy = s_newQy; 01932 01933 }//end for-loop - see comment at begin of the loop -> 01934 // "index" - stores the information about the capacity, i.e. how many 01935 // times we need to add the "Take from..." "Deliver from" cycle 01936 01937 01938 }// End create Constraint 01939 01940 } // end namespace faudes*******end namespace faudes********end namespace faudes 01941 01942 /********************************END*******************************************/ libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |