libFAUDES
Sections
Index
|
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 // find out how many pieces to take from left (mType[1]) and how many from right 01172 // (mType[1]). For the higher value start adding the corresponding states and transitions 01173 // as implemented in the template 01174 int forloop; 01175 if(mType[1] >= mType[2]) 01176 { 01177 forloop = mType[1]; 01178 } 01179 forloop = mType[2]; 01180 01181 //2. so called "Qy_stby" - states are of states were we decied if an other 01182 // "Take from..." or "Deliver to..." - cycle must be added to the specification. 01183 // This are also states where the specification branch out, so it is important 01184 // to keep this state in order to implement all transitions starting here. 01185 01186 // "index" - stores the information about the capacity, i.e. how many times we 01187 // need to add the "Take from..." "Deliver from" cycle 01188 for(int i=0; i<mType[0]; i++) 01189 { 01190 s_lastQy_stby = s_newQy_stby; 01191 index++; 01192 01193 //if no piece loaded yet, deliver actions would lead to an Error state 01194 if(loaded == 0) 01195 { 01196 rHioSpec.SetTransition(s_lastQup, "CBx_2L", "ErrQy"); 01197 s_lastQup2L = "ErrQy"; 01198 rHioSpec.SetTransition(s_lastQup, "CBx_2R", "ErrQy"); 01199 s_lastQup2R = "ErrQy"; 01200 } 01201 01202 // the value of "fl" holds how many "Take from left"-cycles we already implemented 01203 // in the specification. If the fl < requested "Take from left"- operations, 01204 // implement an other one. 01205 if(fl<mType[1]) 01206 { 01207 // if index = 1 then we are in the first implementation cycle 01208 // so need to insert a new state. (in the next cycles, this 01209 // state will have be already inserted -> see "else" statement) 01210 if(!(index > 1)) 01211 { 01212 s_lastState = ToStringInteger(i_lastState+1); 01213 rHioSpec.InsMarkedState(s_lastState); 01214 } 01215 else 01216 { 01217 // hold that the last inserted state is "Qy"-state that 01218 // we arrive through a "Take from" - transition 01219 s_lastState = s_newQy_FL; 01220 } 01221 01222 //insert the corresponding "Take from" - transition 01223 rHioSpec.SetTransition(s_lastQup, "CBx_FL", s_lastState); 01224 s_lastQy = s_lastState; 01225 i_lastState++; 01226 01227 //insert the corresponding "request from" - transition; 01228 //therefor we first need to insert a new state 01229 s_lastState = ToStringInteger(i_lastState+1); 01230 rHioSpec.InsMarkedState(s_lastState); 01231 rHioSpec.SetTransition(s_lastQy, "CBx_req_fl", s_lastState); 01232 s_lastQue = s_lastState; 01233 i_lastState++; 01234 01235 //insert the corresponding "acknowledge" - transition 01236 //therefor we first need to insert a new state 01237 s_lastState = ToStringInteger(i_lastState+1); 01238 rHioSpec.InsMarkedState(s_lastState); 01239 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastState); 01240 s_lastQy = s_lastState; 01241 i_lastState++; 01242 01243 //Ue must be free -> insert transition to error-state 01244 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01245 01246 //insert the corresponding "busy" - transition 01247 //therefor we first need to insert a new state 01248 s_lastState = ToStringInteger(i_lastState+1); 01249 rHioSpec.InsMarkedState(s_lastState); 01250 rHioSpec.SetTransition(s_lastQy, "CBx_busy", s_lastState); 01251 s_lastQupFL = s_lastState; 01252 i_lastState++; 01253 01254 //update the status of the loaded number of pieces 01255 loaded = index; 01256 //update the number of implemented "Take from Left" - cycles 01257 fl++; 01258 01259 } 01260 //Up must be free -> insert transition to error-state; 01261 else 01262 { 01263 rHioSpec.SetTransition(s_lastQup, "CBx_FL", "ErrQy"); 01264 s_lastQupFL = "ErrQy"; 01265 } 01266 01267 01268 //as "Take from left" or "Take from right" are simetrical, the implementation 01269 //is also the same as above 01270 // the value of "fr" holds how many "Take from right"-cycles we already implemented 01271 // in the specification. If the fr < requested "Take from right"- operations, 01272 // implement an other one. 01273 if(fr<mType[2]) 01274 { 01275 // if index = 1 then we are in the first implementation cycle 01276 // so need to insert a new state. (in the next cycles, this 01277 // state will have be already inserted -> see "else" statement) 01278 if(!(index > 1)) 01279 { 01280 s_lastState = ToStringInteger(i_lastState+1); 01281 rHioSpec.InsMarkedState(s_lastState); 01282 } 01283 else 01284 { 01285 // hold that the last inserted state is "Qy"-state that 01286 // we arrive through a "Take from" - transition 01287 s_lastState = s_newQy_FR; 01288 } 01289 01290 //insert the corresponding "Take from" - transition 01291 rHioSpec.SetTransition(s_lastQup, "CBx_FR", s_lastState); 01292 s_lastQy = s_lastState; 01293 i_lastState++; 01294 01295 //insert the corresponding "request from" - transition; 01296 //therefor we first need to insert a new state 01297 s_lastState = ToStringInteger(i_lastState+1); 01298 rHioSpec.InsMarkedState(s_lastState); 01299 rHioSpec.SetTransition(s_lastQy, "CBx_req_fr", s_lastState); 01300 s_lastQue = s_lastState; 01301 i_lastState++; 01302 01303 //insert the corresponding "acknowledge" - transition 01304 //therefor we first need to insert a new state 01305 s_lastState = ToStringInteger(i_lastState+1); 01306 rHioSpec.InsMarkedState(s_lastState); 01307 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastState); 01308 s_lastQy = s_lastState; 01309 i_lastState++; 01310 01311 //Ue must be free -> insert transition to error-state 01312 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01313 01314 //insert the corresponding "busy" - transition 01315 //therefor we first need to insert a new state 01316 s_lastState = ToStringInteger(i_lastState+1); 01317 rHioSpec.InsMarkedState(s_lastState); 01318 rHioSpec.SetTransition(s_lastQy, "CBx_busy", s_lastState); 01319 s_lastQupFR = s_lastState; 01320 i_lastState++; 01321 01322 //update the status of the loaded number of pieces 01323 loaded = index; 01324 //update the number of implemented "Take from Right" - cycles 01325 fr++; 01326 } 01327 //Up must be free -> insert transition to error-state; 01328 else 01329 { 01330 rHioSpec.SetTransition(s_lastQup, "CBx_FR", "ErrQy"); 01331 s_lastQupFR = "ErrQy"; 01332 } 01333 01334 // as far as the last QupFL or QupFR did not lead to an error state (i.e. the 01335 // requested number of "Take from..." achieved) insert a new stbyState in order 01336 // to start the new cycle of "Take from..." 01337 if((s_lastQupFL != "ErrQy") ||(s_lastQupFR != "ErrQy")) 01338 { 01339 s_lastState = ToStringInteger(i_lastState+1); 01340 rHioSpec.InsMarkedState(s_lastState); 01341 s_newQy_stby = s_lastState; 01342 i_lastState++; 01343 01344 } 01345 01346 //here is the standby case handeled, if before a "Take from left" - command occured 01347 if(s_lastQupFL != "ErrQy") 01348 { 01349 // insert the stby transition 01350 s_lastState = ToStringInteger(i_lastState+1); 01351 rHioSpec.InsMarkedState(s_lastState); 01352 rHioSpec.SetTransition(s_lastQupFL, "CBx_stby", s_lastState); 01353 s_lastQy = s_lastState; 01354 i_lastState++; 01355 01356 // insert the corresponding environment transition 01357 s_lastState = ToStringInteger(i_lastState+1); 01358 rHioSpec.InsMarkedState(s_lastState); 01359 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01360 s_lastQue = s_lastState; 01361 i_lastState++; 01362 01363 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_stby); 01364 //Ue must be free -> insert transition to error-state 01365 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01366 01367 } 01368 01369 //here is the standby case handeled, if before a "Take from right" - command occured 01370 if(s_lastQupFR != "ErrQy") 01371 { 01372 // insert the stby transition 01373 s_lastState = ToStringInteger(i_lastState+1); 01374 rHioSpec.InsMarkedState(s_lastState); 01375 rHioSpec.SetTransition(s_lastQupFR, "CBx_stby", s_lastState); 01376 s_lastQy = s_lastState; 01377 i_lastState++; 01378 01379 // insert the corresponding environment transition 01380 s_lastState = ToStringInteger(i_lastState+1); 01381 rHioSpec.InsMarkedState(s_lastState); 01382 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01383 s_lastQue = s_lastState; 01384 i_lastState++; 01385 01386 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_stby); 01387 //Ue must be free -> insert transition to error-state 01388 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01389 } 01390 01391 //setup the stanby-loop 01392 if((s_lastQupFL != "ErrQy") ||(s_lastQupFR != "ErrQy")) 01393 { 01394 s_lastState = ToStringInteger(i_lastState+1); 01395 rHioSpec.InsMarkedState(s_lastState); 01396 rHioSpec.SetTransition(s_newQy_stby, "CBx_busy", s_lastState); 01397 s_lastQup = s_lastState; 01398 i_lastState++; 01399 rHioSpec.SetTransition(s_lastState, "CBx_stby", s_newQy_stby); 01400 } 01401 01402 01403 01404 //insert shared 2L-state if the number of "Deliver to Left" transitions is not 01405 //already acheived. By shared we mean the "Deliver to Left" transition 01406 //starting from the stby state, where no communication with the environment occurs 01407 if(tol<mType[3]) 01408 { 01409 s_lastState = ToStringInteger(i_lastState+1); 01410 rHioSpec.InsMarkedState(s_lastState); 01411 s_newQy_2L = s_lastState; 01412 i_lastState++; 01413 } 01414 else tol++; 01415 01416 //insert 'shared' 2R-state if the number of "Deliver to Right" transitions is not 01417 //already acheived; By shared we mean the "Deliver to Right" transition 01418 //starting from the stby state, where no communication with the environment occurs; 01419 if(tor<mType[4]) 01420 { 01421 s_lastState = ToStringInteger(i_lastState+1); 01422 rHioSpec.InsMarkedState(s_lastState); 01423 s_newQy_2R = s_lastState; 01424 i_lastState++; 01425 } 01426 else tor++; 01427 01428 // if at least one piece is available (fl or fr != 0) continue with the 01429 // implementation of the 2L action 01430 if(tol<mType[3] && (fl !=0 ||fr !=0)) 01431 { 01432 // if the last FL led to an Error State, then don't implement 01433 // the "Deliver to..." action (as this would start from an 01434 // Error State - ErrQy) 01435 if(s_lastQupFL != "ErrQy") 01436 { 01437 //insert the corresponding "Deliver to..." - transition 01438 s_lastState = ToStringInteger(i_lastState+1); 01439 rHioSpec.InsMarkedState(s_lastState); 01440 rHioSpec.SetTransition(s_lastQupFL, "CBx_2L", s_lastState); 01441 s_lastQy = s_lastState; 01442 i_lastState++; 01443 01444 //insert the corresponding "request to..." - transition 01445 s_lastState = ToStringInteger(i_lastState+1); 01446 rHioSpec.InsMarkedState(s_lastState); 01447 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01448 s_lastQue = s_lastState; 01449 i_lastState++; 01450 01451 //Enivronment acknowledge 01452 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2L); 01453 //Ue must be free -> insert transition to error-state 01454 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01455 } 01456 01457 // if the last FR led to an Error State, then don't implement 01458 // the "Deliver to..." action (as this would start from an 01459 // Error State - ErrQy) 01460 if(s_lastQupFR != "ErrQy") 01461 { 01462 //insert the corresponding "Deliver to..." - transition 01463 s_lastState = ToStringInteger(i_lastState+1); 01464 rHioSpec.InsMarkedState(s_lastState); 01465 rHioSpec.SetTransition(s_lastQupFR, "CBx_2L", s_lastState); 01466 s_lastQy = s_lastState; 01467 i_lastState++; 01468 01469 //insert the corresponding "request to..." - transition 01470 s_lastState = ToStringInteger(i_lastState+1); 01471 rHioSpec.InsMarkedState(s_lastState); 01472 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01473 s_lastQue = s_lastState; 01474 i_lastState++; 01475 01476 //Enivronment acknowledge 01477 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2L); 01478 //Ue must be free -> insert transition to error-state 01479 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01480 01481 01482 } 01483 // Both deliver actions (2L, 2R) contiue on 01484 // the same path 01485 // Environment receieved the piece 01486 s_lastState = ToStringInteger(i_lastState+1); 01487 rHioSpec.InsMarkedState(s_lastState); 01488 rHioSpec.SetTransition(s_newQy_2L, "CBx_wpar_tl", s_lastState); 01489 s_lastQue = s_lastState; 01490 i_lastState++; 01491 01492 if(loaded ==1) 01493 { 01494 //up to here only one piece loaded -> go back to init state 01495 rHioSpec.SetTransition(s_lastQue, "CBx_pack", "1"); 01496 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01497 } 01498 else 01499 { 01500 //if more then one piece loaded go to the last stby state 01501 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastQy_stby); 01502 //Ue must be free -> insert transition to error-state 01503 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01504 } 01505 01506 //increase number of delivered pieces 01507 tol++; 01508 01509 } 01510 01511 // Uc must be free: if last Qup was an Error state, still insert the "Deliver to..." 01512 // action leading also to an Error state 01513 else 01514 { 01515 if(s_lastQupFL != "ErrQy") 01516 { 01517 rHioSpec.SetTransition(s_lastQupFL, "CBx_2L", "ErrQy"); 01518 } 01519 if(s_lastQupFR != "ErrQy") 01520 { 01521 rHioSpec.SetTransition(s_lastQupFR, "CBx_2L", "ErrQy"); 01522 } 01523 } 01524 01525 // if at least one piece is available (fl or fr != 0) continue with the 01526 // implementation of the 2R action 01527 if(tor<mType[4] && (fl !=0 ||fr !=0)) 01528 { 01529 // if the last FL led to an Error State, then don't implement 01530 // the "Deliver to..." action (as this would start from an 01531 // Error State - ErrQy) 01532 if(s_lastQupFL != "ErrQy") 01533 { 01534 //insert the corresponding "Deliver to..." - transition 01535 s_lastState = ToStringInteger(i_lastState+1); 01536 rHioSpec.InsMarkedState(s_lastState); 01537 rHioSpec.SetTransition(s_lastQupFL, "CBx_2R", s_lastState); 01538 s_lastQy = s_lastState; 01539 i_lastState++; 01540 01541 //insert the corresponding "request to..." - transition 01542 s_lastState = ToStringInteger(i_lastState+1); 01543 rHioSpec.InsMarkedState(s_lastState); 01544 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01545 s_lastQue = s_lastState; 01546 i_lastState++; 01547 01548 //Enivronment acknowledge 01549 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2R); 01550 //Ue must be free -> insert transition to error-state 01551 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01552 01553 } 01554 01555 // if the last FR led to an Error State, then don't implement 01556 // the "Deliver to..." action (as this would start from an 01557 // Error State - ErrQy) 01558 if(s_lastQupFR != "ErrQy") 01559 { 01560 //insert the corresponding "Deliver to..." - transition 01561 s_lastState = ToStringInteger(i_lastState+1); 01562 rHioSpec.InsMarkedState(s_lastState); 01563 rHioSpec.SetTransition(s_lastQupFR, "CBx_2R", s_lastState); 01564 s_lastQy = s_lastState; 01565 i_lastState++; 01566 01567 //insert the corresponding "request to..." - transition 01568 s_lastState = ToStringInteger(i_lastState+1); 01569 rHioSpec.InsMarkedState(s_lastState); 01570 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01571 s_lastQue = s_lastState; 01572 i_lastState++; 01573 01574 //Enivronment acknowledge 01575 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_2R); 01576 //Ue must be free -> insert transition to error-state 01577 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01578 01579 } 01580 // Both deliver actions (2L, 2R) contiue on 01581 // the same path 01582 // Environment receieved the piece 01583 s_lastState = ToStringInteger(i_lastState+1); 01584 rHioSpec.InsMarkedState(s_lastState); 01585 rHioSpec.SetTransition(s_newQy_2R, "CBx_wpar_tr", s_lastState); 01586 s_lastQue = s_lastState; 01587 i_lastState++; 01588 01589 if(loaded ==1) 01590 { 01591 //up to here only one piece loaded -> go back to init state 01592 rHioSpec.SetTransition(s_lastQue, "CBx_pack", "1"); 01593 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01594 } 01595 //if more then one piece loaded go to the last stby state 01596 else 01597 { 01598 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_lastQy_stby); 01599 //Ue must be free -> insert transition to error-state 01600 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01601 } 01602 01603 // increase number of delivered pieces 01604 tor++; 01605 01606 } 01607 // Uc must be free: if last Qup was an Error state, still insert the "Deliver to..." 01608 // action leading also to an Error state 01609 else 01610 { 01611 01612 if(s_lastQupFL != "ErrQy") 01613 { 01614 rHioSpec.SetTransition(s_lastQupFL, "CBx_2R", "ErrQy"); 01615 } 01616 if(s_lastQupFR != "ErrQy") 01617 { 01618 rHioSpec.SetTransition(s_lastQupFR, "CBx_2R", "ErrQy"); 01619 } 01620 } 01621 01622 //insert the next FL action after an FL or FR action already occured; 01623 if(fl<mType[1]) 01624 { 01625 s_lastState = ToStringInteger(i_lastState+1); 01626 rHioSpec.InsMarkedState(s_lastState); 01627 s_newQy_FL = s_lastState; 01628 i_lastState++; 01629 } 01630 01631 //insert the next FL action after an FL or FR action already occured; 01632 if(fr<mType[2]) 01633 { 01634 s_lastState = ToStringInteger(i_lastState+1); 01635 rHioSpec.InsMarkedState(s_lastState); 01636 s_newQy_FR = s_lastState; 01637 i_lastState++; 01638 } 01639 01640 // if last action was a FL, implement the corresponding environment events (wpar_fl) 01641 // before continue with the next take from action 01642 if((s_lastQupFL != "ErrQy") && fl <mType[1]) 01643 01644 { 01645 //insert the "Take from..." transition 01646 s_lastState = ToStringInteger(i_lastState+1); 01647 rHioSpec.InsMarkedState(s_lastState); 01648 rHioSpec.SetTransition(s_lastQupFL, "CBx_FL", s_lastState); 01649 s_lastQy = s_lastState; 01650 i_lastState++; 01651 01652 //insert the environment transition 01653 s_lastState = ToStringInteger(i_lastState+1); 01654 rHioSpec.InsMarkedState(s_lastState); 01655 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01656 s_lastQue = s_lastState; 01657 i_lastState++; 01658 01659 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FL); 01660 //Ue must be free -> insert transition to error-state 01661 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01662 01663 } 01664 //Up must be free -> insert transition to error-state; 01665 else 01666 if(fl<mType[1]) 01667 { 01668 rHioSpec.SetTransition(s_lastQupFL, "CBx_FL", "ErrQy"); 01669 } 01670 // if last action was a FL, implement the corresponding environment events (wpar_fl) 01671 // before continue with the next take from action 01672 if((s_lastQupFL != "ErrQy") && fr <mType[2]) 01673 01674 { 01675 //insert the "Take from..." transition 01676 s_lastState = ToStringInteger(i_lastState+1); 01677 rHioSpec.InsMarkedState(s_lastState); 01678 rHioSpec.SetTransition(s_lastQupFL, "CBx_FR", s_lastState); 01679 s_lastQy = s_lastState; 01680 i_lastState++; 01681 01682 //insert the environment transition 01683 s_lastState = ToStringInteger(i_lastState+1); 01684 rHioSpec.InsMarkedState(s_lastState); 01685 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fl", s_lastState); 01686 s_lastQue = s_lastState; 01687 i_lastState++; 01688 01689 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FR); 01690 //Ue must be free -> insert transition to error-state 01691 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01692 01693 } 01694 //Up must be free -> insert transition to error-state; 01695 else 01696 if(fl<mType[1]) 01697 { 01698 rHioSpec.SetTransition(s_lastQupFL, "CBx_FR", "ErrQy"); 01699 } 01700 01701 01702 // if last action was a FR, implement the corresponding environment events (wpar_fl) 01703 // before continue with the next take from action 01704 if((s_lastQupFR != "ErrQy") && fl <mType[1]) 01705 01706 { 01707 //insert the "Take from..." transition 01708 s_lastState = ToStringInteger(i_lastState+1); 01709 rHioSpec.InsMarkedState(s_lastState); 01710 rHioSpec.SetTransition(s_lastQupFR, "CBx_FL", s_lastState); 01711 s_lastQy = s_lastState; 01712 i_lastState++; 01713 01714 //insert the environment transition 01715 s_lastState = ToStringInteger(i_lastState+1); 01716 rHioSpec.InsMarkedState(s_lastState); 01717 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01718 s_lastQue = s_lastState; 01719 i_lastState++; 01720 01721 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FL); 01722 //Ue must be free -> insert transition to error-state 01723 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01724 01725 } 01726 //Up must be free -> insert transition to error-state; 01727 else 01728 if (fr<mType[2]) 01729 { 01730 rHioSpec.SetTransition(s_lastQupFR, "CBx_FL", "ErrQy"); 01731 } 01732 01733 // if last action was a FR, implement the corresponding environment events (wpar_fl) 01734 // before continue with the next take from action 01735 if((s_lastQupFR != "ErrQy") && fr <mType[2]) 01736 01737 { 01738 //insert the "Take from..." transition 01739 s_lastState = ToStringInteger(i_lastState+1); 01740 rHioSpec.InsMarkedState(s_lastState); 01741 rHioSpec.SetTransition(s_lastQupFR, "CBx_FR", s_lastState); 01742 s_lastQy = s_lastState; 01743 i_lastState++; 01744 01745 //insert the environment transition 01746 s_lastState = ToStringInteger(i_lastState+1); 01747 rHioSpec.InsMarkedState(s_lastState); 01748 rHioSpec.SetTransition(s_lastQy, "CBx_wpar_fr", s_lastState); 01749 s_lastQue = s_lastState; 01750 i_lastState++; 01751 01752 rHioSpec.SetTransition(s_lastQue, "CBx_pack", s_newQy_FR); 01753 //Ue must be free -> insert transition to error-state 01754 rHioSpec.SetTransition(s_lastQue, "CBx_nack", "ErrQy"); 01755 } 01756 //Up must be free -> insert transition to error-state; 01757 else 01758 if (fr<mType[2]) 01759 { 01760 rHioSpec.SetTransition(s_lastQupFR, "CBx_FR", "ErrQy"); 01761 } 01762 01763 01764 01765 // insert the remaining "Deliver to..." transition; 01766 if(tol <= mType[3]) 01767 rHioSpec.SetTransition(s_lastQup, "CBx_2L", s_newQy_2L); 01768 else 01769 // Up must be free -> insert transition to error-state; 01770 rHioSpec.SetTransition(s_lastQup, "CBx_2L", "ErrQy"); 01771 01772 // insert the remaining "Deliver to..." transition; 01773 if(tor <= mType[4]) 01774 rHioSpec.SetTransition(s_lastQup, "CBx_2R", s_newQy_2R); 01775 else 01776 // Up must be free -> insert transition to error-state; 01777 rHioSpec.SetTransition(s_lastQup, "CBx_2R", "ErrQy"); 01778 01779 // finaly, if the numer of maximal capacity is achieved, insert remaining transition 01780 // in order to ensure the I/O plant format of the specification; 01781 if(index == mType[0]) 01782 { 01783 if(s_lastQup != "ErrQy") 01784 { 01785 rHioSpec.SetTransition(s_lastQup, "CBx_FR", "ErrQy"); 01786 rHioSpec.SetTransition(s_lastQup, "CBx_FL", "ErrQy"); 01787 } 01788 01789 if(s_lastQupFL != "ErrQy") 01790 { 01791 rHioSpec.SetTransition(s_lastQupFL, "CBx_FL", "ErrQy"); 01792 rHioSpec.SetTransition(s_lastQupFL, "CBx_FR", "ErrQy"); 01793 } 01794 01795 if(s_lastQupFR != "ErrQy") 01796 { 01797 rHioSpec.SetTransition(s_lastQupFR, "CBx_FR", "ErrQy"); 01798 rHioSpec.SetTransition(s_lastQupFR, "CBx_FL", "ErrQy"); 01799 } 01800 01801 rHioSpec.SWrite(); 01802 01803 // for the creaded specification create now also the constraints which describe 01804 // the condition of completeness and Yp-liveness 01805 CreateConstraint(mType, constrP, constrE); 01806 01807 }// end if 01808 01809 }// end for-loop: see comment at begin of the (main)loop -> 01810 // "index" - stores the information about the capacity, i.e. how many 01811 // times we need to add the "Take from..." "Deliver from" cycle 01812 01813 }// end createSpec() 01814 01815 01816 // This function creates constraints which describe the condition of completeness 01817 // and Yp-liveness of a Specification. The implementation follows the same algorithm 01818 // as the CreateSpec() function, and has the same limitation: it is only for use 01819 // with a specific model 01820 void CreateConstraint(int mType[5], Generator& constrP, Generator& constrE) 01821 { 01822 01823 int i_lastState, fl, fr, tol, tor; 01824 i_lastState = fl = fr = tol = tor = 0; 01825 01826 std::string s_lastState, s_lastQup, s_lastQy, s_newQy, s_return; 01827 s_lastState = s_lastQup = s_lastQy = s_newQy = s_return = ""; 01828 01829 // the environment constraint constrE: this is an automata with one state, 01830 // one event and no transitions 01831 constrE.InsEvent("CBx_nack"); 01832 constrE.InsInitState("1"); 01833 constrE.SetMarkedState("1"); 01834 01835 // the operator constraint constrP 01836 constrP.InsEvent("CBx_free"); 01837 constrP.InsEvent("CBx_busy"); 01838 constrP.InsEvent("CBx_stby"); 01839 constrP.InsEvent("CBx_FL"); 01840 constrP.InsEvent("CBx_FR"); 01841 constrP.InsEvent("CBx_2L"); 01842 constrP.InsEvent("CBx_2R"); 01843 01844 // insert the states and transitions that are independent of the type of the 01845 // constraint 01846 constrP.InsInitState("1"); 01847 constrP.SetMarkedState("1"); 01848 s_return = "1"; 01849 s_lastQy = "1"; 01850 constrP.InsMarkedState("2"); 01851 constrP.SetTransition("1", "CBx_free", "2"); 01852 constrP.SetTransition("1", "CBx_busy", "2"); 01853 i_lastState = 2; 01854 s_lastQup = "2"; 01855 01856 // start the main loop 01857 for (int i=0; i<mType[0]; i++) 01858 { 01859 01860 //insert shared state Qy 01861 if(fl<mType[1] || fr<mType[2]) 01862 { 01863 s_lastState = ToStringInteger(i_lastState+1); 01864 constrP.InsMarkedState(s_lastState); 01865 s_newQy = s_lastState; 01866 constrP.SetTransition(s_lastQup, "CBx_stby", s_lastQy); 01867 i_lastState++; 01868 01869 } 01870 // insert "Take from left" transition if number of needed transitions not 01871 // already achieved 01872 if(fl<mType[1]) 01873 { 01874 constrP.SetTransition(s_lastQup, "CBx_FL", s_newQy); 01875 fl++; 01876 } 01877 01878 // insert "Take from right" transition if number of needed transitions not 01879 // already achieved 01880 if(fr<mType[2]) 01881 { 01882 constrP.SetTransition(s_lastQup, "CBx_FR", s_newQy); 01883 fr++; 01884 } 01885 // i>0 only after we implemented at least one "Take from..." action; if i==0 01886 // "Deliver to..." action will be not implemented, as a deliver action is not 01887 // possible yet 01888 if(i>0) 01889 { 01890 //insert 2L-Trans 01891 if(tol<mType[3]) 01892 { 01893 // insert corresponding "Deliver to..." transition 01894 // and increase the number of implemented "Deliver 01895 // to..." transitions 01896 constrP.SetTransition(s_lastQup, "CBx_2L", s_return); 01897 tol++; 01898 } 01899 01900 //insert 2R-Trans 01901 if(tor<mType[4]) 01902 { 01903 // insert corresponding "Deliver to..." transition 01904 // and increase the number of implemented "Deliver 01905 // to..." transitions 01906 constrP.SetTransition(s_lastQup, "CBx_2R", s_return); 01907 tor++; 01908 } 01909 01910 // store the last state 01911 s_return = s_lastQy; 01912 } 01913 01914 // implement stby loop 01915 s_lastState = ToStringInteger(i_lastState+1); 01916 constrP.InsMarkedState(s_lastState); 01917 constrP.SetTransition(s_newQy, "CBx_free", s_lastState); 01918 constrP.SetTransition(s_newQy, "CBx_busy", s_lastState); 01919 constrP.SetTransition(s_lastState, "CBx_stby", s_newQy); 01920 s_lastQup = s_lastState; 01921 i_lastState++; 01922 01923 // as i starts at 0, check if the limit is achieved and implemet the remaining 01924 // "Deliver to..." transitions 01925 if(i+1 == mType[0]) 01926 { 01927 if(tol<mType[3]) 01928 { 01929 constrP.SetTransition(s_lastQup, "CBx_2L", s_return); 01930 tol++; 01931 } 01932 01933 if(tor<mType[4]) 01934 { 01935 constrP.SetTransition(s_lastQup, "CBx_2R", s_return); 01936 tor++; 01937 } 01938 } 01939 // store the last state 01940 s_lastQy = s_newQy; 01941 01942 }//end for-loop - see comment at begin of the loop -> 01943 // "index" - stores the information about the capacity, i.e. how many 01944 // times we need to add the "Take from..." "Deliver from" cycle 01945 01946 01947 }// End create Constraint 01948 01949 } // end namespace faudes*******end namespace faudes********end namespace faudes 01950 01951 /********************************END*******************************************/ |
libFAUDES 2.20s --- 2011.10.12 --- c++ source docu by doxygen