47 std::stringstream errstr;
48 errstr <<
"Alphabets of generators do not match.";
49 throw Exception(
"IsRelativelyMarked", errstr.str(), 100);
55 std::stringstream errstr;
56 errstr <<
"Arguments are expected to be nonblocking.";
57 throw Exception(
"IsRelativelyMarked", errstr.str(), 201);
64 std::stringstream errstr;
65 errstr <<
"Arguments are expected to be deterministic.";
66 throw Exception(
"IsRelativelyMarked", errstr.str(), 202);
71 std::map< std::pair<Idx,Idx> ,
Idx> revmap;
74 Product(rGenPlant,rGenCand,revmap,product);
77 std::map< std::pair<Idx,Idx> ,
Idx>::iterator rit;
78 for(rit=revmap.begin(); rit!=revmap.end(); ++rit) {
90 return rit==revmap.end();
99 FD_DF(
"IsRelativelyPrefixClosed(\"" << rGenPlant.
Name() <<
"\", \"" << rGenCand.
Name() <<
"\")");
103 std::stringstream errstr;
104 errstr <<
"Alphabets of generators do not match.";
105 throw Exception(
"IsRelativelyPrefixClosed", errstr.str(), 100);
108 #ifdef FAUDES_CHECKED
111 std::stringstream errstr;
112 errstr <<
"Arguments are expected to be nonblocking.";
113 throw Exception(
"IsRelativelyPrefixClosed", errstr.str(), 201);
117 #ifdef FAUDES_CHECKED
120 std::stringstream errstr;
121 errstr <<
"Arguments are expected to be deterministic.";
122 throw Exception(
"IsRelativelyPrefixClosed", errstr.str(), 202);
127 FD_DF(
"IsRelativelyPrefixClosed(..): perform product");
130 std::stack< std::pair<Idx,Idx> > todo;
132 std::pair<Idx,Idx> currentstates, newstates;
134 std::set< std::pair<Idx,Idx> > productstates;
136 StateSet::Iterator lit1, lit2;
138 std::set< std::pair<Idx,Idx> >::iterator rcit;
140 bool inclusion12=
true;
143 FD_DF(
"IsRelativelyPrefixClosed(..): perform product: adding all combinations of initial states to todo");
148 currentstates = std::make_pair(*lit1, *lit2);
149 todo.push(currentstates);
150 productstates.insert(currentstates);
151 FD_DF(
"IsRelativelyPrefixClosed(..): perform product: (" <<
152 *lit1 <<
"|" << *lit2 <<
")");
157 FD_DF(
"IsRelativelyPrefixClosed(..): perform product: Product: processing reachable states:");
158 while (! todo.empty() && inclusion12) {
162 currentstates = todo.top();
164 FD_DF(
"Processing (" << currentstates.first <<
"|"
165 << currentstates.second <<
")");
168 tit1_end = rGenCand.
TransRelEnd(currentstates.first);
170 tit2_end = rGenPlant.
TransRelEnd(currentstates.second);
172 bool resolved12=
true;
173 while((tit1 != tit1_end) && (tit2 != tit2_end)) {
175 if(tit1->Ev != curev1) {
176 if(!resolved12) inclusion12=
false;
181 if(tit1->Ev == tit2->Ev) {
183 newstates = std::make_pair(tit1->X2, tit2->X2);
185 rcit = productstates.find(newstates);
186 if(rcit == productstates.end()) {
187 todo.push(newstates);
188 productstates.insert(newstates);
189 FD_DF(
"Product: todo push: (" << newstates.first <<
"|"
190 << newstates.second <<
")");
196 else if (tit1->Ev < tit2->Ev) {
200 else if (tit1->Ev > tit2->Ev) {
205 if(!resolved12) inclusion12=
false;
208 #ifdef FAUDES_DEBUG_FUNCTION
209 FD_DF(
"IsRelativelyClosed(): Product: done");
211 FD_DF(
"IsRelativelyClosed(): Product: inclusion L(G1) <= L(G2) not satisfied");
216 if(!inclusion12)
return false;
219 std::set< std::pair<Idx,Idx> >::iterator rit;
220 for(rit=productstates.begin(); rit!=productstates.end(); ++rit) {
234 return rit==productstates.end();
250 only_in_plant.
Name(
"Only_In_Plant");
251 only_in_spec.
Name(
"Only_In_Specification");
252 std::stringstream errstr;
253 errstr <<
"Alphabets of generators do not match.";
254 if(!only_in_plant.
Empty())
255 errstr <<
" " << only_in_plant.
ToString() <<
".";
256 if(!only_in_spec.
Empty())
257 errstr <<
" " << only_in_spec.
ToString() <<
".";
258 throw Exception(
"SupCon/SupConNB", errstr.str(), 100);
264 if ((plant_det ==
false) && (spec_det ==
true)) {
265 std::stringstream errstr;
266 errstr <<
"Plant generator must be deterministic, "
267 <<
"but is nondeterministic";
268 throw Exception(
"ControllableConsistencyCheck", errstr.str(), 201);
270 else if ((plant_det ==
true) && (spec_det ==
false)) {
271 std::stringstream errstr;
272 errstr <<
"Spec generator must be deterministic, "
273 <<
"but is nondeterministic";
274 throw Exception(
"ControllableConsistencyCheck", errstr.str(), 203);
276 else if ((plant_det ==
false) && (spec_det ==
false)) {
277 std::stringstream errstr;
278 errstr <<
"Plant and spec generator must be deterministic, "
279 <<
"but both are nondeterministic";
280 throw Exception(
"ControllableConsistencyCheck", errstr.str(), 204);
284 std::map< std::pair<Idx,Idx>,
Idx> rcmap;
295 std::map< std::pair<Idx,Idx>,
Idx>& rCompositionMap,
298 FD_DF(
"SupRelativelyPrefixClosed(" << &rPlantGen <<
"," << &rSpecGen <<
")");
302 if(&rResGen== &rPlantGen || &rResGen== &rSpecGen) {
303 pResGen= rResGen.
New();
312 Product(rPlantGen, rSpecGen, rCompositionMap, pmarked, smarked, *pResGen);
318 if(!pmarked.
Exists(s))
continue;
319 if(smarked.
Exists(s))
continue;
325 if(pResGen != &rResGen) {
326 pResGen->
Move(rResGen);
337 FD_DF(
"IsRelativelyOmegaMarked(\"" << rGenPlant.
Name() <<
"\", \"" << rGenCand.
Name() <<
"\")");
341 std::stringstream errstr;
342 errstr <<
"Alphabets of generators do not match.";
343 throw Exception(
"RelativelyOmegaMarked", errstr.str(), 100);
346 #ifdef FAUDES_CHECKED
349 std::stringstream errstr;
350 errstr <<
"Arguments are expected to be nonblocking.";
351 throw Exception(
"IsRelativelyOmegaMarked", errstr.str(), 201);
355 #ifdef FAUDES_CHECKED
358 std::stringstream errstr;
359 errstr <<
"Arguments are expected to be deterministic.";
360 throw Exception(
"IsRelativelyOmegaMarked", errstr.str(), 202);
366 std::map< std::pair<Idx,Idx> ,
Idx> revmap;
371 Product(rGenPlant,rGenCand,revmap,markPlant,markCand,product);
376 std::list<StateSet> umsccs;
381 std::list<StateSet>::iterator ssit=umsccs.begin();
382 for(;ssit!=umsccs.end(); ++ssit) {
383 FD_DF(
"IsRelativelyOmegaMarked(): GPlant-marked scc without GCand-mark: " << ssit->ToString());
387 return umsccs.size()==0;
399 FD_DF(
"IsRelativelyOmegaClosed(\"" << rGenPlant.
Name() <<
"\", \"" << rGenCand.
Name() <<
"\")");
403 std::stringstream errstr;
404 errstr <<
"Alphabets of generators do not match.";
405 throw Exception(
"RelativelyOmegaClosed", errstr.str(), 100);
408 #ifdef FAUDES_CHECKED
411 std::stringstream errstr;
412 errstr <<
"Argument \"" << rGenCand.
Name() <<
"\" is not omegatrim.";
413 throw Exception(
"IsRelativelyOmegaClosed", errstr.str(), 201);
416 std::stringstream errstr;
417 errstr <<
"Argument \"" << rGenPlant.
Name() <<
"\" is not omega-trim.";
418 throw Exception(
"IsRelativelyOmegaClosed", errstr.str(), 201);
425 if(rGenCand.
Empty()) {
426 FD_DF(
"IsRelativelyOmegaClosed(..): empty candidate: pass");
432 if(rGenPlant.
Empty()) {
433 FD_DF(
"IsRelativelyOmegaClosed(..): non-empty candidate. empty plant: fail");
437 #ifdef FAUDES_CHECKED
440 std::stringstream errstr;
441 errstr <<
"Arguments are expected to be deterministic.";
442 throw Exception(
"IsRelativelyOmegaClosed", errstr.str(), 202);
455 std::map< std::pair<Idx,Idx> ,
Idx> revmap;
465 std::stack< std::pair<Idx,Idx> > todo;
467 std::pair<Idx,Idx> currentstates, newstates;
471 StateSet::Iterator lit1, lit2;
473 std::map< std::pair<Idx,Idx>,
Idx>::iterator rcit;
475 bool inclusion12=
true;
478 FD_DF(
"IsRelativelyOmegaClosed(): Product composition A");
483 currentstates = std::make_pair(*lit1, *lit2);
484 todo.push(currentstates);
486 revmap[currentstates] = tmpstate;
487 FD_DF(
"IsRelativelyOmegaClosed(): Product composition A: (" << *lit1 <<
"|" << *lit2 <<
") -> "
488 << revmap[currentstates]);
493 while (! todo.empty() && inclusion12) {
497 currentstates = todo.top();
499 FD_DF(
"IsRelativelyOmegaClosed(): Product composition B: (" << currentstates.first <<
"|"
500 << currentstates.second <<
") -> " << revmap[currentstates]);
503 tit1_end = rGenCand.
TransRelEnd(currentstates.first);
505 tit2_end = rGenPlant.
TransRelEnd(currentstates.second);
507 bool resolved12=
true;
508 while((tit1 != tit1_end) && (tit2 != tit2_end)) {
510 if(tit1->Ev != curev1) {
511 if(!resolved12) inclusion12=
false;
516 if (tit1->Ev == tit2->Ev) {
518 newstates = std::make_pair(tit1->X2, tit2->X2);
520 rcit = revmap.find(newstates);
521 if (rcit == revmap.end()) {
522 todo.push(newstates);
524 revmap[newstates] = tmpstate;
525 FD_DF(
"IsRelativelyOmegaClosed(): Product composition C: (" << newstates.first <<
"|"
526 << newstates.second <<
") -> " << revmap[newstates]);
529 tmpstate = rcit->second;
531 product.
SetTransition(revmap[currentstates], tit1->Ev, tmpstate);
536 else if (tit1->Ev < tit2->Ev) {
540 else if (tit1->Ev > tit2->Ev) {
545 if(!resolved12) inclusion12=
false;
548 #ifdef FAUDES_DEBUG_FUNCTION
549 FD_DF(
"IsRelativelyOmegaClosed(): Product: done");
551 FD_DF(
"IsRelativelyOmegaClosed(): Product: inclusion L(G1) <= L(G2) not satisfied");
556 if(!inclusion12)
return false;
559 std::map< std::pair<Idx,Idx>,
Idx>::iterator rit;
560 for(rit=revmap.begin(); rit!=revmap.end(); ++rit){
568 std::list<StateSet> umsccs12;
570 ComputeScc(product,umfilter12,umsccs12,umroots12);
573 std::list<StateSet>::iterator ssit=umsccs12.begin();
574 for(;ssit!=umsccs12.end(); ++ssit) {
575 FD_DF(
"IsRelativelyOmegaClosed(): G2-marked scc without G1-mark: " << ssit->ToString());
579 if(umsccs12.size()!=0)
return false;
584 std::list<StateSet> umsccs21;
586 ComputeScc(product,umfilter21,umsccs21,umroots21);
589 ssit=umsccs21.begin();
590 for(;ssit!=umsccs21.end(); ++ssit) {
591 FD_DF(
"IsRelativelyOmegaClosed(): G1-marked scc without G2-mark: " << ssit->ToString());
595 if(umsccs21.size()!=0)
return false;
598 FD_DF(
"IsRelativelyOmegaClosed(): pass");
#define FD_DF(message)
Debug: optional report on user functions.
Idx Insert(void)
Insert new index to set.
Set of indices with symbolic names.
Filter for strictly connected components (SCC) search/compute routines.
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator on transition.
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
Base class of all FAUDES generators.
StateSet::Iterator StatesBegin(void) const
Iterator to Begin() of state set.
StateSet::Iterator InitStatesBegin(void) const
Iterator to Begin() of mInitStates.
bool SetTransition(Idx x1, Idx ev, Idx x2)
Add a transition to generator by indices.
const EventSet & Alphabet(void) const
Return const reference to alphabet.
virtual void Move(vGenerator &rGen)
Destructive copy to other vGenerator.
TransSet::Iterator TransRelBegin(void) const
Iterator to Begin() of transition relation.
bool Trim(void)
Make generator trim.
virtual vGenerator * New(void) const
Construct on heap.
void Name(const std::string &rName)
Set the generator's name.
bool DelState(Idx index)
Delete a state from generator by index.
StateSet::Iterator StatesEnd(void) const
Iterator to End() of state set.
TransSet::Iterator TransRelEnd(void) const
Iterator to End() of transition relation.
bool IsDeterministic(void) const
Check if generator is deterministic.
Idx InsState(void)
Add new anonymous state to generator.
bool Empty(void) const
Check if generator is empty (no states)
Idx InsInitState(void)
Create new anonymous state and set as initial state.
bool StateNamesEnabled(void) const
Whether libFAUEDS functions are requested to generate state names.
StateSet::Iterator InitStatesEnd(void) const
Iterator to End() of mInitStates.
virtual void Clear(void)
Clear generator data.
bool ExistsMarkedState(Idx index) const
Test existence of state in mMarkedStates.
void InjectAlphabet(const EventSet &rNewalphabet)
Set mpAlphabet without consistency check.
bool Empty(void) const
Test whether if the TBaseSet is Empty.
bool Exists(const T &rElem) const
Test existence of element.
const std::string & Name(void) const
Return name of TBaseSet.
bool ComputeScc(const Generator &rGen, const SccFilter &rFilter, std::list< StateSet > &rSccList, StateSet &rRoots)
Compute strongly connected components (SCC)
bool IsOmegaTrim(const vGenerator &rGen)
RTI wrapper function.
void Product(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Product composition.
bool IsDeterministic(const vGenerator &rGen)
RTI wrapper function.
bool IsRelativelyMarked(const Generator &rGenPlant, const Generator &rGenCand)
Test for relative marking.
bool IsRelativelyOmegaMarked(const Generator &rGenPlant, const Generator &rGenCand)
Test for relative marking, omega langauges.
bool IsRelativelyPrefixClosed(const Generator &rGenPlant, const Generator &rGenCand)
Test for relative prefix-closedness.
bool IsRelativelyOmegaClosed(const Generator &rGenPlant, const Generator &rGenCand)
Test for relative closedness, omega languages.
void SupRelativelyPrefixClosed(const Generator &rPlantGen, const Generator &rSpecGen, Generator &rResGen)
Supremal Relatively Closed Sublanguage.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
void LoopCallback(bool pBreak(void))
void SupRelativelyPrefixClosedUnchecked(const Generator &rPlantGen, const Generator &rSpecGen, std::map< std::pair< Idx, Idx >, Idx > &rCompositionMap, Generator &rResGen)
Supremal Relatively Closed Sublanguage (internal function)
bool IsNonblocking(const GeneratorVector &rGvec)
std::string CollapsString(const std::string &rString, unsigned int len)
Limit length of string, return head and tail of string.
bool IsRelativelyOmegaClosedUnchecked(const Generator &rGenPlant, const Generator &rGenCand)
Test for relative closedness, omega languages.
Misc functions related to synthesis.