|
Go to the documentation of this file.
49 StateSet::Iterator lit;
56 FD_DF( "ProjectNonDet: todo add: " << rGen. SStr(*lit));
61 while (! todo.empty()) {
62 currentstate = todo.top();
65 FD_DF( "ProjectNonDet: current state: " << rGen. SStr(currentstate));
76 while(tit != tit_end) {
77 FD_DF( "ProjectNonDet: current transition: " << rGen. SStr(tit->X1)
78 << "-" << rGen. EStr(tit->Ev) << "-" << rGen. SStr(tit->X2));
79 if (! rProjectAlphabet. Exists(tit->Ev)) {
80 FD_DF( "ProjectNonDet: deleting current transition");
90 FD_DF( "ProjectNonDet: relinking outgoing transitions...");
91 for (lit = reach. Begin(); lit != reach. End(); ++lit) {
94 for (; tit != tit_end; ++tit) {
95 if (rProjectAlphabet. Exists(tit->Ev)) {
96 FD_DF( "ProjectNonDet: relinking transition: " << rGen. TStr(*tit) << " to " << rGen. SStr(currentstate));
98 if (! done. Exists(tit->X2)) {
99 FD_DF( "ProjectNonDet: todo push: " << rGen. SStr(tit->X2));
106 FD_DF( "ProjectNonDet: setting marked state " << rGen. SStr(currentstate));
129 std::stack<Idx> todod, todor;
132 StateSet::Iterator sit;
133 StateSet::Iterator sit_end;
149 while(!todod.empty()) {
152 FD_WPC(doned. Size() - todod.size(), rGen. Size(), "ProjectNonDet() [STD]: done/size: "
153 << doned. Size() - todod.size() << " / " << rGen. Size());
156 currentstate = todod.top();
158 FD_DF( "ProjectNonDet: current state: " << rGen. SStr(currentstate));
161 todor.push(currentstate);
163 doner. Insert(currentstate);
165 while(!todor.empty()) {
166 Idx reachstate = todor.top();
168 FD_DF( "ProjectNonDet: reach: " << rGen. SStr(reachstate));
174 for(; tit != tit_end; ++tit) {
175 if(tit->X1!=reachstate) break;
177 if(rProjectAlphabet. Exists(tit->Ev)) {
179 if(doned. Insert(tit->X2)) {
180 FD_DF( "ProjectNonDet: todod insert: " << rGen. SStr(tit->X2));
186 if(doner. Insert(tit->X2)) {
199 while(tit != tit_end) {
200 if(tit->X1!=currentstate) break;
201 FD_DF( "ProjectNonDet: current transition: " << rGen. SStr(tit->X1)
202 << "-" << rGen. EStr(tit->Ev) << "-" << rGen. SStr(tit->X2));
203 if(!rProjectAlphabet. Exists(tit->Ev)) {
204 FD_DF( "ProjectNonDet: deleting current transition");
236 template< class VLabel, class ELabel >
238 template< class VLabel, class ELabel >
240 template< class VLabel, class ELabel >
241 struct graph_iterator_t;
242 template< class VLabel, class ELabel >
243 struct node_iterator_t;
244 template< class VLabel, class ELabel >
264 template< class VLabel, class ELabel >
265 struct TGraph : std::map< VLabel , TNode< VLabel , ELabel > > {
270 static TGraph gInfX1; return gInfX1.begin(); }
279 template< class VLabel, class ELabel >
280 struct TNode : std::set< node_entry_t< VLabel , ELabel > > {
298 template< class VLabel, class ELabel >
310 inline bool operator<(const node_entry_t< VLabel , ELabel >& ent) const {
311 if(this-> Ev < ent.Ev) return true;
312 if(this-> Ev > ent.Ev) return false;
313 if(this-> X2It->first == ent.X2It->first) return false;
316 return this-> X2It->first < ent.X2It->first;
327 template< class VLabel, class ELabel >
334 : TGraph< VLabel , ELabel >::iterator() {}
336 : TGraph< VLabel , ELabel >::iterator(git) {}
338 inline VLabel X1( void) const { return (*this)->first; }
340 { return (* FakeConst())->second.begin(); }
342 { return (*this)->second.end(); }
344 { return (* FakeConst())->second.lower_bound(
347 { return (* FakeConst())->second.lower_bound(
352 if(x2it!=(* this)) ++(x2it->second.RefCnt);
356 if(nit-> X2It != (* this)) --(nit-> X2It->second.RefCnt);
357 (*this)->second.erase(nit);
360 ++((*this)->second.RefCnt);
363 inline Int& UsrFlg( void) { return (*this)->second.UsrFlg; }
365 std::string Str( void) const {
366 std::stringstream rep;
369 rep << "[" << X1() << "] ";
370 for(; nit!=nit_end; ++nit)
371 rep << "(" << nit. Ev() << ")->" << nit. X2() << " ";
382 template< class VLabel, class ELabel >
385 : TNode< VLabel , ELabel >::iterator() {}
387 : TNode< VLabel , ELabel >::iterator(nit) {}
388 inline ELabel Ev( void) const { return (*this)->Ev; }
390 inline VLabel X2( void) const { return (*this)->X2It->first; }
413 return (this->insert(std::make_pair(x1,mapped_type()))).first; }
415 if(Find(x1)==End()) return false;
418 for(;git!=git_end;++git) {
421 while(nit!=nit_end) {
422 if(nit. X2()==x1) git. Erase(nit++);
426 return ((*this).erase(x1)) !=0;
431 if(x2it->second.RefCnt == 0 ) ((*this).erase(x2it));
439 if(git==end()) git = insert(std::make_pair(tit->X1,mapped_type())).first;
441 if(x2it==end()) x2it = insert(std::make_pair(tit->X2,mapped_type())).first;
446 for(; sit != sit_end; sit++)
447 Find(*sit).IncRefCnt();
454 for(; git != git_end; git++) {
457 for(; nit != nit_end; ++nit) {
467 std::string Str( void) const {
468 std::stringstream rep;
471 for(; git!=git_end; ++git)
472 rep << git. Str() << std::endl;
478 return gInfX1.begin(); }
493 std::stack<Graph::Iterator> todod, todor;
494 std::stack<Graph::Iterator> todov;
498 StateSet::Iterator sit;
507 FD_WARN( "ProjectNonDet: convert to graph");
509 FD_WARN( "ProjectNonDet: convert to graph: done");
513 todod.push(trg. Find(*sit));
518 while(!todod.empty()) {
521 FD_WPC(doned. Size() - todod.size(),trg.size(), "ProjectNonDet() [G1]: done/size: "
522 << doned. Size() - todod.size() << "/" << trg.size());
525 currentstate = todod.top();
527 FD_DF( "ProjectNonDet: current state: " << rGen. SStr(currentstate.X1()));
530 todor.push(currentstate);
532 doner. Insert(currentstate.X1());
534 while(!todor.empty()) {
535 reachstate = todor.top();
537 FD_DF( "ProjectNonDet: reach: " << rGen. SStr(reachstate. X1()));
541 nit=reachstate. Begin();
542 nit_end=reachstate. End();
543 for(; nit != nit_end; ++nit) {
545 if(rProjectAlphabet. Exists(nit. Ev())) {
547 FD_DF( "ProjectNonDet: todod insert: " << rGen. SStr(nit. X2()));
548 todod.push(nit. X2It());
551 if(reachstate!=currentstate) {
552 FD_DF( "ProjectNonDet: trans insert: " << rGen. SStr(currentstate.X1()) << " -> " << rGen. SStr(nit. X2()));
553 currentstate.Insert(nit. Ev(),nit. X2It());
559 todor.push(nit. X2It());
560 if(nit. X2It()==currentstate)
561 todov.push(reachstate);
570 nit=currentstate.Begin();
571 nit_end=currentstate.End();
572 while(nit != nit_end) {
573 if(!rProjectAlphabet. Exists(nit. Ev()))
574 trg. Erase(currentstate,nit++);
583 FD_WARN( "ProjectNonDet: convert from graph");
585 FD_WARN( "ProjectNonDet: convert from graph: done");
604 std::stack<Idx> todod;
607 StateSet::Iterator sit, sit_end;
623 while(!todod.empty()) {
626 FD_WPC(doned. Size(),rGen. Size(), "ProjectNonDet() [SIMPL]: current/size: "
627 << doned. Size() << " / " << rGen. Size());
630 currentstate = todod.top();
632 FD_DF( "ProjectNonDet: current state: " << rGen. SStr(currentstate));
638 for(; tit != tit_end; ++tit) {
639 if(!doned. Exists(tit->X2)) { todod.push(tit->X2); doned. Insert(tit->X2); }
640 if(rProjectAlphabet. Exists(tit->Ev)) continue;
641 if(tit->X2==currentstate) continue;
649 sit_end = reach. End();
650 for(; sit != sit_end; ++sit) {
653 for(; tit != tit_end; ++tit) {
661 if(revisit) todod.push(currentstate);
665 FD_DF( "ProjectNonDet: finalize");
688 StateSet::Iterator lit;
689 StateSet::Iterator lit2;
712 while(!todo. Empty()) {
713 currentstate = *todo. Begin();
715 done. Insert(currentstate);
716 FD_DF( "ProjectNonDet: current state: " << rGen. SStr(currentstate));
724 FD_DF( "ProjectNonDet: relinking outgoing transitions...");
725 for(lit = reach. Begin(); lit != reach. End(); ++lit) {
728 for(; tit != tit_end; ++tit) {
729 if(rProjectAlphabet. Exists(tit->Ev)) {
730 FD_DF( "ProjectNonDet: relinking transition: " << rGen. TStr(*tit) << " to " << rGen. SStr(currentstate));
732 if (!done. Exists(tit->X2)) {
733 FD_DF( "ProjectNonDet: todo insert: " << rGen. SStr(tit->X2));
740 FD_DF( "ProjectNonDet: local reach from state " << tit->X2 << ": " << reachext. ToString());
741 for (lit2 = reachext. Begin(); lit2 != reachext. End(); ++lit2) {
742 if (!rGen. ExistsTransition(tit->X2, tit->Ev, *lit2) && (tit->X2 != *lit2)) {
744 FD_DF( "ProjectNonDet: setting transition: " << rGen. SStr(tit->X1) << "-" << rGen. EStr(tit->Ev) << "-" << rGen. SStr(*lit2));
746 if (!done. Exists(*lit2)) {
747 FD_DF( "ProjectNonDet: todo insert: " << rGen. SStr(tit->X2));
756 FD_DF( "ProjectNonDet: setting marked state " << rGen. SStr(currentstate));
764 while(tit != tit_end) {
765 FD_DF( "ProjectNonDet: current transition: " << rGen. SStr(tit->X1)
766 << "-" << rGen. EStr(tit->Ev) << "-" << rGen. SStr(tit->X2));
767 if(!rProjectAlphabet. Exists(tit->Ev)) {
768 FD_DF( "ProjectNonDet: deleting current transition");
803 std::stack<Idx> todod, todor, todof, todox;
804 StateSet doned, doner, donef, donex;
809 StateSet::Iterator sit;
810 StateSet::Iterator sit_end;
821 FD_WPD(0,1, "ProjectNonDet() [FB-REACH]: remove silent selfloops");
824 while(tit!=tit_end) {
825 if(tit->X1 == tit->X2)
826 if(!rProjectAlphabet. Exists(tit->Ev))
838 while(!todod.empty()) {
841 FD_WPD(donex. Size(), rGen. Size(), "ProjectNonDet() [FB-REACH]: done/size: "
842 << donex. Size() << " / " << rGen. Size());
845 currentstate = todod.top();
847 FD_DF( "ProjectNonDet: ---- current state: " << rGen. SStr(currentstate));
850 if(donex. Exists(currentstate)) continue;
853 FD_DF( "ProjectNonDet: running f-reach on " << rGen. SStr(currentstate));
855 todor.push(currentstate);
857 doner. Insert(currentstate);
858 Idx lastfound=currentstate;
859 while(!todor.empty()) {
860 reachstate = todor.top();
866 for(; tit != tit_end; ++tit) {
867 if(tit->X1 != reachstate) break;
869 if(rProjectAlphabet. Exists(tit->Ev)) {
885 if(reachstate!=currentstate) todox.push(reachstate);
890 if(donex. Exists(currentstate)) continue;
892 FD_DF( "ProjectNonDet: f-reach-proj found #" << doner. Size() << " reachable states");
893 FD_DF( "ProjectNonDet: f-reach-proj found #" << (donex*doner).Size() << " exit states");
898 FD_DF( "ProjectNonDet: f-reach-proj found #" << candx. Size() << " exit candidates");
904 FD_DF( "ProjectNonDet: running b-reach-proj on exitstates");
905 while(!todox.empty()) {
906 exitstate = todox.top();
908 FD_DF( "ProjectNonDet: -- b-reach on exit state: " << rGen. SStr(exitstate));
915 for(;tit!=tit_end; ++tit) {
916 if(tit->X1!=exitstate) break;
921 rit_end = revrel. End();
922 while(rit != rit_end) {
923 if(rit->X2!=exitstate) break;
929 if(donex. Exists(rit->X1)) {++rit; continue;}
930 FD_DF( "ProjectNonDet: -- b-reach predecessor: " << rGen. SStr(rit->X1));
934 for(;tit!=tit_end; ++tit)
939 FD_DF( "unlink " << rit->Str());
942 if(!donex. Exists(rit->X1)) {
946 while(tit != tit_end) {
947 if(rProjectAlphabet. Exists(tit->Ev)) { ++tit; continue;}
953 FD_DF( "ProjectNonDet: b-reach new exit state: " << rGen. SStr(currentstate));
956 candx. Erase(rit->X1);
971 if(doner<=donex) break;
975 FD_DF( "ProjectNonDet: b-reach-proj stuck with #" << donex. Size() << " exit states");
976 FD_DF( "ProjectNonDet: choosing first of #" << candx. Size() << " exit candidates");
977 exitstate= *candx. Begin();
981 FD_DF( "ProjectNonDet: running f-reach-proj on: " << rGen. SStr(exitstate));
982 todof.push(exitstate);
986 while(!todof.empty()) {
987 reachstate = todof.top();
994 for(; tit != tit_end; ++tit) {
995 if(tit->X1!=reachstate) break;
997 if(rProjectAlphabet. Exists(tit->Ev))
1001 if(donef. Insert(tit->X2))
1002 todof.push(tit->X2);
1006 FD_DF( "ProjectNonDet: f-reach-proj found #" << donef. Size() << " states");
1014 while(tit != tit_end) {
1015 if(tit->X1!=exitstate) break;
1016 if(!rProjectAlphabet. Exists(tit->Ev))
1023 #ifdef FAUDES_CHECKED
1024 if(donex. Exists(exitstate))
1025 FD_WARN( "ProjectNonDet: ERROR: new exit state " << exitstate);
1027 todox.push(exitstate);
1029 candx. Erase(exitstate);
1058 std::stack<Idx> todod, todor, todof, todox;
1059 StateSet doned, doner, donef, donex;
1064 StateSet::Iterator sit;
1065 StateSet::Iterator sit_end;
1076 FD_WPD(0,1, "ProjectNonDet() [SCC]: remove silent selfloops");
1079 while(tit!=tit_end) {
1080 if(tit->X1 == tit->X2)
1081 if(!rProjectAlphabet. Exists(tit->Ev))
1087 FD_WPD(0,1, "ProjectNonDet() [SCC]: compute silent sccs");
1091 std::list<StateSet> scclist;
1096 FD_WPD(0,1, "ProjectNonDet() [SCC]: processing #" << scclist.size() << " sccs");
1097 std::list<StateSet>::iterator cit=scclist.begin();
1098 std::list<StateSet>::iterator cit_end=scclist.end();
1099 std::map<Idx,Idx> sccxmap;
1101 for(;cit!=cit_end;++cit) {
1110 for(;sit!=sit_end;++sit){
1115 while(tit!=tit_end) {
1117 if(!cit->Exists(tit->X2)) {
1122 if(rProjectAlphabet. Exists(tit->Ev))
1135 for(;sit!=sit_end;++sit) sccxmap[*sit]=sccx;
1139 if(sccxmap.size()>0){
1140 FD_WPD(0,1, "ProjectNonDet() [SCC]: applying state substitution for #" << sccxmap.size() << " states");
1141 std::map<Idx,Idx>::iterator xxit;
1144 while(tit!=tit_end) {
1145 xxit=sccxmap.find(tit->X2);
1146 if(xxit==sccxmap.end()) {++tit; continue;}
1154 cit=scclist.begin();
1155 cit_end=scclist.end();
1156 for(;cit!=cit_end;++cit)
1170 while(!todod.empty()) {
1173 FD_WPD(donex. Size(), rGen. Size(), "ProjectNonDet() [FB-REACH]: done/size: "
1174 << donex. Size() << " / " << rGen. Size());
1177 currentstate = todod.top();
1179 FD_DF( "ProjectNonDet: ---- current state: " << rGen. SStr(currentstate));
1182 if(donex. Exists(currentstate)) continue;
1185 FD_DF( "ProjectNonDet: running f-reach on " << rGen. SStr(currentstate));
1187 todor.push(currentstate);
1189 doner. Insert(currentstate);
1190 Idx lastfound=currentstate;
1191 while(!todor.empty()) {
1192 reachstate = todor.top();
1198 for(; tit != tit_end; ++tit) {
1199 if(tit->X1 != reachstate) break;
1201 if(rProjectAlphabet. Exists(tit->Ev)) {
1202 if(doned. Insert(tit->X2))
1203 todod.push(tit->X2);
1210 if(doner. Insert(tit->X2))
1211 todor.push(tit->X2);
1216 donex. Insert(reachstate);
1217 if(reachstate!=currentstate) todox.push(reachstate);
1222 if(donex. Exists(currentstate)) continue;
1224 FD_DF( "ProjectNonDet: f-reach-proj found #" << doner. Size() << " reachable states");
1225 FD_DF( "ProjectNonDet: f-reach-proj found #" << (donex*doner).Size() << " exit states");
1230 FD_DF( "ProjectNonDet: f-reach-proj found #" << candx. Size() << " exit candidates");
1233 FD_DF( "ProjectNonDet: running b-reach-proj on exitstates");
1234 while(!todox.empty()) {
1235 exitstate = todox.top();
1237 FD_DF( "ProjectNonDet: -- b-reach on exit state: " << rGen. SStr(exitstate));
1244 for(;tit!=tit_end; ++tit) {
1245 if(tit->X1!=exitstate) break;
1250 rit_end = revrel. End();
1251 while(rit != rit_end) {
1252 if(rit->X2!=exitstate) break;
1258 if(donex. Exists(rit->X1)) {++rit; continue;}
1259 FD_DF( "ProjectNonDet: -- b-reach predecessor: " << rGen. SStr(rit->X1));
1262 tit_end=exits. End();
1263 for(;tit!=tit_end; ++tit)
1268 FD_DF( "unlink " << rit->Str());
1271 if(!donex. Exists(rit->X1)) {
1275 while(tit != tit_end) {
1276 if(rProjectAlphabet. Exists(tit->Ev)) { ++tit; continue;}
1282 FD_DF( "ProjectNonDet: b-reach new exit state: " << rGen. SStr(currentstate));
1283 todox.push(rit->X1);
1285 candx. Erase(rit->X1);
1293 revrel. Erase(rit++);
1300 #ifdef FAUDES_CHECKED
1301 if(!donex. Exists(currentstate))
1302 FD_WARN( "ProjectNonDet: ERROR: b-reach-proj stuck with #" << donex. Size() << " exit states");
1315 FD_WPD(0,1, "ProjectNonDet() [SCC]: done");
1340 if(&rResGen != &rGen) rResGen. Assign(rGen);
1407 if(&rResGen== &rGen) {
1408 pResGen= rResGen. New();
1411 Project(rGen,rProjectAlphabet,*pResGen);
1415 if(pResGen != &rResGen) {
1416 pResGen-> Move(rResGen);
1425 std::map<Idx,StateSet>& rEntryStatesMap, Generator& rResGen) {
1426 FD_DF( "Project(...)");
1428 std::map<Idx,StateSet> tmp_entrystatemap;
1430 if(&rResGen != &rGen) rResGen. Assign(rGen);
1437 std::vector<StateSet> subsets;
1438 std::vector<Idx> newindices;
1440 StateMin(*tmp, rResGen, subsets, newindices);
1442 std::vector<StateSet>::size_type i;
1443 std::map<Idx,StateSet>::iterator esmit;
1444 StateSet::Iterator sit;
1445 for (i = 0; i < subsets.size(); ++i) {
1447 for (sit = subsets[i].Begin(); sit != subsets[i].End(); ++sit) {
1448 esmit = tmp_entrystatemap.find(*sit);
1449 #ifdef FAUDES_DEBUG_CODE
1450 if (esmit == tmp_entrystatemap.end()) {
1451 FD_DF( "project internal error");
1459 rEntryStatesMap.insert(std::make_pair(newindices[i], tmpstates));
1469 std::stringstream errstr;
1470 errstr << "Input alphabet has to contain alphabet of generator \"" << rGen. Name() << "\"";
1471 throw Exception( "InvProject(Generator,EventSet)", errstr.str(), 506);
1476 FD_DF( "InvProject: adding events \"" << newevents. ToString()
1477 << "\" at every state");
1478 StateSet::Iterator lit;
1479 EventSet::Iterator eit;
1482 for (eit = newevents. Begin(); eit != newevents. End(); ++eit) {
1492 FD_DF( "aInvProject(..)");
1503 FD_DF( "aInvProject(..): fixing attributes: source " << typeid(rProjectAlphabet. Attribute()).name() <<
1505 for(EventSet::Iterator eit=newevents. Begin(); eit!=newevents. End(); ++eit)
1524 std::map<Idx,StateSet>& rEntryStatesMap) {
1525 std::map<StateSet,Idx>::const_iterator it;
1526 for (it = rRevEntryStatesMap.begin(); it != rRevEntryStatesMap.end(); ++it) {
1527 rEntryStatesMap.insert(std::make_pair(it->second, it->first));
libFAUDES 2.26g
--- 2015.08.17
--- c++ api documentaion by doxygen
|