|
|
Go to the documentation of this file.
106 cout << "Writing info-map for event " << event << endl;
107 const std::map<Idx,Idx> & pMap = infoMap[event];
108 std::map<Idx,Idx>::const_iterator mIt;
109 std::map<Idx,Idx>::const_iterator mItBegin = pMap.begin();
110 std::map<Idx,Idx>::const_iterator mItEnd = pMap.end();
111 if(mItBegin == mItEnd)
112 cout << "no entries for this event" << endl;
113 for(mIt=mItBegin; mIt != mItEnd; ++mIt)
114 cout << "state: " << (*mIt).first << " : occurrences: " << (*mIt).second << endl;
186 void partition(std::map<Idx,Idx>& rMapStateToPartition);
195 void partition(std::list< StateSet >& rPartition);
208 vector< vector<Idx> > suc;
209 vector< vector<Idx> > pre;
230 std::vector<Pnode*> W;
337 FD_DF( "Bisimulation::Bisimulation(" << g. Name() << ")");
362 states[smap[tit->X1]].suc[emap[tit->Ev]].push_back(smap[tit->X2]);
363 states[smap[tit->X2]].pre[emap[tit->Ev]].push_back(smap[tit->X1]);
368 universe->pParent=NULL;
371 for(;st< states.size();++st) universe->states.push_back(st);
372 universe->nsize = universe->states.size();
379 FD_DF( "Bisimulation::Bisimulation: leaving function");
385 vector<Pnode*>::iterator wit= W.begin();
386 vector<Pnode*>::iterator wit_end= W.end();
387 for(;wit!=wit_end;++wit) delete *wit;
396 nn->pFirstChild=NULL;
397 nn->pSecondChild=NULL;
399 nn->infoMap.resize( events.size());
400 nn->activeEv.resize( events.size());
414 FD_DF( "Bisimulation::partitionSplitter(B)");
415 FD_DF( "Bisimulation::partitionSplitter: index of current coset is " << B.index);
421 Pnode* BParent = B.pParent;
424 Pnode* BSmallerPart=BParent->pFirstChild;
425 Pnode* BLargerPart=BParent->pSecondChild;
426 if(BSmallerPart->nsize > BLargerPart->nsize) {
427 BSmallerPart=BParent->pSecondChild;
428 BLargerPart=BParent->pFirstChild;
431 FD_DF( "Bisimulation::partitionSplitter: the smaller coset (chosen) has index: " << BSmallerPart->index);
432 FD_DF( "Bisimulation::partitionSplitter: the larger coset has index: " << BLargerPart->index);
435 vector<Idx>::iterator sit;
436 vector<Idx>::iterator sit_end;
443 for(; ev < events.size(); ++ev){
447 if(!BParent->activeEv[ev]) continue;
452 BLargerPart->infoMap[ev]= BParent->infoMap[ev];
454 BSmallerPart->infoMap[ev].clear();
473 FD_DF( "Bisimulation::partitionSplitter: computing predecessor cosets of parent coset with index " << BParent->index);
474 set<Pnode*>::iterator rit;
475 for(rit= ro.begin(); rit!= ro.end(); ++rit) {
477 if((*rit)->nsize==1) continue;
479 Idx testState = *((*rit)->states.begin());
480 FD_DF( "Bisimulation::partitionSplitter: candidate coset index " << (*rit)->index << " and test state " << gen-> SStr(testState));
483 FD_DF( "Bisimulation::partitionSplitter: coset index " << (*rit)->index << " is predecessor for parent coset with index " << (*BParent).index << " and event = " << gen-> EStr( events[ev]) << " and was pushed on toDo-stack");
488 map<Idx, Idx> & imapParentEv = BParent->infoMap[ev];
489 map<Idx, Idx> & imapSmallerEv = BSmallerPart->infoMap[ev];
490 map<Idx, Idx>::const_iterator imapParentEvX1;
491 map<Idx, Idx>::const_iterator imapSmallerEvX1;
499 while(!toDo.empty()){
501 Pnode* rop=toDo.top();
503 FD_DF( "Bisimulation::partitionSplitter: current coset taken from todo-stack has index " << rop->index);
512 sit_end = rop->states.end();
513 for(sit=rop->states.begin(); sit!=sit_end; ++sit) {
514 if(imapSmallerEv.empty()){
517 imapSmallerEvX1=imapSmallerEv.find(*sit);
518 if(imapSmallerEvX1==imapSmallerEv.end()) {
521 imapParentEvX1=imapParentEv.find(*sit);
522 if(imapParentEvX1->second==imapSmallerEvX1->second)
543 sort(sX1.begin(), sX1.end());
544 sort(sX2.begin(), sX2.end());
545 sort(sX3.begin(), sX3.end());
551 if(!sX1.empty()) { nX1= newnode(); nX1->nsize=sX1.size(); nX1->states.swap(sX1); };
552 if(!sX2.empty()) { nX2= newnode(); nX2->nsize=sX2.size(); nX2->states.swap(sX2); };
553 if(!sX3.empty()) { nX3= newnode(); nX3->nsize=sX3.size(); nX3->states.swap(sX3); };
556 if((nX1!=NULL ? 1 : 0) + (nX2!=NULL ? 1 : 0) + (nX3!=NULL ? 1 : 0) <2) continue;
559 if(nX1!=NULL) { ro.insert(nX1); roDividers.insert(nX1);};
560 if(nX2!=NULL) { ro.insert(nX2); roDividers.insert(nX2);};
561 if(nX3!=NULL) { ro.insert(nX3); roDividers.insert(nX3);};
571 if(rop->pParent!=NULL && rop->pParent != BParent)
572 if(rop->pParent->pFirstChild->pFirstChild!=NULL && rop->pParent->pSecondChild->pSecondChild!=NULL) {
573 rop->pParent->infoMap.clear();
574 rop->pParent->states=vector<Idx>();
578 switch( (nX1!=NULL ? 1 : 0) + (nX2!=NULL ? 2 : 0) + (nX3!=NULL ? 4 : 0) ) {
586 FD_DF( "Bisimulation::partitionSplitter: coset " << rop->index << " has been split into cosets X1 and X2");
587 rop->pFirstChild=nX1;
588 rop->pSecondChild=nX2;
594 FD_DF( "Bisimulation::partitionSplitter: coset " << rop->index << " has been split into cosets X1 and X3");
595 rop->pFirstChild=nX1;
596 rop->pSecondChild=nX3;
602 FD_DF( "Bisimulation::partitionSplitter: coset " << rop->index << " has been split into cosets X2 and X3");
603 rop->pFirstChild=nX2;
604 rop->pSecondChild=nX3;
610 FD_DF( "Bisimulation::partitionSplitter: coset " << rop->index << " has been split into cosets X1, X2 and X3");
613 std::set_union(nX2->states.begin(), nX2->states.end(), nX3->states.begin(), nX3->states.end(),
614 std::inserter(nX23->states, nX23->states.begin()));
616 rop->pFirstChild=nX1;
617 rop->pSecondChild=nX23;
620 nX23->pFirstChild=nX2;
621 nX23->pSecondChild=nX3;
624 nX23->nsize=nX2->nsize + nX3->nsize;
633 BParent->infoMap.clear();
634 BParent->states=vector<Idx>();
637 BSmallerPart->rostable= true;
638 BLargerPart->rostable= true;
641 if(BSmallerPart->pFirstChild != NULL) BSmallerPart->states=vector<Idx>();
642 if(BLargerPart->pFirstChild != NULL) BLargerPart->states=vector<Idx>();
648 FD_DF( "Bisimulation::partitionSplitter: leaving function");
656 FD_DF( "Bisimulation::computeInfoMaps(" << node.index << "," << pSmallerPart->index << "," << pLargerPart->index << "," << gen-> EventName(ev) << ")");
659 if(node.states.empty()){
660 if(node.pFirstChild!=NULL)
662 if(node.pSecondChild!=NULL)
668 vector<Idx>::iterator tit;
669 vector<Idx>::iterator tit_end;
672 map<Idx,Idx>& imapLEv = pLargerPart->infoMap[ev];
673 map<Idx,Idx>& imapSEv = pSmallerPart->infoMap[ev];
674 map<Idx,Idx>::iterator imapLEvX1;
675 map<Idx,Idx>::iterator imapSEvX1;
678 vector<Idx>::iterator xit2=node.states.begin();
679 vector<Idx>::iterator xit2_end=node.states.end();
680 for(; xit2!=xit2_end; ++xit2) {
683 tit = states[*xit2].pre[ev].begin();
684 tit_end = states[*xit2].pre[ev].end();
685 for(; tit!=tit_end; ++tit) {
689 imapSEvX1=imapSEv.find(x1);
690 if(imapSEvX1!=imapSEv.end())
695 imapLEvX1=imapLEv.find(x1);
697 if(imapLEvX1->second==0) imapLEv.erase(imapLEvX1);
714 pSmallerPart->activeEv[ev]= !pSmallerPart->infoMap[ev].empty();
715 pLargerPart->activeEv[ev]= !pLargerPart->infoMap[ev].empty();
717 FD_DF( "Bisimulation::computeInfoMaps: leaving function");
725 FD_DF( "Bisimulation::stateLeadsToPartition(" << state << "," << node.index << "," << gen-> EventName(ev) << ")");
728 if(node.states.empty()) {
729 if(node.pFirstChild!=NULL)
731 if(node.pSecondChild!=NULL)
737 vector<Idx>::iterator tit = states[state].suc[ev].begin();
738 vector<Idx>::iterator tit_end = states[state].suc[ev].end();
739 for(;tit!=tit_end; ++tit) {
740 if(binary_search(node.states.begin(),node.states.end(),*tit)) return true;
787 FD_DF( "Bisimulation::partitionClass(" << B.index << ")");
788 FD_DF( "Bisimulation::partitionClass: index of passed coset is " << B.index);
791 vector<Pnode*> addSet;
792 vector<Pnode*>::iterator addIt;
793 vector<Pnode*> removeSet;
794 vector<Pnode*>::iterator remIt;
796 FD_DV( "Bisimulation::partitionClass: loop over events");
800 for(; ev< events.size(); ++ev) {
810 if(!B.activeEv[ev]) continue;
813 set<Pnode*>::iterator rit;
814 for(rit = ro.begin(); rit != ro.end(); ++rit) {
815 FD_DF( "Bisimulation::partitionClass: candidate coset to be split has index " << (*rit)->index);
818 if((*rit)->nsize==1) continue;
822 std::set_intersection((*rit)->states.begin(), (*rit)->states.end(), tb.begin(), tb.end(),
823 std::inserter(sXinter, sXinter.begin()));
826 if(sXinter.empty() || sXinter.size()==(*rit)->states.size()) continue;
827 FD_DF( "Bisimulation::partitionClass: current coset with index " << (*rit)->index << " will be split");
831 removeSet.push_back(*rit);
835 nXinter->nsize=sXinter.size();
836 nXinter->states.swap(sXinter);
837 (*rit)->pFirstChild=nXinter;
838 nXinter->pParent=*rit;
842 std::set_difference((*rit)->states.begin(), (*rit)->states.end(), nXinter->states.begin(), nXinter->states.end(),
843 std::inserter(nXdiff->states,nXdiff->states.begin()));
844 (*rit)->pSecondChild=nXdiff;
845 nXdiff->pParent=*rit;
846 nXdiff->nsize=nXdiff->states.size();
849 addSet.push_back(nXinter);
850 addSet.push_back(nXdiff);
855 FD_DF( "Bisimulation::partitionClass: the coset with index " << nXinter->index << " has been added to addSet and to roDividers");
856 FD_DF( "Bisimulation::partitionClass: the coset with index " << nXdiff->index << " has been added to addSet and to roDividers");
857 FD_DF( "Bisimulation::partitionClass: the candidate coset has been split");
860 if((*rit)->pParent!=NULL) {
861 FD_DF( "Bisimulation::partitionClass: split coset has parent coset with index " << (*rit)->pParent->index);
862 if((*rit)->pParent->pFirstChild->pFirstChild!=NULL && (*rit)->pParent->pSecondChild->pSecondChild!=NULL && (*rit)->pParent->rostable) {
863 (*rit)->pParent->infoMap.clear();
864 (*rit)->pParent->states=vector<Idx>();
865 FD_DF( "Bisimulation::partitionClass: info map of parent coset deleted");
871 FD_DF( "Bisimulation::partitionClass: states of split coset " << (*rit)->index << " have been deleted");
876 FD_DF( "Bisimulation::partitionClass: deleting split cosets from ro");
877 for(remIt=removeSet.begin(); remIt!=removeSet.end();++remIt)
882 FD_DF( "Bisimulation::partitionClass: inserting #" << addSet.size() << " new cosets into ro");
883 for(addIt=addSet.begin();addIt!=addSet.end();++addIt)
897 if(B.pFirstChild != NULL) B.states=vector<Idx>();
899 FD_DF( "Bisimulation::partitionClass(): done");
906 FD_DF( "Bisimulation::computeInfoMap(" << B.index << "," << Bstates.index << "," << gen-> EventName(ev) << ", Stateset&)");
907 FD_DF( "Bisimulation::computeInfoMap: consider stateSet of coset " << Bstates.index);
910 if(Bstates.states.empty()) {
911 if(Bstates.pFirstChild!=NULL)
913 if(Bstates.pSecondChild!=NULL)
919 vector< Idx >::iterator tit;
920 vector< Idx >::iterator tit_end;
923 map<Idx, Idx>& imapBEv = B.infoMap[ev];
924 map<Idx, Idx>::iterator imapBEvX1;
927 vector<Idx>::iterator xit2 = Bstates.states.begin();
928 vector<Idx>::iterator xit2_end = Bstates.states.end();
929 for(; xit2 != xit2_end; ++ xit2){
931 tit= states[*xit2].pre[ev].begin();
932 tit_end= states[*xit2].pre[ev].end();
933 for(; tit < tit_end; ++tit) {
938 imapBEvX1=imapBEv.find(x1);
939 if(imapBEvX1!=imapBEv.end()) ++imapBEvX1->second;
944 sort(tb.begin(),tb.end());
946 B.activeEv[ev]= !tb.empty();
948 FD_DF( "Bisimulation::computeInfoMap: leaving function");
962 vector<State>::iterator sit= states.begin();
963 if(sit!= states.end()) ++sit;
964 for(;sit!= states.end();++sit) {
970 vector< Idx >::iterator tit;
971 vector< Idx >::iterator tit_end;
972 vector<Idx>::iterator xit2;
977 xit2 = BSmaller.states.begin();
978 for(; xit2 != BSmaller.states.end(); ++xit2) {
980 tit= states[*xit2].pre[ev].begin();
981 tit_end= states[*xit2].pre[ev].end();
982 for(; tit < tit_end; ++tit) {
989 if(found) BSmaller.activeEv[ev]= true;
994 xit2 = BLarger.states.begin();
995 for(; xit2 != BLarger.states.end(); ++xit2) {
997 tit= states[*xit2].pre[ev].begin();
998 tit_end= states[*xit2].pre[ev].end();
999 for(; tit < tit_end; ++tit) {
1006 if(found) BLarger.activeEv[ev]= true;
1008 FD_DF( "Bisimulation::setInfoMap: leaving function");
1016 if(Bstates.states.empty()) {
1017 if(Bstates.pFirstChild!=NULL)
1018 invImage(B, *(Bstates.pFirstChild), ev, tb);
1019 if(Bstates.pSecondChild!=NULL)
1020 invImage(B, *(Bstates.pSecondChild), ev, tb);
1025 vector< Idx >::iterator tit;
1026 vector< Idx >::iterator tit_end;
1029 vector<Idx>::iterator xit2 = Bstates.states.begin();
1030 for(; xit2 != Bstates.states.end(); ++xit2) {
1032 tit= states[*xit2].pre[ev].begin();
1033 tit_end= states[*xit2].pre[ev].end();
1034 for(; tit < tit_end; ++tit) {
1041 sort(tb.begin(),tb.end());
1043 B.activeEv[ev]= !tb.empty();
1049 FD_DF( "Bisimulation::refine()");
1051 set<Pnode*>::iterator roDivIt;
1062 pParent=(*roDivIt)->pParent;
1063 if(pParent == NULL) { roDivIt++; continue; };
1064 if(pParent->rostable != true) { roDivIt++; continue; };
1083 FD_DF( "Bisimulation::partition(rMapStateToPartition," << rGenPart. Name() << ")");
1087 rMapStateToPartition.clear();
1090 set<Pnode*>::const_iterator cRoIt = ro.begin();
1091 set<Pnode*>::const_iterator cRoItEnd = ro.end();
1092 vector<Idx>::iterator cSIt;
1093 vector<Idx>::iterator cSItEnd;
1094 for(; cRoIt != cRoItEnd; ++cRoIt) {
1096 std::ostringstream ostr;
1098 FD_DF( "Bisimulation::partition: new state " << newstate << " for coset "
1099 << (*cRoIt)->index );
1102 cSIt=(*cRoIt)->states.begin();
1103 cSItEnd=(*cRoIt)->states.end();
1104 for(; cSIt != cSItEnd; ++cSIt) {
1109 rMapStateToPartition[st] = newstate;
1113 else ostr << st << ",";
1125 std::string statename = ostr.str();
1126 if(statename.length()>=1) statename.erase(statename.length()-1);
1127 statename = "{" + statename + "}";
1128 rGenPart. StateName(newstate, statename);
1129 FD_DF( "Bisimulation::partition: new state " << statename);
1138 for(; tIt != tItEnd; ++tIt) {
1140 rGenPart. SetTransition(rMapStateToPartition[tIt->X1], tIt->Ev, rMapStateToPartition[tIt->X2]);
1141 FD_DF( "Bisimulation::partition: adding transition: X1=" << rGenPart. TStr(*tIt) );
1143 FD_DF( "Bisimulation::partition: leaving function");
1150 FD_DF( "Bisimulation::partition(rMapStateToPartition)");
1154 rMapStateToPartition.clear();
1157 set<Pnode*>::const_iterator cRoIt = ro.begin();
1158 set<Pnode*>::const_iterator cRoItEnd = ro.end();
1159 vector<Idx>::iterator cSIt;
1160 vector<Idx>::iterator cSItEnd;
1161 for (; cRoIt != cRoItEnd; ++cRoIt) {
1162 cSIt=(*cRoIt)->states.begin();
1163 cSItEnd=(*cRoIt)->states.end();
1164 for(; cSIt!=cSItEnd; ++ cSIt) {
1167 rMapStateToPartition[st] = (*cRoIt)->index;
1170 FD_DF( "Bisimulation::partition: leaving function");
1176 FD_DF( "Bisimulation::partition(rPartition)");
1182 set<Pnode*>::const_iterator cRoIt = ro.begin();
1183 for(; cRoIt != ro.end(); ++cRoIt) {
1184 if((*cRoIt)->states.size()<=1) continue;
1186 vector<Idx>::iterator cSIt=(*cRoIt)->states.begin();
1187 for(; cSIt!=(*cRoIt)->states.end(); ++ cSIt) tb. Insert( states[*cSIt].idx);
1188 rPartition.push_back(tb);
1190 FD_DF( "Bisimulation::partition: leaving function");
1197 FD_DF( "Bisimulation:writeW()");
1198 cout << "Plotting the W-tree:" << endl;
1205 FD_DF( "Bisimulation::writeNode(" << node.index << ")");
1206 cout << "Coset with index " << node.index << " has the following states:" << endl;
1207 vector<Idx>::iterator cSIt;
1208 vector<Idx>::iterator cSItEnd;
1209 cSIt=node.states.begin();
1210 cSItEnd=node.states.end();
1211 for(; cSIt!=cSItEnd; ++ cSIt) cout << *cSIt << " ";
1213 if(node.pParent!=NULL)
1214 cout << "Parent coset has index: " << node.pParent->index << endl;
1216 cout << "Coset is the root of the tree" << endl;
1217 if(node.pParent!=NULL)
1218 if(node.pParent->pFirstChild!=NULL)
1219 if(node.index!=node.pParent->pFirstChild->index)
1220 cout << "Coset has brother coset with index: " << node.pParent->pFirstChild->index << endl;
1221 if(node.pParent!=NULL)
1222 if(node.pParent->pSecondChild!=NULL)
1223 if(node.index!=node.pParent->pSecondChild->index)
1224 cout << "Coset has brother coset with index: " << node.pParent->pSecondChild->index << endl;
1227 if(node.pFirstChild!=NULL && node.pSecondChild!=NULL)
1228 cout << "Child cosets have indices : " << node.pFirstChild->index << " and " << node.pSecondChild->index << endl;
1230 cout << "Coset has no children" << endl;
1231 cout << "ro is stable with respect to this coset (1=yes; 0=no): " << node.rostable << endl;
1248 FD_DF( "Bisimulation::writeRo()");
1249 cout << "The Cosets with the following indices are in ro: " << endl;
1250 set<Pnode*>::iterator roIt;
1251 set<Pnode*>::iterator roItBegin = ro.begin();
1252 set<Pnode*>::iterator roItEnd = ro.end();
1253 for(roIt=roItBegin; roIt!=roItEnd; roIt++)
1254 cout << (*roIt)->index << endl;
1274 FD_DF( "ComputeBisimulation(" << rGenOrig. Name() << ", rMapStateToPartition)");
1280#ifdef FAUDES_DEBUG_FUNCTION
1281 cout << "The result of the partition refinement is:" << endl;
1285 FD_DF( "ComputeBisimulation: leaving function");
1291 FD_DF( "ComputeBisimulation(" << rGenOrig. Name() << ", rMapStateToPartition, " << rGenPart. Name() << ")");
1296 bisim. partition(rMapStateToPartition, rGenPart);
1298 cout << "The result of the partition refinement is:" << endl;
1302 FD_DF( "ComputeBisimulation: leaving function");
1308 FD_DF( "ComputeBisimulation(" << rGenOrig. Name() << ", rPartition)");
1315 cout << "The result of the partition refinement is:" << endl;
1319 FD_DF( "ComputeBisimulation: leaving function");
#define FD_WPC(cntnow, contdone, message)
void partitionClass(Pnode &B)
void computeInfoMap(Pnode &B, Pnode &Bstates, Idx ev, vector< Idx > &tb)
std::set< Pnode * > roDividers
void partition(std::map< Idx, Idx > &rMapStateToPartition, Generator &rGenPart)
void invImage(Pnode &B, Pnode &Bstates, Idx ev, vector< Idx > &tb)
bool stateLeadsToPartition(Idx state, Pnode &node, Idx ev)
void computeInfoMaps(Pnode &node, Pnode *pSmallerPart, Pnode *pLargerPart, Idx ev)
Bisimulation(const Generator &g)
void writeNode(Pnode &node)
void partitionSplitter(Pnode &B)
void setInfoMap(Pnode &BSmaller, Pnode &BLarger, Idx ev)
const std::string & Name(void) const
StateSet::Iterator StatesBegin(void) const
bool SetTransition(Idx x1, Idx ev, Idx x2)
const EventSet & Alphabet(void) const
TransSet::Iterator TransRelBegin(void) const
EventSet::Iterator AlphabetBegin(void) const
void SetInitState(Idx index)
std::string TStr(const Transition &rTrans) const
std::string StateName(Idx index) const
StateSet::Iterator StatesEnd(void) const
TransSet::Iterator TransRelEnd(void) const
std::string EStr(Idx index) const
void SetMarkedState(Idx index)
bool StateNamesEnabled(void) const
std::string EventName(Idx index) const
EventSet::Iterator AlphabetEnd(void) const
bool ExistsInitState(Idx index) const
std::string SStr(Idx index) const
bool ExistsMarkedState(Idx index) const
const StateSet & States(void) const
void ComputeBisimulation(const Generator &rGenOrig, map< Idx, Idx > &rMapStateToPartition)
vector< vector< Idx > > pre
vector< vector< Idx > > suc
void writeInfoMap(Idx event) const
std::vector< bool > activeEv
std::vector< std::map< Idx, Idx > > infoMap
std::vector< Idx > states
libFAUDES 2.33k
--- 2025.09.16
--- c++ api documentaion by doxygen
|