65 FD_DF(
"IsBuechiTrim(): result " << res);
71 FD_DF(
"BuechiClosure("<< rGen.
Name() <<
")");
85 FD_DF(
"IsBuechiClosed("<< rGen.
Name() <<
")");
96 StateSet::Iterator sit_end = rGen.
States().
End();
98 for(; sit!=sit_end; ++sit) {
99 if(irrelevant.
Exists(*sit))
continue;
102 for (; tit != tit_end; ++tit) {
103 if(!irrelevant.
Exists(tit->X2))
break;
115 #ifdef FAUDES_DEBUG_FUNCTION
116 FD_DF(
"IsBuechiClosed(..): irrelevant states "<< irrelevant.
ToString());
121 std::list<StateSet> umsccs;
125 #ifdef FAUDES_DEBUG_FUNCTION
126 std::list<StateSet>::iterator ssit=umsccs.begin();
127 for(;ssit!=umsccs.end(); ++ssit) {
128 FD_DF(
"IsBuechiClosed(): GPlant-marked scc without GCand-mark: " << ssit->ToString());
132 return umsccs.empty();
147 if (
q1 < other.
q1)
return(
true);
148 if (
q1 > other.
q1)
return(
false);
149 if (
q2 < other.
q2)
return(
true);
150 if (
q2 > other.
q2)
return(
false);
170 FD_DF(
"BuechiProduct(" << &rGen1 <<
"," << &rGen2 <<
")");
174 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
175 pResGen= rResGen.
New();
185 std::map< OPState, Idx> reverseCompositionMap;
187 std::stack< OPState > todo;
189 OPState currentstates, newstates;
192 StateSet::Iterator lit1, lit2;
194 std::map< OPState, Idx>::iterator rcit;
196 FD_DF(
"BuechiProduct: adding all combinations of initial states to todo:");
199 currentstates =
OPState(*lit1, *lit2,
true);
200 todo.push(currentstates);
201 reverseCompositionMap[currentstates] = pResGen->
InsInitState();
202 FD_DF(
"BuechiProduct: " << currentstates.
Str() <<
" -> " << reverseCompositionMap[currentstates]);
207 FD_DF(
"BuechiProduct: processing reachable states:");
208 while (! todo.empty()) {
212 currentstates = todo.top();
214 FD_DF(
"BuechiProduct: processing (" << currentstates.
Str() <<
" -> " << reverseCompositionMap[currentstates]);
218 for(; tit1 != tit1_end; ++tit1) {
221 tit2_end = rGen2.
TransRelEnd(currentstates.q2, tit1->Ev);
222 for (; tit2 != tit2_end; ++tit2) {
223 newstates =
OPState(tit1->X2, tit2->X2,currentstates.m1required);
225 if(currentstates.m1required) {
233 rcit = reverseCompositionMap.find(newstates);
234 if(rcit == reverseCompositionMap.end()) {
235 todo.push(newstates);
240 reverseCompositionMap[newstates] = tmpstate;
241 FD_DF(
"BuechiProduct: todo push: (" << newstates.
Str() <<
") -> " << reverseCompositionMap[newstates]);
244 tmpstate = rcit->second;
248 FD_DF(
"BuechiProduct: add transition to new generator: " <<
249 pResGen->
TStr(
Transition(reverseCompositionMap[currentstates], tit1->Ev, tmpstate)));
259 for(rcit=reverseCompositionMap.begin(); rcit!=reverseCompositionMap.end(); rcit++) {
260 Idx x1=rcit->first.q1;
261 Idx x2=rcit->first.q2;
262 bool m1requ=rcit->first.m1required;
263 Idx x12=rcit->second;
269 std::string name12 = name1 +
"|" + name2;
270 if(m1requ) name12 +=
"|r1m";
271 else name12 +=
"|r2m";
281 if(pResGen != &rResGen) {
282 pResGen->
Move(rResGen);
297 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
298 pResGen= rResGen.
New();
308 if(pResGen != &rResGen) {
309 pResGen->
Move(rResGen);
320 FD_DF(
"BuechiParallel(" << &rGen1 <<
"," << &rGen2 <<
")");
323 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
324 pResGen= rResGen.
New();
335 FD_DF(
"BuechiParallel: shared events: " << sharedalphabet.
ToString());
338 std::map< OPState, Idx> reverseCompositionMap;
340 std::stack< OPState > todo;
342 OPState currentstates, newstates;
345 StateSet::Iterator lit1, lit2;
347 std::map< OPState, Idx>::iterator rcit;
349 FD_DF(
"BuechiParallel: adding all combinations of initial states to todo:");
352 currentstates =
OPState(*lit1, *lit2,
true);
358 todo.push(currentstates);
359 reverseCompositionMap[currentstates] = tmpstate;
360 FD_DF(
"BuechiParallel: " << currentstates.
Str() <<
" -> " << tmpstate);
365 FD_DF(
"BuechiParallel: processing reachable states:");
366 while (! todo.empty()) {
370 currentstates = todo.top();
372 FD_DF(
"BuechiParallel: processing (" << currentstates.
Str() <<
" -> "
373 << reverseCompositionMap[currentstates]);
378 for(; tit1 != tit1_end; ++tit1) {
380 if(! sharedalphabet.
Exists(tit1->Ev)) {
381 FD_DF(
"BuechiParallel: exists only in rGen1");
382 newstates =
OPState(tit1->X2, currentstates.q2, currentstates.m1required);
385 if(currentstates.m1required) {
392 rcit = reverseCompositionMap.find(newstates);
393 if (rcit == reverseCompositionMap.end()) {
394 todo.push(newstates);
397 reverseCompositionMap[newstates] = tmpstate;
398 FD_DF(
"BuechiParallel: todo push: " << newstates.
Str() <<
"|"
399 << reverseCompositionMap[newstates]);
402 tmpstate = rcit->second;
405 pResGen->
SetTransition(reverseCompositionMap[currentstates], tit1->Ev,
407 FD_DF(
"BuechiParallel: add transition to new generator: " <<
408 pResGen->
TStr(
Transition(reverseCompositionMap[currentstates], tit1->Ev, tmpstate)));
412 FD_DF(
"BuechiParallel: common event");
415 tit2_end = rGen2.
TransRelEnd(currentstates.q2, tit1->Ev);
416 for (; tit2 != tit2_end; ++tit2) {
417 newstates =
OPState(tit1->X2,tit2->X2,currentstates.m1required);
420 if(currentstates.m1required) {
432 rcit = reverseCompositionMap.find(newstates);
433 if (rcit == reverseCompositionMap.end()) {
434 todo.push(newstates);
437 reverseCompositionMap[newstates] = tmpstate;
438 FD_DF(
"BuechiParallel: todo push: (" << newstates.
Str() <<
") -> "
439 << reverseCompositionMap[newstates]);
442 tmpstate = rcit->second;
446 FD_DF(
"BuechiParallel: add transition to new generator: " <<
447 pResGen->
TStr(
Transition(reverseCompositionMap[currentstates], tit1->Ev, tmpstate)));
455 for (; tit2 != tit2_end; ++tit2) {
456 if (! sharedalphabet.
Exists(tit2->Ev)) {
457 FD_DF(
"BuechiParallel: exists only in rGen2: " << sharedalphabet.
Str(tit2->Ev));
458 newstates =
OPState(currentstates.q1, tit2->X2, currentstates.m1required);
461 if(!currentstates.m1required) {
467 FD_DF(
"BuechiParallel: set trans: " << currentstates.Str() <<
" " << newstates.
Str());
469 rcit = reverseCompositionMap.find(newstates);
470 if (rcit == reverseCompositionMap.end()) {
471 todo.push(newstates);
474 reverseCompositionMap[newstates] = tmpstate;
475 FD_DF(
"BuechiParallel: todo push: " << newstates.
Str() <<
" -> "
476 << reverseCompositionMap[newstates]);
479 tmpstate = rcit->second;
483 FD_DF(
"BuechiParallel: add transition to new generator: " <<
484 pResGen->
TStr(
Transition(reverseCompositionMap[currentstates], tit2->Ev, tmpstate)));
493 for(rcit=reverseCompositionMap.begin(); rcit!=reverseCompositionMap.end(); rcit++) {
494 Idx x1=rcit->first.q1;
495 Idx x2=rcit->first.q2;
496 bool m1requ=rcit->first.m1required;
497 bool mres=rcit->first.mresolved;
498 Idx x12=rcit->second;
504 std::string name12 = name1 +
"|" + name2 ;
505 if(m1requ) name12 +=
"|r1m";
506 else name12 +=
"|r2m";
507 if(mres) name12 +=
"*";
517 if(pResGen != &rResGen) {
518 pResGen->
Move(rResGen);
534 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
535 pResGen= rResGen.
New();
545 if(pResGen != &rResGen) {
546 pResGen->
Move(rResGen);
556 FD_DF(
"IsBuechiRelativelyMarked(\"" << rGenPlant.
Name() <<
"\", \"" << rGenCand.
Name() <<
"\")");
560 std::stringstream errstr;
561 errstr <<
"Alphabets of generators do not match.";
562 throw Exception(
"BuechiRelativelyMarked", errstr.str(), 100);
565 #ifdef FAUDES_CHECKED
568 std::stringstream errstr;
569 errstr <<
"Arguments are expected to be nonblocking.";
570 throw Exception(
"IsBuechiRelativelyMarked", errstr.str(), 201);
574 #ifdef FAUDES_CHECKED
577 std::stringstream errstr;
578 errstr <<
"Arguments are expected to be deterministic.";
579 throw Exception(
"IsBuechiRelativelyMarked", errstr.str(), 202);
585 std::map< std::pair<Idx,Idx> ,
Idx> revmap;
590 Product(rGenPlant,rGenCand,revmap,markPlant,markCand,product);
595 std::list<StateSet> umsccs;
600 std::list<StateSet>::iterator ssit=umsccs.begin();
601 for(;ssit!=umsccs.end(); ++ssit) {
602 FD_DF(
"IsBuechiRelativelyMarked(): GPlant-marked scc without GCand-mark: " << ssit->ToString());
606 return umsccs.size()==0;
618 FD_DF(
"IsBuechiRelativelyClosed(\"" << rGenPlant.
Name() <<
"\", \"" << rGenCand.
Name() <<
"\")");
622 std::stringstream errstr;
623 errstr <<
"Alphabets of generators do not match.";
624 throw Exception(
"BuechiRelativelyClosed", errstr.str(), 100);
627 #ifdef FAUDES_CHECKED
630 std::stringstream errstr;
631 errstr <<
"Argument \"" << rGenCand.
Name() <<
"\" is not omegatrim.";
632 throw Exception(
"IsBuechiRelativelyClosed", errstr.str(), 201);
635 std::stringstream errstr;
636 errstr <<
"Argument \"" << rGenPlant.
Name() <<
"\" is not omega-trim.";
637 throw Exception(
"IsBuechiRelativelyClosed", errstr.str(), 201);
644 if(rGenCand.
Empty()) {
645 FD_DF(
"IsBuechiRelativelyClosed(..): empty candidate: pass");
651 if(rGenPlant.
Empty()) {
652 FD_DF(
"IsBuechiRelativelyClosed(..): non-empty candidate. empty plant: fail");
656 #ifdef FAUDES_CHECKED
659 std::stringstream errstr;
660 errstr <<
"Arguments are expected to be deterministic.";
661 throw Exception(
"IsBuechiRelativelyClosed", errstr.str(), 202);
674 std::map< std::pair<Idx,Idx> ,
Idx> revmap;
684 std::stack< std::pair<Idx,Idx> > todo;
686 std::pair<Idx,Idx> currentstates, newstates;
690 StateSet::Iterator lit1, lit2;
692 std::map< std::pair<Idx,Idx>,
Idx>::iterator rcit;
694 bool inclusion12=
true;
697 FD_DF(
"IsBuechiRelativelyClosed(): Product composition A");
702 currentstates = std::make_pair(*lit1, *lit2);
703 todo.push(currentstates);
705 revmap[currentstates] = tmpstate;
706 FD_DF(
"IsBuechiRelativelyClosed(): Product composition A: (" << *lit1 <<
"|" << *lit2 <<
") -> "
707 << revmap[currentstates]);
712 while (! todo.empty() && inclusion12) {
716 currentstates = todo.top();
718 FD_DF(
"IsBuechiRelativelyClosed(): Product composition B: (" << currentstates.first <<
"|"
719 << currentstates.second <<
") -> " << revmap[currentstates]);
722 tit1_end = rGenCand.
TransRelEnd(currentstates.first);
724 tit2_end = rGenPlant.
TransRelEnd(currentstates.second);
726 bool resolved12=
true;
727 while((tit1 != tit1_end) && (tit2 != tit2_end)) {
729 if(tit1->Ev != curev1) {
730 if(!resolved12) inclusion12=
false;
735 if (tit1->Ev == tit2->Ev) {
737 newstates = std::make_pair(tit1->X2, tit2->X2);
739 rcit = revmap.find(newstates);
740 if (rcit == revmap.end()) {
741 todo.push(newstates);
743 revmap[newstates] = tmpstate;
744 FD_DF(
"IsBuechiRelativelyClosed(): Product composition C: (" << newstates.first <<
"|"
745 << newstates.second <<
") -> " << revmap[newstates]);
748 tmpstate = rcit->second;
750 product.
SetTransition(revmap[currentstates], tit1->Ev, tmpstate);
755 else if (tit1->Ev < tit2->Ev) {
759 else if (tit1->Ev > tit2->Ev) {
764 if(!resolved12) inclusion12=
false;
767 #ifdef FAUDES_DEBUG_FUNCTION
768 FD_DF(
"IsBuechiRelativelyClosed(): Product: done");
770 FD_DF(
"IsBuechiRelativelyClosed(): Product: inclusion L(G1) <= L(G2) not satisfied");
775 if(!inclusion12)
return false;
778 std::map< std::pair<Idx,Idx>,
Idx>::iterator rit;
779 for(rit=revmap.begin(); rit!=revmap.end(); ++rit){
787 std::list<StateSet> umsccs12;
789 ComputeScc(product,umfilter12,umsccs12,umroots12);
792 std::list<StateSet>::iterator ssit=umsccs12.begin();
793 for(;ssit!=umsccs12.end(); ++ssit) {
794 FD_DF(
"IsBuechiRelativelyClosed(): G2-marked scc without G1-mark: " << ssit->ToString());
798 if(umsccs12.size()!=0)
return false;
803 std::list<StateSet> umsccs21;
805 ComputeScc(product,umfilter21,umsccs21,umroots21);
808 ssit=umsccs21.begin();
809 for(;ssit!=umsccs21.end(); ++ssit) {
810 FD_DF(
"IsBuechiRelativelyClosed(): G1-marked scc without G2-mark: " << ssit->ToString());
814 if(umsccs21.size()!=0)
return false;
817 FD_DF(
"IsBuechiRelativelyClosed(): pass");
const std::string & Name(void) const
bool Exists(const Idx &rIndex) const
std::string Str(const Idx &rIndex) const
bool operator<(const OPState &other) const
OPState(const Idx &rq1, const Idx &rq2, const bool &rf)
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
StateSet::Iterator InitStatesBegin(void) const
bool SetTransition(Idx x1, Idx ev, Idx x2)
const StateSet & MarkedStates(void) const
const EventSet & Alphabet(void) const
virtual void Move(vGenerator &rGen)
std::string MarkedStatesToString(void) const
const StateSet & InitStates(void) const
TransSet::Iterator TransRelBegin(void) const
bool IsAccessible(void) const
void InsEvents(const EventSet &events)
bool IsComplete(void) const
virtual vGenerator * New(void) const
void InjectMarkedStates(const StateSet &rNewMarkedStates)
StateSet AccessibleSet(void) const
bool ExistsState(Idx index) const
bool IsCoaccessible(void) const
std::string TStr(const Transition &rTrans) const
std::string StateName(Idx index) const
TransSet::Iterator TransRelEnd(void) const
StateSet TerminalStates(void) const
void SetMarkedState(Idx index)
virtual void EventAttributes(const EventSet &rEventSet)
bool StateNamesEnabled(void) const
StateSet::Iterator InitStatesEnd(void) const
StateSet CoaccessibleSet(void) const
bool ExistsMarkedState(Idx index) const
std::string UniqueStateName(const std::string &rName) const
const StateSet & States(void) const
void InjectAlphabet(const EventSet &rNewalphabet)
bool Exists(const T &rElem) const
virtual void InsertSet(const TBaseSet &rOtherSet)
bool EqualAttributes(const TBaseSet &rOtherSet) const
Iterator Begin(void) const
virtual void EraseSet(const TBaseSet &rOtherSet)
bool ComputeScc(const Generator &rGen, const SccFilter &rFilter, std::list< StateSet > &rSccList, StateSet &rRoots)
void Product(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
bool IsDeterministic(const vGenerator &rGen)
void aBuechiProduct(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void BuechiProduct(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void BuechiParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void aBuechiParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
bool BuechiTrim(vGenerator &rGen)
void BuechiClosure(Generator &rGen)
bool IsBuechiClosed(const Generator &rGen)
bool IsBuechiRelativelyClosed(const Generator &rGenPlant, const Generator &rGenCand)
bool IsBuechiRelativelyMarked(const Generator &rGenPlant, const Generator &rGenCand)
void LoopCallback(bool pBreak(void))
bool IsBuechiTrim(const vGenerator &rGen)
std::string ToStringInteger(Int number)
std::string CollapsString(const std::string &rString, unsigned int len)
bool IsBuechiRelativelyClosedUnchecked(const Generator &rGenPlant, const Generator &rGenCand)