23 #ifndef FAUDES_OMG_RABINAUT_H
24 #define FAUDES_OMG_RABINAUT_H
51 template <
class GlobalAttr,
class StateAttr,
class EventAttr,
class TransAttr>
125 return dynamic_cast< const TrGenerator*
> (pOther); };
186 void RabinAcceptanceWrite(
void)
const;
197 virtual void RestrictStates(
const StateSet& rStates);
211 virtual void DotWrite(
const std::string& rFileName)
const;
243 #define THIS TrGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
244 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
245 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
250 FD_DG(
"TrGenerator(" <<
this <<
")::TrGenerator()");
255 FD_DG(
"TrGenerator(" <<
this <<
")::TrGenerator(rOtherGen)");
260 FD_DG(
"TrGenerator(" <<
this <<
")::TrGenerator(rOtherGen)");
264 TEMP THIS::TrGenerator(
const std::string& rFileName) :
BASE(rFileName) {
265 FD_DG(
"TrGenerator(" <<
this <<
")::TrGenerator(rFilename) : done");
270 FD_DG(
"TrGenerator(" <<
this <<
")::operator = " << &rOtherGen);
272 BASE::DoAssign(rSrc);
277 FD_DG(
"TrGenerator(" <<
this <<
")::operator = " << &rSrc);
285 if(&rSrc==
static_cast<const Type*
>(
this))
288 const THIS* pgen=
dynamic_cast<const THIS*
>(&rSrc);
294 FD_DG(
"TrGenerator(" <<
this <<
")::Assign([type] " << &rSrc <<
"): call base");
304 res->EventSymbolTablep(BASE::mpEventSymbolTable);
305 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
306 res->mReindexOnWrite=BASE::mReindexOnWrite;
321 THIS res= BASE::NewCGen();
327 BASE::GlobalAttribute(rRabAcc);
332 return *BASE::GlobalAttributep();
337 return BASE::GlobalAttribute();
344 rpair.
ISet()=THIS::States();
345 rpair.
RSet()=rMarking;
350 TEMP void THIS::RabinAcceptanceWrite(
void)
const {
356 BASE::RestrictStates(rStates);
362 TEMP void THIS::DotWrite(
const std::string& rFileName)
const {
363 FD_DG(
"RabinAutomaton(" <<
this <<
")::DotWrite(" << rFileName <<
")");
365 if(BASE::ReindexOnWrite()) BASE::SetMinStateIndexMap();
367 StateSet::Iterator lit;
370 std::vector<std::string> ColorPalette;
371 ColorPalette.push_back(
"lightblue");
372 ColorPalette.push_back(
"darkblue");
373 ColorPalette.push_back(
"#ffcc80");
374 ColorPalette.push_back(
"#ff9900");
375 ColorPalette.push_back(
"#b0ffb0");
376 ColorPalette.push_back(
"#307030");
377 ColorPalette.push_back(
"#ff9090");
378 ColorPalette.push_back(
"#a00202");
379 ColorPalette.push_back(
"black");
380 if(2*THIS::RabinAcceptance().Size()>ColorPalette.size()-1) {
381 FD_DG(
"RabinAutomaton(" <<
this <<
")::DotWrite(...): to many Rabin pairs");
382 BASE::DotWrite(rFileName);
387 std::ofstream stream;
388 stream.exceptions(std::ios::badbit|std::ios::failbit);
391 stream.open(rFileName.c_str());
392 stream <<
"// dot output generated by libFAUDES RabinAutomaton" << std::endl;
393 stream <<
"digraph \"" << BASE::Name() <<
"\" {" << std::endl;
394 stream <<
" rankdir=LR" << std::endl;
396 stream <<
" node [shape=rectangle, style=rounded];" << std::endl;
400 stream <<
" // initial states" << std::endl;
402 for (lit = BASE::InitStatesBegin(); lit != BASE::InitStatesEnd(); ++lit) {
403 std::string xname= BASE::StateName(*lit);
404 if(xname==
"") xname=
ToStringInteger(
static_cast<long int>(BASE::MinStateIndex(*lit)));
405 stream <<
" dot_dummyinit_" << i <<
" [shape=none, label=\"\" ];" << std::endl;
406 stream <<
" dot_dummyinit_" << i <<
" -> \"" << xname <<
"\";" << std::endl;
413 RabinAcceptance::CIterator rit;
414 for(rit=THIS::RabinAcceptance().Begin();rit!=THIS::RabinAcceptance().End();++rit) {
415 marked = marked + rit->ISet();
416 marked = marked + rit->RSet();
421 stream <<
" // plain states" << std::endl;
422 for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); ++lit) {
423 if(marked.
Exists(*lit))
continue;
424 std::string xname=BASE::StateName(*lit);
426 stream <<
" \"" << xname <<
"\";" << std::endl;
431 stream <<
" // colored states" << std::endl;
432 for (lit = marked.
Begin(); lit != marked.
End(); ++lit) {
433 std::string xname=BASE::StateName(*lit);
434 if(xname==
"") xname=
ToStringInteger(
static_cast<long int>(BASE::MinStateIndex(*lit)));
435 stream <<
" \"" << xname <<
"\"";
437 RabinAcceptance::CIterator rit;
438 std::vector<int> colvec;
440 for(rit=THIS::RabinAcceptance().Begin();rit!=THIS::RabinAcceptance().End();++rit) {
441 if(rit->ISet().Exists(*lit)) colvec.push_back(col);
442 if(rit->RSet().Exists(*lit)) colvec.push_back(col+1);
446 if(this->ExistsMarkedState(*lit))
447 colvec.push_back(ColorPalette.size()-1);
449 stream <<
" [label=<<TABLE BORDER=\"0\"><TR>";
451 stream <<
"<TD>" << xname <<
"</TD>";
453 stream <<
"<TD WIDTH=\"5\"></TD>";
456 for(i=0;i<colvec.size();++i) {
457 stream <<
"<TD BGCOLOR=\"" << ColorPalette.at(colvec.at(i)) <<
"\" BORDER=\"0\" WIDTH=\"10\"></TD>";
460 stream <<
"</TR></TABLE>>";
461 stream <<
"];" << std::endl;
465 stream <<
" // transition relation" << std::endl;
467 for(tit = trx1x2ev.
Begin(); tit != trx1x2ev.
End();) {
469 if(!elabel.empty()) elabel = elabel +
", ";
470 if(elabel.length()>9) elabel = elabel +
"\n";
471 elabel=elabel + BASE::EventName(tit->Ev);
477 if(tit==trx1x2ev.
End())
480 flush=((tit->X1 != x1) || (tit->X2 != x2));
483 std::string x1name= BASE::StateName(x1);
485 std::string x2name= BASE::StateName(x2);
487 stream <<
" \"" << x1name <<
"\" -> \"" << x2name
488 <<
"\" [label=\"" << elabel <<
"\"];" << std::endl;
494 stream <<
"}" << std::endl;
497 catch (std::ios::failure&) {
499 "Exception opening/writing dotfile \""+rFileName+
"\"", 3);
501 BASE::ClearMinStateIndexMap();
void RestrictStates(const StateSet &rDomain)
virtual void Insert(const T &rElem)
Iterator Begin(void) const
virtual const Type * Cast(const Type *pOther) const
void Write(const Type *pContext=0) const
bool Exists(const T &rElem) const
virtual void InsertSet(const TBaseSet &rOtherSet)
Iterator Begin(void) const
TrGenerator< RabinAcceptance, AttributeVoid, AttributeCFlags, AttributeVoid > RabinAutomaton
std::string ToStringInteger(Int number)