111 void partition(std::map<Idx,Idx>& rMapStateToPartition,
Generator& rGenPart);
121 vector< vector<Idx> >
suc;
122 vector< vector<Idx> >
pre;
183 std::vector<Pnode*>
W;
198 void initStateMember_Pre();
203 void initStateMember_Pres();
216 void partitionClass(
Pnode& B);
226 void computeRel(
Pnode& B, std::vector<Relation>& relations);
241 void computeEquStates(
Pnode& B,
Relation& rel, std::set<Idx>& tb, std::stack<Pnode*>& todo);
247 void relCase_1(
Pnode& B,
Relation& rel, set<Idx>& tb, stack<Pnode*>& todo);
248 void relCase_2(
Pnode& B,
Relation& rel, set<Idx>& tb, stack<Pnode*>& todo);
249 void relCase_3(
Pnode& B,
Relation& rel, set<Idx>& tb, stack<Pnode*>& todo);
250 void relCase_4(
Pnode& B,
Relation& rel, set<Idx>& tb, stack<Pnode*>& todo);
270 std::vector<Pnode*>::iterator wit=W.begin();
271 for(; wit!=W.end(); ++wit)
delete *wit;
282 std::map<Idx,Idx> smap;
283 std::map<Idx,Idx> emap;
286 events.resize(gen->Alphabet().Size()+1);
288 for(; eit != gen->AlphabetEnd(); ++eit) {
294 states.resize(gen->States().Size()+1);
295 StateSet::Iterator sit=gen->StatesBegin();
296 for(; sit != gen->StatesEnd(); ++sit) {
298 states[max].idx=*sit;
299 states[max].pre.resize(events.size());
300 states[max].suc.resize(events.size());
301 states[max].shaconPre.resize(events.size());
302 states[max].shauncPre.resize(events.size());
303 states[max].shauncPres.resize(events.size());
307 for(; tit != gen->TransRelEnd(); ++tit) {
308 states[smap[tit->X2]].pre[emap[tit->Ev]].push_back(smap[tit->X1]);
309 states[smap[tit->X1]].suc[emap[tit->Ev]].push_back(smap[tit->X2]);
313 eit=rConAlph.
Begin();
314 for(; eit != rConAlph.
End(); ++eit) conalph.insert(emap[*eit]);
315 eit=rLocAlph.
Begin();
316 for(; eit != rLocAlph.
End(); ++eit) localph.insert(emap[*eit]);
318 for(; ev < events.size(); ++ev)
319 if(conalph.find(ev) == conalph.end()) uncalph.insert(ev);
321 for(; ev < events.size(); ++ev)
322 if(localph.find(ev) == localph.end()) shaalph.insert(ev);
324 std::set_intersection(localph.begin(), localph.end(), uncalph.begin(), uncalph.end(),
325 std::inserter(locuncalph, locuncalph.begin()));
326 std::set_intersection(localph.begin(), localph.end(), conalph.begin(), conalph.end(),
327 std::inserter(locconalph, locconalph.begin()));
328 std::set_intersection(shaalph.begin(), shaalph.end(), uncalph.begin(), uncalph.end(),
329 std::inserter(shauncalph, shauncalph.begin()));
330 std::set_intersection(shaalph.begin(), shaalph.end(), conalph.begin(), conalph.end(),
331 std::inserter(shaconalph, shaconalph.begin()));
334 initStateMember_Pre();
335 initStateMember_Pres();
338 Pnode* universe = newnode();
340 for(;st<states.size();++st) universe->states.insert(st);
341 universe->nsize = universe->states.size();
344 roDividers.insert(universe);
349 void SOE::initStateMember_Pre()
352 std::set<Idx>::iterator sit;
353 std::vector<Idx>::iterator vit;
356 sit=shaconalph.begin();
357 for(; sit!=shaconalph.end(); ++sit) {
359 for(; idx < states.size(); ++idx) {
360 vit=states[idx].pre[*sit].begin();
361 for(;vit!=states[idx].pre[*sit].end();++vit)
362 states[idx].shaconPre[*sit].push_back(*vit);
367 sit=shauncalph.begin();
368 for(;sit!=shauncalph.end();++sit) {
370 for(;idx<states.size();++idx) {
371 vit=states[idx].pre[*sit].begin();
372 for(;vit!=states[idx].pre[*sit].end();++vit)
373 states[idx].shauncPre[*sit].push_back(*vit);
378 sit=locconalph.begin();
379 for(;sit!=locconalph.end();++sit) {
381 for(;idx<states.size();++idx) {
382 vit=states[idx].pre[*sit].begin();
383 for(;vit!=states[idx].pre[*sit].end();++vit)
384 states[idx].locconPre.push_back(*vit);
389 sit=locuncalph.begin();
390 for(;sit!=locuncalph.end();++sit) {
392 for(;idx<states.size();++idx) {
393 vit=states[idx].pre[*sit].begin();
394 for(;vit!=states[idx].pre[*sit].end();++vit)
395 states[idx].locuncPre.push_back(*vit);
401 void SOE::initStateMember_Pres()
404 std::stack<Idx> todo;
405 std::vector<Idx>::iterator vit;
406 std::vector<Idx>::iterator Ivit;
410 for(;idx<states.size();++idx) {
411 vit=states[idx].locuncPre.begin();
412 for(;vit!=states[idx].locuncPre.end();++vit) {
414 while(!todo.empty()) {
417 if(std::find(states[idx].locuncPres.begin(),states[idx].locuncPres.end(),st)
418 !=states[idx].locuncPres.end())
continue;
419 states[idx].locuncPres.push_back(st);
420 Ivit=states[st].locuncPre.begin();
421 for(;Ivit!=states[st].locuncPre.end();++Ivit)
427 std::set<Idx> tempset;
428 std::set<Idx>::iterator sit;
429 std::vector<Idx>::iterator IIvit;
432 sit=shauncalph.begin();
433 for(;sit!=shauncalph.end();++sit) {
435 for(;idx<states.size();++idx) {
436 vit=states[idx].locuncPre.begin();
437 for(;vit!=states[idx].locuncPre.end();++vit) {
439 while(!todo.empty()){
442 if(tempset.find(st)!=tempset.end())
continue;
444 Ivit=states[st].locuncPre.begin();
445 for(;Ivit!=states[st].locuncPre.end();++Ivit)
447 IIvit=states[st].shauncPre[*sit].begin();
448 for(;IIvit!=states[st].shauncPre[*sit].end();++IIvit)
449 states[st].shauncPres[*sit].push_back(*IIvit);
461 vector<Relation> relations;
462 std::stack<Pnode*> todo;
463 std::vector<Pnode*> addSet;
464 std::vector<Pnode*> removeSet;
466 vector<Relation>::iterator relIt;
467 std::vector<Pnode*>::iterator addIt;
468 std::vector<Pnode*>::iterator remIt;
471 computeRel(B, relations);
474 relIt=relations.begin();
475 for(; relIt!=relations.end(); ++relIt) {
479 computeEquStates(B, *relIt, tb, todo);
483 while(!todo.empty()) {
484 Pnode* rop=todo.top();
488 if(rop->nsize==1)
continue;
490 if(rop->states.empty())
continue;
493 std::set<Idx> sXinter;
494 std::set_intersection(rop->states.begin(), rop->states.end(),
495 tb.begin(), tb.end(),
496 std::inserter(sXinter, sXinter.begin()));
499 if(sXinter.size()==rop->states.size())
continue;
502 roDividers.erase(rop);
503 removeSet.push_back(rop);
506 Pnode* nXinter= newnode();
507 nXinter->states.swap(sXinter);
508 nXinter->nsize=sXinter.size();
511 Pnode* nXdiff = newnode();
512 std::set_difference(rop->states.begin(), rop->states.end(), nXinter->states.begin(),
513 nXinter->states.end(),
514 std::inserter(nXdiff->states, nXdiff->states.begin()));
515 nXdiff->nsize=nXdiff->states.size();
518 addSet.push_back(nXinter);
519 addSet.push_back(nXdiff);
520 roDividers.insert(nXinter);
521 roDividers.insert(nXdiff);
529 for(remIt=removeSet.begin(); remIt!=removeSet.end(); ++remIt) ro.erase(*remIt);
533 for(addIt=addSet.begin(); addIt!=addSet.end(); ++addIt) ro.insert(*addIt);
537 if(B.states.empty())
return;
542 roDividers.erase(&B);
548 void SOE::computeRel(
Pnode& B, std::vector<Relation>& relations)
554 std::set<Idx>::iterator sit;
555 std::set<Idx>::iterator evit;
556 std::vector<Idx>::iterator vit;
561 for(evit=shaconalph.begin(); evit!=shaconalph.end(); ++evit) {
563 for(sit=B.states.begin(); sit!=B.states.end(); ++sit) {
565 vit=states[*sit].shaconPre[*evit].begin();
566 for(;vit!=states[*sit].shaconPre[*evit].end();++vit) {
569 rel.
pre.insert(*vit);
570 relations.push_back(rel);
576 for(evit=shauncalph.begin();evit!=shauncalph.end();++evit) {
580 for(sit=B.states.begin(); sit!=B.states.end(); ++sit) {
582 vit=states[*sit].shauncPre[*evit].begin();
583 for(;vit!=states[*sit].shauncPre[*evit].end();++vit) {
584 rel.
pre.insert(*vit);
587 if(!rel.
pre.empty()) relations.push_back(rel);
591 for(evit=locconalph.begin(); evit!=locconalph.end(); ++evit) {
593 for(sit=B.states.begin(); sit!=B.states.end(); ++sit) {
595 vit=states[*sit].locconPre.begin();
596 for(;vit!=states[*sit].locconPre.end();++vit) {
599 rel.
pre.insert(*vit);
600 relations.push_back(rel);
607 for(evit=locuncalph.begin();evit!=locuncalph.end();++evit) {
610 for(sit=B.states.begin(); sit!=B.states.end(); ++sit) {
611 vit=states[*sit].locuncPre.begin();
612 for(;vit!=states[*sit].locuncPre.end();++vit)
613 rel.
pre.insert(*vit);
616 if(!rel.
pre.empty()) relations.push_back(rel);
623 std::stack<Pnode*>& todo)
628 if(shaconalph.find(rel.
ev)!=shaconalph.end()) {
629 relCase_1(B, rel, tb, todo);
return;}
631 else if(shauncalph.find(rel.
ev)!=shauncalph.end()) {
632 relCase_2(B, rel, tb, todo);
return;}
634 else if(locconalph.find(rel.
ev)!=locconalph.end()) {
635 relCase_3(B, rel, tb, todo);
return;}
637 else if(locuncalph.find(rel.
ev)!=locuncalph.end()) {
638 relCase_4(B, rel, tb, todo);
return;}
640 std::cout<<
"####[SOE]this can not happen[SOE]####\n";
646 void SOE::relCase_1(
Pnode& B,
Relation& rel, set<Idx>& tb, stack<Pnode*>& todo)
650 std::stack<Idx> stodo;
651 std::set<Idx>::iterator sit;
652 std::vector<Idx>::iterator vit;
653 std::set<Pnode*>::iterator roIt;
657 for(; sit!=rel.
pre.end(); ++sit) {
659 for(; roIt!=ro.end(); ++roIt) {
660 if((*roIt)->states.find(*sit)!=(*roIt)->states.end()) {
668 sit=B.states.begin();
669 for(;sit!=B.states.end();++sit) {
670 vit=states[*sit].shaconPre[rel.
ev].begin();
671 for(;vit!=states[*sit].shaconPre[rel.
ev].end();++vit)
676 while(!stodo.empty()) {
679 if(tb.find(idx)!=tb.end())
continue;
682 vit=states[idx].locuncPre.begin();
683 for(;vit!=states[idx].locuncPre.end();++vit)
686 vit=states[idx].locconPre.begin();
687 for(;vit!=states[idx].locconPre.end();++vit)
688 if(todo.top()->states.find(*vit)!=todo.top()->states.end())
696 void SOE::relCase_2(
Pnode& B,
Relation& rel, set<Idx>& tb, stack<Pnode*>& todo)
700 std::set<Idx>::iterator sit;
701 std::vector<Idx>::iterator vit;
702 std::set<Pnode*>::iterator roIt;
706 for(; sit!=rel.
pre.end(); ++sit) {
708 for(; roIt!=ro.end(); ++roIt) {
709 if((*roIt)->states.find(*sit)!=(*roIt)->states.end()) {
720 sit=B.states.begin();
721 for(; sit != B.states.end(); ++sit) {
722 vit=states[*sit].shauncPres[rel.
ev].begin();
723 for(; vit!=states[*sit].shauncPres[rel.
ev].end(); ++vit) tb.insert(*vit);
728 for(; sit != tb.end(); ++sit) {
729 vit=states[*sit].locuncPres.begin();
730 for(; vit != states[*sit].locuncPres.end(); ++vit) tb.insert(*vit);
737 void SOE::relCase_3(
Pnode& B,
Relation& rel, set<Idx>& tb, stack<Pnode*>& todo)
741 std::stack<Idx> stodo;
742 std::set<Idx>::iterator sit;
743 std::vector<Idx>::iterator vit;
744 std::set<Pnode*>::iterator roIt;
748 for(; sit!=rel.
pre.end(); ++sit) {
750 for(; roIt!=ro.end(); ++roIt) {
751 if((*roIt)->states.find(*sit)!=(*roIt)->states.end()) {
762 sit=B.states.begin();
763 for(; sit!=B.states.end(); ++sit) {
764 vit=states[*sit].locconPre.begin();
765 for(; vit != states[*sit].locconPre.end(); ++vit)
770 while(!stodo.empty()) {
773 if(tb.find(idx)!=tb.end())
continue;
776 vit=states[idx].locuncPre.begin();
777 for(;vit!=states[idx].locuncPre.end();++vit)
780 vit=states[idx].locconPre.begin();
781 for(;vit!=states[idx].locconPre.end();++vit)
782 if(todo.top()->states.find(*vit)!=todo.top()->states.end())
790 void SOE::relCase_4(
Pnode& B,
Relation& rel, set<Idx>& tb, stack<Pnode*>& todo)
794 std::vector<Idx>::iterator vit;
795 std::set<Idx>::iterator sit;
796 std::set<Pnode*>::iterator roIt;
800 for(; sit!=rel.
pre.end(); ++sit) {
802 for(; roIt!=ro.end(); ++roIt) {
803 if((*roIt)->states.find(*sit)!=(*roIt)->states.end()) {
814 sit=B.states.begin();
815 for(; sit != B.states.end(); ++sit) {
816 vit=states[*sit].locuncPres.begin();
817 for(; vit != states[*sit].locuncPres.end(); ++vit)
826 FD_DF(
"SOE::refine()");
829 std::set<Pnode*>::iterator roDivIt;
831 while(!roDividers.empty()) {
832 roDivIt=roDividers.begin();
833 partitionClass(**roDivIt);
839 void SOE::partition(std::map<Idx,Idx>& rMapStateToPartition,
Generator& rGenPart) {
841 FD_DF(
"SOE::partition(rMapStateToPartition," << rGenPart.
Name() <<
")");
845 rGenPart.
Name(gen->Name());
846 rMapStateToPartition.clear();
849 std::set<Pnode*>::iterator cRoIt = ro.begin();
850 std::set<Pnode*>::iterator cRoItEnd = ro.end();
851 std::set<Idx>::iterator cSIt;
852 std::set<Idx>::iterator cSItEnd;
855 for(; cRoIt != cRoItEnd; ++cRoIt) {
857 std::ostringstream ostr;
862 cSIt=(*cRoIt)->states.begin();
863 cSItEnd=(*cRoIt)->states.end();
864 for(; cSIt != cSItEnd; ++cSIt) {
866 Idx st=states[*cSIt].idx;
869 rMapStateToPartition[st] = newstate;
872 if(gen->StateName(st)!=
"") ostr << gen->StateName(st) <<
",";
873 else ostr << st <<
",";
876 if(gen->ExistsInitState(st))
879 if(gen->ExistsMarkedState(st))
885 std::string statename = ostr.str();
886 if(statename.length()>=1) statename.erase(statename.length()-1);
887 statename =
"{" + statename +
"}";
896 for(; tIt != tItEnd; ++tIt) {
898 rGenPart.
SetTransition(rMapStateToPartition[tIt->X1], tIt->Ev,
899 rMapStateToPartition[tIt->X2]);
919 std::map<Idx,Idx>& rMapStateToPartition,
925 SOE soe =
SOE(rGenOrig, rConAlph, rLocAlph);
928 soe.
partition(rMapStateToPartition, rResGen);
#define FD_DF(message)
Debug: optional report on user functions.
Set of indices with symbolic names.
std::vector< Pnode * > W
W-tree contains all blocks ever created [required for destruction].
void partition(std::map< Idx, Idx > &rMapStateToPartition, Generator &rGenPart)
Extract output generator that represents the resulting quotient automaton.
const Generator * gen
keep a reference to automaton
Idx nxidx
Counter to assign a unique index to each node [debugging/cosmetic only].
std::set< Idx > locuncalph
std::set< Idx > shaconalph
std::vector< Idx > events
vector of all events [starting with 1]
std::set< Idx > shauncalph
void refine(void)
Perform fixpoint iteration to obtain the coarset synthesis-observation-equivalence.
std::set< Idx > uncalph
vorious eventsets of interest
std::set< Pnode * > ro
set of nodes that form current partition, i.e.
std::set< Idx > locconalph
std::set< Pnode * > roDividers
set of nodes that can possibly split classes in ro
std::vector< State > states
vector of all states [starting with 1]
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator on transition.
Base class of all FAUDES generators.
bool SetTransition(Idx x1, Idx ev, Idx x2)
Add a transition to generator by indices.
EventSet::Iterator AlphabetBegin(void) const
Iterator to Begin() of alphabet.
void SetInitState(Idx index)
Set an existing state as initial state by index.
std::string StateName(Idx index) const
State name lookup.
void Name(const std::string &rName)
Set the generator's name.
Idx InsState(void)
Add new anonymous state to generator.
void SetMarkedState(Idx index)
Set an existing state as marked state by index.
bool StateNamesEnabled(void) const
Whether libFAUEDS functions are requested to generate state names.
bool InsEvent(Idx index)
Add an existing event to alphabet by index.
virtual void Clear(void)
Clear generator data.
Iterator End(void) const
Iterator to the end of set.
Iterator Begin(void) const
Iterator to the begin of set.
void ComputeSynthObsEquiv(const Generator &rGenOrig, const EventSet &rConAlph, const EventSet &rLocAlph, std::map< Idx, Idx > &rMapStateToPartition, Generator &rResGen)
Synthesis-observation equivalence.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
std::set< Idx > states
Associated set of states.
a relation according to SOE in one block
internal representation of transition relation with consecutive indexed states and events
vector< vector< Idx > > shauncPre
vector< vector< Idx > > shauncPres
vector< vector< Idx > > suc
vector< Idx > locuncPres
Part 3:
vector< vector< Idx > > shaconPre
Part 2 (only via an transition)
vector< vector< Idx > > pre
Synthesis-observation equivalence.