54 std::vector<StateSet> subsets;
55 std::vector<Idx> newindices;
56 StateMin(rGen, rResGen, subsets, newindices);
62 std::vector<StateSet>& rSubsets, std::vector<Idx>& rNewIndices) {
63 FD_DF(
"StateMin: *** computing state space minimization of generator "
66 FD_DF(
"StateMin: making generator accessible");
68 if (rGen.
Size() == 0) {
69 FD_DF(
"StateMin: generator size 0. returning given generator");
73 if(rGen.
Size() == 1) {
74 FD_DF(
"StateMin: generator size 1. returning given generator");
76 rSubsets.push_back(rGen.
States() );
77 rNewIndices.push_back(*( rResGen.
States().
Begin() ) );
84 throw Exception(
"StateMin",
"input automaton nondeterministic", 101);
92 pResGen= pResGen->
New();
97 pResGen->
Name(rGen.
Name()+
" [minstate]");
101 std::vector<StateSet>& b = rSubsets;
104 std::set<Idx> active;
105 std::set<Idx>::iterator ait;
111 StateSet::Iterator sit;
119 notmarked.
Name(
"B[i]");
120 FD_DF(
"StateMin: new block B[" << i <<
"] = {" << notmarked.
ToString() <<
"}");
121 b.push_back(notmarked);
131 while (! active.empty()) {
132 FD_WPC(b.size()-active.size(), b.size(),
"StateMin: blocks/active: " << b.size() <<
" / " << active.size());
133 #ifdef FAUDES_DEBUG_FUNCTION
134 FD_DF(
"StateMin: while there is an active block B...");
135 std::set<Idx>::iterator _it1;
136 std::stringstream str;
137 for (_it1 = active.begin(); _it1 != active.end(); ++_it1) {
140 FD_DF(
"StateMin: active: "+str.str());
141 std::vector<StateSet>::iterator _it2;
144 for (_it2 = b.begin(); _it2 != b.end(); ++_it2) {
145 str <<
"{" << _it2->ToString() <<
"} "<<std::endl;
148 FD_DF(
"B: "+str.str());
151 i = *(active.begin());
153 active.erase(active.begin());
154 FD_DF(
"StateMin: getting active block B[" << i <<
"] = {" <<
155 b.at(i).ToString() <<
"}");
161 EventSet::Iterator eit;
166 for (sit = b_current.Begin(); sit != b_current.End(); ++sit) {
169 rtit_end = rtransrel.
EndByEvX2(*eit, *sit);
170 for (; rtit != rtit_end; ++rtit) {
175 if(c.
Empty())
continue;
177 FD_DF(
"StateMin: computed predecessor states C = {" << c.
ToString()
178 <<
"} for event " << rGen.
EventName(*eit));
180 for (j=0; j < b.size(); ++j) {
182 const StateSet& d_current = b.at(j);
183 FD_DF(
"StateMin: examining block B[" << j <<
"] = {" <<
189 if(d_.Empty() || (d_.Size()==d_current.
Size())) {
190 FD_DF(
"StateMin: -> no split");
193 FD_DF(
"StateMin: -> split:");
200 FD_DF(
"StateMin: new block B[" << j <<
"] = {" << d_.ToString() <<
"}");
201 FD_DF(
"StateMin: new block B[" << b.size()-1 <<
"] = {" << d__.
ToString() <<
"}");
203 if(active.find(j) != active.end()) {
204 active.insert((
Idx)b.size()- 1);
205 FD_DF(
"StateMin: mark active: " << b.size()-1);
209 if (d_.Size() < d__.
Size()) {
211 FD_DF(
"StateMin: mark active: " << j);
213 active.insert((
Idx)b.size()-1);
214 FD_DF(
"StateMin: mark active: " << b.size()-1);
221 FD_DF(
"StateMin: *** building minimized generator ***");
223 std::map<Idx,Idx> minstatemap;
226 for (i = 0; i < b.size(); ++i) {
229 rNewIndices.push_back(newstate);
230 FD_DF(
"StateMin: block {" << b.at(i).ToString()
231 <<
"} -> new state " << newstate);
232 std::ostringstream ostr;
233 for (sit = b.at(i).Begin(); sit != b.at(i).End(); ++sit) {
235 minstatemap[*sit] = newstate;
247 FD_DF(
"StateMin: -> initial state");
252 FD_DF(
"StatMmin: -> marked state");
256 std::string statename = ostr.str();
257 if(statename!=
"") statename.erase(statename.length()-1);
258 statename =
"{" + statename +
"}";
264 pResGen->
SetTransition(minstatemap[tit->X1], tit->Ev, minstatemap[tit->X2]);
265 FD_DF(
"statemin: adding transition: "
266 << minstatemap[tit->X1] <<
"-" << tit->Ev <<
"-"
267 << minstatemap[tit->X2]);
271 if(pResGen != &rResGen) {
272 pResGen->
Move(rResGen);