|
|
Go to the documentation of this file.
54 std::vector< std::vector<Idx> > pre;
62 std::string setstr( const std::set<Idx>& sset) {
63 std::set<Idx>::const_iterator ssit;
64 std::stringstream str;
66 for(ssit = sset.begin(); ssit != sset.end(); ++ssit)
75 std::string vecstr( const std::vector<Idx>& svec) {
76 std::vector<Idx>::const_iterator ssit;
77 std::stringstream str;
79 for(ssit = svec.begin(); ssit != svec.end(); ++ssit)
89 std::vector< std::vector<Idx> > blocks;
106 throw Exception( "StateMin", "input automaton non-deterministic", 101);
114 std::map<Idx,Idx> smap;
115 std::map<Idx,Idx> emap;
125 StateSet::Iterator sit=acc. Begin();
126 for(; sit != acc. End(); ++sit) {
133 if(!acc. Exists(tit->X1)) continue;
134 if(!acc. Exists(tit->X2)) continue;
135 states[smap[tit->X2]].pre[emap[tit->Ev]].push_back(smap[tit->X1]);
138 FD_DF( "Hopcroft::Initialize(): states #" << states.size()-1);
159 if( states.size()-1 == 0) {
160 FD_DF( "Hopcroft::Minimize(): generator size 0");
165 if( states.size()-1 == 1) {
166 FD_DF( "Hopcroft::Minimize(): generator size 1");
174 std::stack<Idx> active;
175 std::vector<Idx>::iterator ssit;
176 std::vector<Idx>::iterator ssit_end;
178 std::vector<Idx> dpp;
184 std::vector<Idx> bnm;
187 else bnm.push_back(q);
190 blocks.push_back(std::vector<Idx>());
192 active.push( blocks.size()-1);
193 FD_DF( "Hopcroft::Minimize(): initial partition not-marked #" << blocks.back().size());
196 blocks.push_back(std::vector<Idx>());
198 active.push( blocks.size()-1);
199 FD_DF( "Hopcroft::Minimize(): initial partition not-marked #" << blocks.back().size());
203 while(!active.empty()) {
204 FD_WPC( blocks.size()-active.size(), blocks.size(), "StateMin: blocks/active: " << blocks.size() << " / " << active.size());
205 FD_DF( "Hopcroft::Minimize(): active blocks #" << active.size());
208 std::vector<Idx> b_current( blocks.at(active.top()));
209 FD_DF( "StateMin: getting active block B[" << active.top() << "] = { #" << b_current.size() << "}");
214 for(; ev!= events.size(); ++ev){
217 ssit = b_current.begin();
218 ssit_end = b_current.end();
219 for(; ssit != ssit_end; ++ssit) {
221 std::vector<Idx>& preevx2= states[*ssit].pre[ev];
222 std::vector<Idx>::iterator rit = preevx2.begin();
223 std::vector<Idx>::iterator rit_end = preevx2.end();
224 for (; rit != rit_end; ++rit) c.push_back(*rit);
226 std::sort(c.begin(),c.end());
228 if(c.empty()) continue;
230 FD_DF( "StateMin: computed predecessor states C = {#" << c.size() << "} for event " << gen-> EventName( events[ev]));
234 const std::vector<Idx>& d_current = blocks[j];
236 if(d_current.size()==1) continue;
237 FD_DF( "StateMin: examining block D=B[" << j << "] = {#" << d_current.size() << "}");
240 std::set_intersection(d_current.begin(), d_current.end(), c.begin(), c.end(),
241 std::inserter(dp, dp.begin()));
243 if(dp.empty() || (dp.size()==d_current.size())) continue;
244 FD_DF( "StateMin: -> split:");
247 std::set_difference(d_current.begin(), d_current.end(), dp.begin(), dp.end(),
248 std::inserter(dpp,dpp.begin()));
250 if(dp.size() < dpp.size()) dp.swap(dpp);
254 blocks.push_back(std::vector<Idx>());
256 FD_DF( "StateMin: new block D' as B[" << j << "] = " << vecstr(dp));
257 FD_DF( "StateMin: new block D'' as B[" << blocks.size()-1 << "] = " << vecstr(dpp));
276 FD_DF( "Hopcroft:Partition: building minimized generator #" << blocks.size());
289 std::map<Idx,Idx> minstatemap;
295 FD_DF( "StateMin: block " << vecstr( blocks.at(i)) << " -> new state " << newstate);
296 std::ostringstream ostr;
297 std::vector<Idx>::iterator ssit = blocks[i].begin();
298 std::vector<Idx>::iterator ssit_end = blocks[i].end();
299 for(; ssit != ssit_end; ++ssit) {
302 minstatemap[orgstate] = newstate;
310 FD_DF( "StateMin: -> initial state");
315 FD_DF( "StateMmin: -> marked state");
319 std::string statename = ostr.str();
320 if(statename!= "") statename.erase(statename.length()-1);
321 statename = "{" + statename + "}";
328 std::map<Idx,Idx>::iterator xit1=minstatemap.find(tit->X1);
329 std::map<Idx,Idx>::iterator xit2=minstatemap.find(tit->X2);
330 if(xit1==minstatemap.end()) continue;
331 if(xit2==minstatemap.end()) continue;
336 if(pResGen != &rResGen) {
337 rResGen. Move(*pResGen);
350 void Partition(std::vector< StateSet >& rSubsets, std::vector<Idx>& rNewIndices){
352 FD_DF( "Hopcroft:Partition: returning blocks #" << blocks.size());
358 rNewIndices.push_back(newstate);
360 std::vector<Idx>::iterator ssit = blocks[i].begin();
361 std::vector<Idx>::iterator ssit_end = blocks[i].end();
363 for(; ssit != ssit_end; ++ssit) {
367 rSubsets.push_back(block);
389 std::vector<StateSet>& rSubsets, std::vector<Idx>& rNewIndices) {
390 FD_DF( "StateMin: *** computing state space minimization of generator "
393 FD_DF( "StateMin: restrict to accessible states");
397 if(acc. Size() == 0) {
398 FD_DF( "StateMin: generator size 0. returning given generator");
403 if(rGen. Size() == 1) {
404 FD_DF( "StateMin: generator size 1. returning given generator");
407 rSubsets.push_back(rResGen. States() );
408 rNewIndices.push_back(*( rResGen. States(). Begin() ) );
415 throw Exception( "StateMin", "input automaton nondeterministic", 101);
422 if(&rResGen==&rGen) {
423 pResGen= pResGen-> New();
428 pResGen-> Name(rGen. Name()+ " [minstate]");
432 std::vector<StateSet>& b = rSubsets;
435 std::set<Idx> active;
436 std::set<Idx>::iterator ait;
442 StateSet::Iterator sit;
449 if(marked. Size() > 0) {
450 FD_DF( "StateMin: new block B[" << i << "] = {" << marked. ToString() << "}");
455 if(notmarked. Size() > 0) {
456 notmarked. Name( "B[i]");
457 FD_DF( "StateMin: new block B[" << i << "] = {" << notmarked. ToString() << "}");
458 b.push_back(notmarked);
465 while(! active.empty()) {
466 FD_WPC(b.size()-active.size(), b.size(), "StateMin: blocks/active: " << b.size() << " / " << active.size());
467#ifdef FAUDES_DEBUG_FUNCTION
468 FD_DF( "StateMin: while there is an active block B...");
469 std::set<Idx>::iterator _it1;
470 std::stringstream str;
471 for (_it1 = active.begin(); _it1 != active.end(); ++_it1) {
474 FD_DF( "StateMin: active: "+str.str());
475 std::vector<StateSet>::iterator _it2;
478 for (_it2 = b.begin(); _it2 != b.end(); ++_it2) {
479 str << "{" << _it2->ToString() << "} "<<std::endl;
482 FD_DF( "B: "+str.str());
485 i = *(active.begin());
487 active.erase(active.begin());
488 FD_DF( "StateMin: getting active block B[" << i << "] = {" <<
489 b.at(i).ToString() << "}");
495 EventSet::Iterator eit;
500 for (sit = b_current. Begin(); sit != b_current. End(); ++sit) {
503 rtit_end = rtransrel. EndByEvX2(*eit, *sit);
504 for (; rtit != rtit_end; ++rtit) {
509 if(c. Empty()) continue;
511 FD_DF( "StateMin: computed predecessor states C = {" << c. ToString()
512 << "} for event " << rGen. EventName(*eit));
514 for (j=0; j < b.size(); ++j) {
516 const StateSet& d_current = b.at(j);
517 FD_DF( "StateMin: examining block B[" << j << "] = {" <<
524 FD_DF( "StateMin: -> no split");
527 FD_DF( "StateMin: -> split:");
534 FD_DF( "StateMin: new block B[" << j << "] = {" << d_. ToString() << "}");
535 FD_DF( "StateMin: new block B[" << b.size()-1 << "] = {" << d__. ToString() << "}");
537 if(active.find(j) != active.end()) {
538 active.insert(( Idx)b.size()- 1);
539 FD_DF( "StateMin: mark active: " << b.size()-1);
545 FD_DF( "StateMin: mark active: " << j);
547 active.insert(( Idx)b.size()-1);
548 FD_DF( "StateMin: mark active: " << b.size()-1);
555 FD_DF( "StateMin: *** building minimized generator ***");
557 std::map<Idx,Idx> minstatemap;
560 for (i = 0; i < b.size(); ++i) {
563 rNewIndices.push_back(newstate);
564 FD_DF( "StateMin: block {" << b.at(i).ToString()
565 << "} -> new state " << newstate);
566 std::ostringstream ostr;
567 for (sit = b.at(i).Begin(); sit != b.at(i).End(); ++sit) {
569 minstatemap[*sit] = newstate;
581 FD_DF( "StateMin: -> initial state");
586 FD_DF( "StatMmin: -> marked state");
590 std::string statename = ostr.str();
591 if(statename!= "") statename.erase(statename.length()-1);
592 statename = "{" + statename + "}";
598 if(!acc. Exists(tit->X1)) continue;
599 if(!acc. Exists(tit->X2)) continue;
600 pResGen-> SetTransition(minstatemap[tit->X1], tit->Ev, minstatemap[tit->X2]);
601 FD_DF( "statemin: adding transition: "
602 << minstatemap[tit->X1] << "-" << tit->Ev << "-"
603 << minstatemap[tit->X2]);
607 if(pResGen != &rResGen) {
608 rResGen. Move(*pResGen);
634 std::vector< StateSet >& rSubsets, std::vector<Idx>& rNewIndices){
#define FD_WPC(cntnow, contdone, message)
const std::string & Name(void) const
void Partition(std::vector< StateSet > &rSubsets, std::vector< Idx > &rNewIndices)
std::vector< Idx > events
std::vector< State > states
std::string vecstr(const std::vector< Idx > &svec)
void Partition(Generator &rResGen)
Hopcroft(const Generator &rGen)
std::string setstr(const std::set< Idx > &sset)
std::vector< std::vector< Idx > > blocks
Iterator EndByEvX2(Idx ev, Idx x2) const
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator BeginByEvX2(Idx ev, Idx x2) const
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
const TransSet & TransRel(void) const
bool SetTransition(Idx x1, Idx ev, Idx x2)
const StateSet & MarkedStates(void) const
const EventSet & Alphabet(void) const
TransSet::Iterator TransRelBegin(void) const
virtual void RestrictStates(const StateSet &rStates)
virtual vGenerator & Move(Type &rGen)
EventSet::Iterator AlphabetBegin(void) const
virtual vGenerator * New(void) const
void SetInitState(Idx index)
StateSet AccessibleSet(void) const
std::string StateName(Idx index) const
TransSet::Iterator TransRelEnd(void) const
bool IsDeterministic(void) const
void SetMarkedState(Idx index)
virtual void EventAttributes(const EventSet &rEventSet)
bool StateNamesEnabled(void) const
std::string EventName(Idx index) const
EventSet::Iterator AlphabetEnd(void) const
bool ExistsInitState(Idx index) const
bool ExistsMarkedState(Idx index) const
const StateSet & States(void) const
void InjectAlphabet(const EventSet &rNewalphabet)
bool Exists(const T &rElem) const
Iterator Begin(void) const
void StateMin(const Generator &rGen, Generator &rResGen)
void aStateMin(const Generator &rGen, Generator &rResGen)
void StateMin_org(const Generator &rGen, Generator &rResGen, std::vector< StateSet > &rSubsets, std::vector< Idx > &rNewIndices)
std::string ToStringInteger(Int number)
std::vector< std::vector< Idx > > pre
libFAUDES 2.34g
--- 2026.03.30
--- c++ api documentaion by doxygen
|