33 std::vector<StateSet> subsets;
34 std::vector<Idx> newindices;
40 std::vector<StateSet>& rSubsets, std::vector<Idx>& rNewIndices) {
41 FD_DF(
"statemin: *** computing state space minimization of multi-tasking generator "
43 FD_DF(
"statemin: making generator accessible");
44 #ifdef FAUDES_DEBUG_FUNCTION
45 FD_WARN(
"mtcStateMin: debug out")
46 rGen.
Write(
"tmp_smin_m.gen");
50 #ifdef FAUDES_DEBUG_FUNCTION
51 FD_WARN(
"mtcStateMin: debug out")
52 rGen.
Write(
"tmp_smin_a.gen");
56 if (rGen.
Size() < 2) {
57 FD_DF(
"statemin: generator size < 2. returning given generator");
60 rSubsets.push_back(rGen.
States() );
61 rNewIndices.push_back(*( rResGen.
States().Begin() ) );
67 throw Exception(
"mtcStateMin",
"input automaton nondeterministic", 505);
72 rResGen.
Name(rGen.
Name()+
" [mtc minstate]");
83 std::vector<StateSet>& b = rSubsets;
87 std::set<Idx>::iterator ait;
93 StateSet::Iterator lit;
99 #ifdef FAUDES_DEBUG_FUNCTION
100 FD_WARN(
"mtcStateMin: debug out: states");
102 FD_WARN(
"mtcStateMin: debug out: colored states");
104 FD_WARN(
"mtcStateMin: debug out: unolored states");
111 FD_DF(
"statemin: new block B[" << i-1 <<
"] = {" <<
116 std::map<Idx,ColorSet>::const_iterator sit_end = stateColorMap.end();
117 std::map<ColorSet,StateSet> SameColors;
118 std::map<ColorSet,StateSet>::iterator csit;
119 std::map<Idx,ColorSet>::const_iterator sit;
121 for(sit = stateColorMap.begin(); sit != sit_end; ++sit){
122 csit = SameColors.find(sit->second);
123 FD_DF(
"stateColorMap, state: " <<
ToStringInteger(sit->first) <<
", colors: " << (sit->second).ToString());
124 if(csit != SameColors.end() )
125 csit->second.Insert(sit->first);
128 NewStateSet.
Insert(sit->first);
129 SameColors[sit->second] = NewStateSet;
134 std::map<ColorSet,StateSet>::const_iterator csit_end = SameColors.end();
135 for(csit = SameColors.begin(); csit != csit_end; ++csit){
136 b.push_back(csit->second);
138 FD_DF(
"statemin: new block B[" << i-1 <<
"] = {" <<
139 csit->second.ToString() <<
"}");
143 while (! active.empty()) {
144 FD_WP(
"mtcStateMin: blocks/active: " << b.size() <<
" / " << active.size());
146 FD_DF(
"statemin: if there is an active block B...");
147 std::set<Idx>::iterator _it1;
148 std::stringstream str;
149 for (_it1 = active.begin(); _it1 != active.end(); ++_it1) {
152 FD_DF(
"active: "+str.str());
153 std::vector<StateSet>::iterator _it2;
155 for (_it2 = b.begin(); _it2 != b.end(); ++_it2) {
156 str <<
"{" << _it2->ToString() <<
"} ";
159 FD_DF(
"B: "+str.str());
162 i = *(active.begin());
164 active.erase(active.begin());
165 FD_DF(
"statemin: getting active block B[" << i <<
"] = {" <<
166 b.at(i).ToString() <<
"}");
172 EventSet::Iterator eit;
177 for (lit = b_current.
Begin(); lit != b_current.
End(); ++lit) {
180 rtit_end = rtransrel.
EndByEvX2(*eit, *lit);
181 for (; rtit != rtit_end; ++rtit) {
189 FD_DF(
"statemin: computed predecessor states C = {" << c.
ToString()
190 <<
"} for event " << rGen.
EventName(*eit));
193 for (j=0; j < b.size(); ++j) {
194 FD_DF(
"statemin: examining block B[" << j <<
"] = {" <<
195 b.at(j).ToString() <<
"}");
202 FD_DF(
"statemin: -> no split");
205 FD_DF(
"statemin: -> split:");
207 FD_DF(
"statemin: new block B[" << j <<
"] = {"
210 FD_DF(
"statemin: new block B[" << b.size()-1 <<
"] = {"
213 if (active.count(j) > 0) {
215 active.insert((
Idx)b.size()- 1);
216 FD_DF(
"statemin: mark active: " << b.size()-1);
222 FD_DF(
"statemin: mark active: " << j);
225 active.insert((
Idx)b.size()-1);
226 FD_DF(
"statemin: mark active: " << b.size()-1);
235 FD_DF(
"statemin: *** building minimized generator ***");
237 std::map<Idx,Idx> minstatemap;
240 for (i = 0; i < b.size(); i++) {
243 rNewIndices.push_back(newstate);
244 FD_DF(
"statemin: block {" << b.at(i).ToString()
245 <<
"} -> new state " << newstate);
246 std::ostringstream ostr;
248 for (lit = b.at(i).Begin(); lit != b.at(i).End(); lit++) {
251 minstatemap[*lit] = newstate;
256 FD_DF(
"StateName \"\", ostr = " << ostr.str());
260 FD_DF(
"StateName exists, ostr = " << ostr.str());
266 FD_DF(
"statemin: -> initial state");
269 std::map<Idx,ColorSet>::const_iterator col_it;
270 col_it = stateColorMap.find(*lit);
272 if (col_it != stateColorMap.end()) {
274 FD_DF(
"mtcStateMin: insert colors " << col_it->second.ToString() <<
" to state " << newstate);
275 rResGen.
InsColors(newstate, col_it->second);
280 std::string statename = ostr.str();
281 statename.erase(statename.length()-1);
282 statename =
"{" + statename +
"}";
283 FD_DF(
"Set state name: name: \"" << statename <<
"\", index: \"" << newstate <<
"\"");
289 rResGen.
SetTransition(minstatemap[tit->X1], tit->Ev, minstatemap[tit->X2]);
290 FD_DF(
"statemin: adding transition: "
291 << minstatemap[tit->X1] <<
"-" << tit->Ev <<
"-"
292 << minstatemap[tit->X2]);
294 #ifdef FAUDES_DEBUG_FUNCTION
295 FD_WARN(
"mtcStateMin: debug out: result")
296 rResGen.
Write(
"tmp_smin_r.gen");
305 FD_WARN(
"mtcStateMin: debug out")
Iterator EndByEvX2(Idx ev, Idx x2) const
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator BeginByEvX2(Idx ev, Idx x2) const
const TaStateSet< StateAttr > & States(void) const
const TaEventSet< EventAttr > & Alphabet(void) const
bool SetTransition(Idx x1, Idx ev, Idx x2)
const ATransSet & TransRel(void) const
void InjectAlphabet(const EventSet &rNewalphabet)
void ClrObservable(Idx index)
EventSet ControllableEvents(void) const
void SetControllable(Idx index)
EventSet ForcibleEvents(void) const
void SetForcible(Idx index)
EventSet UnobservableEvents(void) const
void InsColors(Idx stateIndex, const ColorSet &rColors)
StateSet ColoredStates(Idx colorIndex) const
virtual void DotWrite(const std::string &rFileName) const
void ClearStateAttributes()
std::map< Idx, ColorSet > StateColorMap(void) const
StateSet UncoloredStates() const
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
void Write(const Type *pContext=0) const
TransSet::Iterator TransRelBegin(void) const
EventSet::Iterator AlphabetBegin(void) const
void SetInitState(Idx index)
std::string StateName(Idx index) const
void Name(const std::string &rName)
TransSet::Iterator TransRelEnd(void) const
bool IsDeterministic(void) const
bool StateNamesEnabled(void) const
void GraphWrite(const std::string &rFileName, const std::string &rOutFormat="", const std::string &rDotExec="dot") const
std::string EventName(Idx index) const
EventSet::Iterator AlphabetEnd(void) const
bool ExistsInitState(Idx index) const
Iterator Begin(void) const
void mtcStateMin(MtcSystem &rGen, MtcSystem &rResGen)
std::string ToStringInteger(Int number)