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 );
#define FD_WARN(message)
Debug: always report warnings.
#define FD_DF(message)
Debug: optional report on user functions.
Container for colors: this is a NameSet with its own static symboltable.
Idx Insert(void)
Insert new index to set.
Set of indices with symbolic names.
bool Exists(const Idx &rIndex) const
Test existence of index.
bool Insert(const Transition &rTransition)
Add a Transition.
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator on transition.
Idx InsState(void)
Add new anonymous state to generator.
virtual void Clear(void)
Clear generator data.
const TaStateSet< StateAttr > & States(void) const
Return reference to state set.
const TaEventSet< EventAttr > & Alphabet(void) const
Return const reference to alphabet.
bool SetTransition(Idx x1, Idx ev, Idx x2)
Add a transition to generator by indices.
void InjectAlphabet(const EventSet &rNewalphabet)
Set mpAlphabet without consistency check.
void ClrObservable(Idx index)
Mark event unobservable (by index)
EventSet UncontrollableEvents(void) const
Get EventSet with uncontrollable events.
EventSet ControllableEvents(void) const
Get EventSet with controllable events.
void SetControllable(Idx index)
Mark event controllable (by index)
EventSet ForcibleEvents(void) const
Get EventSet with forcible events.
void SetForcible(Idx index)
Mark event forcible (by index)
EventSet UnobservableEvents(void) const
Get EventSet with unobservable events.
Allows to create colored marking generators (CMGs) as the common five tupel consisting of alphabet,...
void InsColors(Idx stateIndex, const ColorSet &rColors)
Insert multiple colors from a color set into an existing state.
void Colors(ColorSet &rColors) const
Insert all colors used in the generator to a given ColorSet.
bool StronglyTrim(void)
Make generator strongly trim.
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
StateSet::Iterator InitStatesBegin(void) const
Iterator to Begin() of mInitStates.
bool InitStatesEmpty(void) const
Check if set of initial states are empty.
const StateSet & InitStates(void) const
Const ref to initial states.
TransSet::Iterator TransRelBegin(void) const
Iterator to Begin() of transition relation.
void ClearStates(void)
Clear all states and transitions, maintain alphabet.
bool ExistsState(Idx index) const
Test existence of state in state set.
void Name(const std::string &rName)
Set the generator's name.
void DelStates(const StateSet &rDelStates)
Delete a set of states Cleans mpStates, mInitStates, mMarkedStates, mpTransrel, and mpStateSymboltabl...
TransSet::Iterator TransRelEnd(void) const
Iterator to End() of transition relation.
bool IsDeterministic(void) const
Check if generator is deterministic.
std::string EStr(Idx index) const
Pretty printable event name for index (eg for debugging).
bool Empty(void) const
Check if generator is empty (no states)
Idx InsInitState(void)
Create new anonymous state and set as initial state.
Idx Size(void) const
Get generator size (number of states)
std::string SStr(Idx index) const
Return pretty printable state name for index (eg for debugging)
bool Empty(void) const
Test whether if the TBaseSet is Empty.
bool Exists(const T &rElem) const
Test existence of element.
void mtcSupConNB(const MtcSystem &rPlantGen, const MtcSystem &rSpecGen, MtcSystem &rResGen)
Nonblocking Supremal Controllable Sublanguage (wrapper function)
void mtcSupConClosed(const MtcSystem &rPlantGen, const MtcSystem &rSpecGen, MtcSystem &rResGen)
Supremal Controllable Sublanguage (wrapper function)
Supremal controllable sublanguage and controllablity.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
void ComposedColorSet(const MtcSystem &rGen1, const Idx sidx1, ColorSet &rColors1, const MtcSystem &rGen2, const Idx sidx2, ColorSet &rColors2, ColorSet &composedSet)
Compose the color set for a state combined from two states in two distinct automata.
void mtcSupConUnchecked(const MtcSystem &rPlantGen, const EventSet &rCAlph, MtcSystem &rSpecGen)
Supremal Controllable Sublangauge (Real SupCon function; unchecked)
void mtcSupConParallel(const MtcSystem &rPlantGen, const MtcSystem &rSpecGen, const EventSet &rUAlph, std::map< std::pair< Idx, Idx >, Idx > &rReverseCompositionMap, MtcSystem &rResGen)
Fast parallel composition for computation for the mtcSupConNB.
std::string ToStringInteger(Int number)
integer to string
void TraverseUncontrollableBackwards(const EventSet &rCAlph, TransSetX2EvX1 &rtransrel, StateSet &rCriticalStates, Idx current)
Helper function for IsControllable.
Includes all header files of the synthesis plug-in.