43 std::map< std::pair<Idx,Idx>,
Idx> rcmap;
51 std::map< std::pair<Idx,Idx>,
Idx>& rCompositionMap,
MtcSystem& rResGen) {
52 FD_DF(
"mtcSupConNB(" << &rPlantGen <<
"," << &rSpecGen <<
")");
57 rResGen.
Name(
"mtcSupConNB(("+rPlantGen.
Name()+
"),("+rSpecGen.
Name()+
"))");
69 FD_DF(
"mtcSupConNB: uncontrollable events: " << ualph.
ToString());
77 std::stringstream errstr;
78 errstr <<
"Alphabets of generators do not match. Only in plant: " << only_in_plant.
ToString()
79 <<
". Only in spec: " << only_in_spec.
ToString() <<
".";
80 throw Exception(
"mtcSupConNB", errstr.str(), 500);
87 if ((plant_det ==
false) && (spec_det ==
true)) {
88 std::stringstream errstr;
89 errstr <<
"Plant generator must be deterministic, "
90 <<
"but is nondeterministic";
91 throw Exception(
"mtcSupConNB", errstr.str(), 501);
93 else if ((plant_det ==
true) && (spec_det ==
false)) {
94 std::stringstream errstr;
95 errstr <<
"Spec generator must be deterministic, "
96 <<
"but is nondeterministic";
97 throw Exception(
"mtcSupConNB", errstr.str(), 503);
99 else if ((plant_det ==
false) && (spec_det ==
false)) {
100 std::stringstream errstr;
101 errstr <<
"Plant and spec generator must be deterministic, "
102 <<
"but both are nondeterministic";
103 throw Exception(
"mtcSupConNB", errstr.str(), 504);
109 FD_DF(
"mtcSupConNB: mtcSupConParallel passed...");
113 if(rResGen.
Empty())
break;
114 Idx state_num = rResGen.
Size();
117 if(rResGen.
Size() == state_num)
break;
122 std::map< std::pair<Idx,Idx>,
Idx>::iterator rcmapit = rCompositionMap.begin();
123 for(; rcmapit != rCompositionMap.end(); rcmapit++)
124 if(!rResGen.
ExistsState(rcmapit->second)) rCompositionMap.erase(rcmapit++);
132 std::map< std::pair<Idx,Idx>,
Idx> rcmap;
141 std::map< std::pair<Idx,Idx>,
Idx>& rCompositionMap,
MtcSystem& rResGen) {
142 FD_DF(
"mtcSupConClosed(" << &rPlantGen <<
"," << &rSpecGen <<
")");
146 rResGen.
Name(
"mtcSupConClosed(("+rPlantGen.
Name()+
"),("+rSpecGen.
Name()+
"))");
159 FD_DF(
"mtcSupConClosed: uncontrollable events: " << ualph.
ToString());
167 std::stringstream errstr;
168 errstr <<
"Alphabets of generators do not match. Only in plant: "
169 << only_in_plant.
ToString() <<
". Only in spec: "
171 throw Exception(
"mtcSupConClosed", errstr.str(), 500);
178 if ((plant_det ==
false) && (spec_det ==
true)) {
179 std::stringstream errstr;
180 errstr <<
"Plant generator must be deterministic, " <<
"but is nondeterministic";
181 throw Exception(
"mtcSupConClosed", errstr.str(), 501);
183 else if ((plant_det ==
true) && (spec_det ==
false)) {
184 std::stringstream errstr;
185 errstr <<
"Spec generator must be deterministic, " <<
"but is nondeterministic";
186 throw Exception(
"mtcSupConClosed", errstr.str(), 503);
188 else if ((plant_det ==
false) && (spec_det ==
false)) {
189 std::stringstream errstr;
190 errstr <<
"Plant and spec generator must be deterministic, "
191 <<
"but both are nondeterministic";
192 throw Exception(
"mtcSupCon", errstr.str(), 504);
203 std::map< std::pair<Idx,Idx>,
Idx>::iterator rcmapit = rCompositionMap.begin();
204 for(; rcmapit != rCompositionMap.end(); rcmapit++)
205 if(!rResGen.
ExistsState(rcmapit->second)) rCompositionMap.erase(rcmapit++);
221 std::map< std::pair<Idx,Idx>,
Idx>& rReverseCompositionMap,
MtcSystem& rResGen) {
222 FD_DF(
"mtcSupConParallel(" << &rPlantGen <<
"," << &rSpecGen <<
")");
227 std::stack< std::pair<Idx,Idx> > todo;
231 std::pair<Idx,Idx> currentstates, newstates;
234 std::map< std::pair<Idx,Idx>,
Idx>::iterator rcmapit;
235 StateSet::Iterator lit1, lit2;
243 FD_DF(
"SupconParallel: plant got no initial states. "
244 <<
"parallel composition contains empty language.");
249 FD_DF(
"mtcSupConParallel: spec got no initial states. "
250 <<
"parallel composition contains empty language.");
257 todo.push(currentstates);
259 ComposedColorSet(rPlantGen, currentstates.first, plantColors, rSpecGen, currentstates.second,
260 specColors, ComposedSet);
261 if (! ComposedSet.
Empty() ) {
263 rReverseCompositionMap[currentstates] = StateIndex;
264 rResGen.
InsColors(StateIndex, ComposedSet);
265 FD_DF(
"mtcSupConParallel: NEW IMSTATE: (" << rPlantGen.
SStr(currentstates.first)
266 <<
"|" << rSpecGen.
SStr(currentstates.second) <<
") -> " << rReverseCompositionMap[currentstates]);
269 rReverseCompositionMap[currentstates] = rResGen.
InsInitState();
270 FD_DF(
"mtcSupConParallel: NEW ISTATE: (" << rPlantGen.
SStr(currentstates.first)
271 <<
"|" << rSpecGen.
SStr(currentstates.second) <<
") -> " << rReverseCompositionMap[currentstates]);
277 FD_DF(
"mtcSupConParallel: *** processing reachable states ***");
278 while (! todo.empty()) {
280 currentstates = todo.top();
282 FD_DF(
"mtcSupConParallel: todo pop: (" << rPlantGen.
SStr(currentstates.first)
283 <<
"|" << rSpecGen.
SStr(currentstates.second) <<
") -> " << rReverseCompositionMap[currentstates]);
286 titg_end = rPlantGen.
TransRelEnd(currentstates.first);
288 tith_end = rSpecGen.
TransRelEnd(currentstates.second);
290 #ifdef FAUDES_DEBUG_FUNCTION
292 FD_DF(
"mtcSupConParallel: transitions from current states:");
293 for (;titg != titg_end; ++titg) {
294 FD_DF(
"mtcSupConParallel: g: " << rPlantGen.
SStr(titg->X1) <<
"-" << rPlantGen.
EStr(titg->Ev)
295 <<
"-" << rPlantGen.
SStr(titg->X2));
297 for (;tith != tith_end; ++tith) {
298 FD_DF(
"mtcSupConParallel: h: " << rSpecGen.
SStr(tith->X1) <<
"-" << rSpecGen.
EStr(tith->Ev)
299 <<
"-" << rSpecGen.
SStr(tith->X2));
305 while ((tith != tith_end) && (titg != titg_end)) {
306 FD_DF(
"mtcSupConParallel: actual g-transition: " << rPlantGen.
SStr(titg->X1)
307 <<
"-" << rPlantGen.
EStr(titg->Ev) <<
"-" << rPlantGen.
SStr(titg->X2));
308 FD_DF(
"mtcSupConParallel: actual h-transition: " << rSpecGen.
SStr(tith->X1)
309 <<
"-" << rSpecGen.
EStr(tith->Ev) <<
"-" << rSpecGen.
SStr(tith->X2));
311 if (titg->Ev == tith->Ev) {
312 FD_DF(
"mtcSupConParallel: executing common event "
313 << rPlantGen.
EStr(titg->Ev));
314 newstates = std::make_pair(titg->X2, tith->X2);
315 rcmapit = rReverseCompositionMap.find(newstates);
317 if (rcmapit == rReverseCompositionMap.end()) {
318 todo.push(newstates);
320 ComposedColorSet(rPlantGen, newstates.first, plantColors, rSpecGen, newstates.second,
321 specColors, ComposedSet);
322 if(!ComposedSet.
Empty() ) {
324 rResGen.
InsColors(tmpstate, ComposedSet);
325 FD_DF(
"mtcSupConParallel: NEW MSTATE: ("
326 << rPlantGen.
SStr(newstates.first) <<
"|"
327 << rSpecGen.
SStr(newstates.second) <<
") -> " << tmpstate);
332 FD_DF(
"mtcSupConParallel: NEW STATE: ("
333 << rPlantGen.
SStr(newstates.first) <<
"|"
334 << rSpecGen.
SStr(newstates.second) <<
") -> " << tmpstate);
336 rReverseCompositionMap[newstates] = tmpstate;
337 FD_DF(
"mtcSupConParallel: todo push: (" << rPlantGen.
SStr(newstates.first)
338 <<
"|" << rSpecGen.
SStr(newstates.second) <<
") -> " << tmpstate);
342 tmpstate = rcmapit->second;
345 if (! forbidden.
Exists(tmpstate)) {
346 FD_DF(
"mtcSupConParallel: ADDING TRANSITION "
347 << rPlantGen.
SStr(rReverseCompositionMap[currentstates]) <<
"-" << rPlantGen.
EStr(titg->Ev)
348 <<
"-" << rPlantGen.
SStr(tmpstate));
349 rResGen.
SetTransition(rReverseCompositionMap[currentstates], titg->Ev, tmpstate);
350 FD_DF(
"mtcSupConParallel: incrementing g transrel");
352 FD_DF(
"mtcSupConParallel: incrementing h transrel");
357 else if (rUAlph.
Exists(titg->Ev)) {
358 FD_DF(
"mtcSupConParallel: successor " << rSpecGen.
SStr(tmpstate)
359 <<
"in forbidden and common event " << rSpecGen.
EStr(titg->Ev)
360 <<
" uncontrollable:");
361 FD_DF(
"mtcSupConParallel: forbidden insert" << rPlantGen.
SStr(tmpstate));
362 forbidden.
Insert(tmpstate);
363 #ifdef FAUDES_CHECKED
366 FD_DF(
"mtcSupConParallel: incrementing g transrel (FAUDES_CHECKED)");
368 FD_DF(
"mtcSupConParallel: incrementing h transrel (FAUDES_CHECKED)");
378 FD_DF(
"mtcSupConParallel: incrementing g transrel");
380 FD_DF(
"mtcSupConParallel: incrementing h transrel");
385 else if (titg->Ev < tith->Ev) {
386 FD_DF(
"mtcSupConParallel: asynchronous execution of event "
387 << rPlantGen.
EStr(titg->Ev) <<
" in g while " << rSpecGen.
EStr(tith->Ev)
391 if (rUAlph.
Exists(titg->Ev)) {
392 FD_DF(
"mtcSupConParallel: asynchronous event " << rPlantGen.
EStr(titg->Ev)
393 <<
" in g is uncontrollable");
394 tmpstate = rReverseCompositionMap[currentstates];
395 FD_DF(
"mtcSupConParallel: forbidden insert" << rPlantGen.
SStr(tmpstate));
396 forbidden.
Insert(tmpstate);
402 FD_DF(
"mtcSupConParallel: incrementing g transrel");
406 #ifdef FAUDES_CHECKED
411 FD_DF(
"mtcSupConParallel: incrementing h transrel");
416 FD_DF(
"mtcSupConParallel: rResGen has no initial states... (2)");
420 while (titg != titg_end) {
421 FD_DF(
"mtcSupConParallel: asynchronous execution of event "
422 << rPlantGen.
EStr(titg->Ev) <<
" in g at end of h");
423 FD_DF(
"mtcSupConParallel: actual g-transition: " << rPlantGen.
SStr(titg->X1)
424 <<
"-" << rPlantGen.
EStr(titg->Ev) <<
"-" << rPlantGen.
SStr(titg->X2));
425 FD_DF(
"mtcSupConParallel: actual h-transition: end");
427 if (rUAlph.
Exists(titg->Ev)) {
428 tmpstate = rReverseCompositionMap[currentstates];
429 FD_DF(
"mtcSupConParallel: asynchron executed uncontrollable end "
430 <<
"event " << rPlantGen.
EStr(titg->Ev) <<
" leaves specification:");
431 FD_DF(
"mtcSupConParallel: forbidden insert" << rPlantGen.
SStr(tmpstate));
432 forbidden.
Insert(tmpstate);
437 FD_DF(
"mtcSupConParallel: incrementing g transrel");
440 #ifdef FAUDES_CHECKED
451 FD_DF(
"mtcSupConParallel: deleting forbidden states...");
466 FD_DF(
"mtcSupConUnchecked(" << &rSpecGen <<
"," << &rPlantGen <<
")");
473 std::stack<Idx> todog, todoh;
492 while (! todog.empty()) {
494 Idx currentg = todog.top();
495 Idx currenth = todoh.top();
498 FD_DF(
"mtcSupCon: todo pop: (" << rPlantGen.
SStr(currentg) <<
"|"
499 << rSpecGen.
SStr(currenth) <<
")");
501 #ifdef FAUDES_DEBUG_FUNCTION
504 FD_DF(
"mtcSupCon: transitions from current states:");
506 FD_DF(
"mtcSupCon: g: " << rPlantGen.
SStr(_titg->X1) <<
"-"
507 << rPlantGen.
EStr(_titg->Ev) <<
"-" << rPlantGen.
SStr(_titg->X2));
509 FD_DF(
"mtcSupCon: h: " << rSpecGen.
SStr(_tith->X1) <<
"-"
510 << rSpecGen.
EStr(_tith->Ev) <<
"-" << rSpecGen.
SStr(_tith->X2));
518 while ((tith != tith_end) && (titg != titg_end)) {
519 FD_DF(
"mtcSupCon: actual g-transition: " << rPlantGen.
SStr(titg->X1)
520 <<
"-" << rPlantGen.
EStr(titg->Ev) <<
"-" << rPlantGen.
SStr(titg->X2));
521 FD_DF(
"mtcSupCon: actual h-transition: " << rSpecGen.
SStr(tith->X1)
522 <<
"-" << rSpecGen.
EStr(tith->Ev) <<
"-" << rSpecGen.
SStr(tith->X2));
524 if (titg->Ev == tith->Ev) {
525 FD_DF(
"mtcSupCon: executing common event " << rPlantGen.
EStr(titg->Ev));
527 if (! discovered.
Exists(currenth)) {
528 todog.push(titg->X2);
529 todoh.push(tith->X2);
530 FD_DF(
"mtcSupCon: todo push: (" << rPlantGen.
SStr(titg->X2) <<
"|"
531 << rSpecGen.
SStr(tith->X2) <<
")");
534 if (! forbidden.
Exists(tith->X2)) {
536 FD_DF(
"mtcSupCon: incrementing g transrel");
538 FD_DF(
"mtcSupCon: incrementing h transrel");
542 else if (!rCAlph.
Exists(titg->Ev)) {
543 FD_DF(
"mtcSupCon: successor state " << rSpecGen.
SStr(tith->X2) <<
544 " forbidden and event " << rPlantGen.
EStr(titg->Ev) <<
" uncontrollable:");
545 FD_DF(
"mtcSupCon: TraverseUncontrollableBackwards(" << rSpecGen.
SStr(currenth) <<
")");
547 #ifdef FAUDES_CHECKED
549 FD_DF(
"mtcSupCon: incrementing g transrel (FAUDES_CHECKED)");
551 FD_DF(
"mtcSupCon: incrementing h transrel (FAUDES_CHECKED)");
562 FD_DF(
"mtcSupCon: incrementing g transrel");
564 FD_DF(
"mtcSupCon: incrementing h transrel");
569 else if (titg->Ev < tith->Ev) {
570 FD_DF(
"mtcSupCon: asynchronous execution of event "
571 << rPlantGen.
EStr(titg->Ev) <<
" in g while " << rSpecGen.
EStr(tith->Ev)
575 if (!rCAlph.
Exists(titg->Ev)) {
576 FD_DF(
"mtcSupCon: asynchronous event " << rPlantGen.
EStr(titg->Ev)
577 <<
" in g is uncontrollable");
578 FD_DF(
"mtcSupCon: TraverseUncontrollableBackwards(" << rSpecGen.
SStr(currenth) <<
")");
584 FD_DF(
"mtcSupCon: incrementing g transrel");
589 #ifdef FAUDES_CHECKED
590 FD_WARN(
"mtcSupCon: transition " << rSpecGen.
SStr(tith->X1) <<
"-"
591 << rSpecGen.
EStr(tith->Ev) <<
"-" << rSpecGen.
SStr(tith->X2)
592 <<
"in specification h not found in g");
594 FD_DF(
"mtcSupCon: incrementing h transrel");
599 while (titg != titg_end) {
600 FD_DF(
"mtcSupCon: asynchronous execution of event "
601 << rPlantGen.
EStr(titg->Ev) <<
" in g at end of h");
602 FD_DF(
"mtcSupCon: actual g-transition: " << rPlantGen.
SStr(titg->X1)
603 <<
"-" << rPlantGen.
EStr(titg->Ev) <<
"-" << rPlantGen.
SStr(titg->X2));
604 FD_DF(
"mtcSupCon: actual h-transition: end");
606 if (!rCAlph.
Exists(titg->Ev)) {
607 FD_DF(
"mtcSupCon: asynchronous execution of uncontrollable event "
608 << rPlantGen.
EStr(titg->Ev) <<
" in g");
609 FD_DF(
"mtcSupCon: TraverseUncontrollableBackwards(" << rPlantGen.
SStr(currenth) <<
")");
614 FD_DF(
"mtcSupCon: incrementing g transrel");
617 #ifdef FAUDES_CHECKED
619 while (tith != tith_end) {
620 FD_WARN(
"mtcSupCon: transition " << rSpecGen.
SStr(tith->X1) <<
"-"
621 << rSpecGen.
EStr(tith->Ev) <<
"-" << rSpecGen.
SStr(tith->X2)
622 <<
"in specification h not found in g");
623 FD_DF(
"mtcSupCon: incrementing h transrel");
627 discovered.
Insert(currenth);
631 forbidden = rSpecGen.
States() - ( discovered - forbidden );
bool Exists(const Idx &rIndex) const
bool Insert(const Transition &rTransition)
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
const TaStateSet< StateAttr > & States(void) const
const TaEventSet< EventAttr > & Alphabet(void) const
bool SetTransition(Idx x1, Idx ev, Idx x2)
void InjectAlphabet(const EventSet &rNewalphabet)
void ClrObservable(Idx index)
EventSet UncontrollableEvents(void) const
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)
void Colors(ColorSet &rColors) const
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
StateSet::Iterator InitStatesBegin(void) const
bool InitStatesEmpty(void) const
const StateSet & InitStates(void) const
TransSet::Iterator TransRelBegin(void) const
bool ExistsState(Idx index) const
void Name(const std::string &rName)
void DelStates(const StateSet &rDelStates)
TransSet::Iterator TransRelEnd(void) const
bool IsDeterministic(void) const
std::string EStr(Idx index) const
std::string SStr(Idx index) const
bool Exists(const T &rElem) const
void mtcSupConNB(const MtcSystem &rPlantGen, const MtcSystem &rSpecGen, MtcSystem &rResGen)
void mtcSupConClosed(const MtcSystem &rPlantGen, const MtcSystem &rSpecGen, MtcSystem &rResGen)
void mtcSupConParallel(const MtcSystem &rPlantGen, const MtcSystem &rSpecGen, const EventSet &rUAlph, std::map< std::pair< Idx, Idx >, Idx > &rReverseCompositionMap, MtcSystem &rResGen)
std::string ToStringInteger(Int number)
void TraverseUncontrollableBackwards(const EventSet &rCAlph, TransSetX2EvX1 &rtransrel, StateSet &rCriticalStates, Idx current)
void ComposedColorSet(const MtcSystem &rGen1, const Idx sidx1, ColorSet &rColors1, const MtcSystem &rGen2, const Idx sidx2, ColorSet &rColors2, ColorSet &composedSet)
void mtcSupConUnchecked(const MtcSystem &rPlantGen, const EventSet &rCAlph, MtcSystem &rSpecGen)