34 std::map< std::pair<Idx,Idx>,
Idx> cmap;
37 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
38 pResGen= rResGen.
New();
41 Parallel(rGen1, rGen2, cmap, *pResGen);
43 if(pResGen != &rResGen) {
44 pResGen->
Move(rResGen);
56 FD_DF(
"aParallel(...)");
63 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
64 pResGen= rResGen.
New();
77 if(pResGen != &rResGen) {
78 pResGen->
Move(rResGen);
82 FD_DF(
"aParallel(...): done");
100 if(rGenVec.
Size()==0) {
105 if(rGenVec.
Size()==1) {
106 rResGen=rGenVec.
At(0);
137 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
138 pResGen= rResGen.
New();
151 if(pResGen != &rResGen) {
152 pResGen->
Move(rResGen);
179 Parallel(rGen1,rGen2,rCompositionMap,rResGen);
202 StateSet::Iterator sit;
215 std::map< std::pair<Idx,Idx>,
Idx>& rCompositionMap,
218 FD_DF(
"Parallel(" << &rGen1 <<
"," << &rGen2 <<
")");
250 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
251 pResGen= rResGen.
New();
255 rCompositionMap.clear();
258 EventSet::Iterator eit;
265 FD_DF(
"Parallel: inserted indices in rResGen.alphabet( "
270 FD_DF(
"Parallel: shared events: " << sharedalphabet.
ToString());
273 std::stack< std::pair<Idx,Idx> > todo;
275 std::pair<Idx,Idx> currentstates, newstates;
278 StateSet::Iterator lit1,lit2;
280 std::map< std::pair<Idx,Idx>,
Idx>::iterator rcit;
283 FD_DF(
"Parallel: adding all combinations of initial states to todo:");
286 currentstates = std::make_pair(*lit1, *lit2);
287 todo.push(currentstates);
289 rCompositionMap[currentstates] = tmpstate;
290 FD_DF(
"Parallel: (" << *lit1 <<
"|" << *lit2 <<
") -> "
291 << rCompositionMap[currentstates]);
296 FD_DF(
"Parallel: processing reachable states:");
297 while (! todo.empty()) {
301 FD_WPC(rCompositionMap.size(),rCompositionMap.size()+todo.size(),
"Parallel(): processing");
303 currentstates = todo.top();
305 FD_DF(
"Parallel: processing (" << currentstates.first <<
"|"
306 << currentstates.second <<
") -> "
307 << rCompositionMap[currentstates]);
312 for (; tit1 != tit1_end; ++tit1) {
314 if (! sharedalphabet.
Exists(tit1->Ev)) {
315 FD_DF(
"Parallel: exists only in rGen1");
316 newstates = std::make_pair(tit1->X2, currentstates.second);
318 rcit = rCompositionMap.find(newstates);
319 if (rcit == rCompositionMap.end()) {
320 todo.push(newstates);
322 rCompositionMap[newstates] = tmpstate;
323 FD_DF(
"Parallel: todo push: (" << newstates.first <<
"|"
324 << newstates.second <<
") -> "
325 << rCompositionMap[newstates]);
328 tmpstate = rcit->second;
330 pResGen->
SetTransition(rCompositionMap[currentstates], tit1->Ev, tmpstate);
331 FD_DF(
"Parallel: add transition to new generator: "
332 << rCompositionMap[currentstates] <<
"-" << tit1->Ev <<
"-"
337 FD_DF(
"Parallel: common event");
340 tit2_end = rGen2.
TransRelEnd(currentstates.second, tit1->Ev);
341 for (; tit2 != tit2_end; ++tit2) {
342 newstates = std::make_pair(tit1->X2, tit2->X2);
344 rcit = rCompositionMap.find(newstates);
345 if (rcit == rCompositionMap.end()) {
346 todo.push(newstates);
348 rCompositionMap[newstates] = tmpstate;
349 FD_DF(
"Parallel: todo push: (" << newstates.first <<
"|"
350 << newstates.second <<
") -> "
351 << rCompositionMap[newstates]);
354 tmpstate = rcit->second;
358 FD_DF(
"Parallel: add transition to new generator: "
359 << rCompositionMap[currentstates] <<
"-"
360 << tit1->Ev <<
"-" << tmpstate);
367 tit2_end = rGen2.
TransRelEnd(currentstates.second);
368 for (; tit2 != tit2_end; ++tit2) {
369 if (! sharedalphabet.
Exists(tit2->Ev)) {
370 FD_DF(
"Parallel: exists only in rGen2");
371 newstates = std::make_pair(currentstates.first, tit2->X2);
373 rcit = rCompositionMap.find(newstates);
374 if (rcit == rCompositionMap.end()) {
375 todo.push(newstates);
377 rCompositionMap[newstates] = tmpstate;
378 FD_DF(
"Parallel: todo push: (" << newstates.first <<
"|"
379 << newstates.second <<
") -> "
380 << rCompositionMap[newstates]);
383 tmpstate = rcit->second;
387 FD_DF(
"Parallel: add transition to new generator: "
388 << rCompositionMap[currentstates] <<
"-"
389 << tit2->Ev <<
"-" << tmpstate);
395 rcit=rCompositionMap.begin();
396 while(rcit!=rCompositionMap.end()) {
405 if(pResGen != &rResGen) {
419 std::map< std::pair<Idx,Idx>,
Idx> cmap;
421 Product(rGen1, rGen2, cmap, rResGen);
437 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
438 pResGen= rResGen.
New();
451 if(pResGen != &rResGen) {
452 pResGen->
Move(rResGen);
471 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
472 pResGen= rResGen.
New();
485 if(pResGen != &rResGen) {
486 pResGen->
Move(rResGen);
495 std::map< std::pair<Idx,Idx>,
Idx>& rCompositionMap,
502 Product(rGen1,rGen2,rCompositionMap,rResGen);
509 std::map< std::pair<Idx,Idx>,
Idx>::iterator rit;
510 for(rit=rCompositionMap.begin(); rit!=rCompositionMap.end(); ++rit){
520 std::map< std::pair<Idx,Idx>,
Idx>& rCompositionMap,
523 FD_DF(
"Product(" << rGen1.
Name() <<
"," << rGen2.
Name() <<
")");
524 FD_DF(
"Product(): state counts " << rGen1.
Size() <<
"/" << rGen2.
Size());
528 if(&rResGen== &rGen1 || &rResGen== &rGen2) {
529 pResGen= rResGen.
New();
532 rCompositionMap.clear();
536 FD_DF(
"Product: shared alphabet: "
540 std::stack< std::pair<Idx,Idx> > todo;
542 std::pair<Idx,Idx> currentstates, newstates;
546 StateSet::Iterator lit1, lit2;
548 std::map< std::pair<Idx,Idx>,
Idx>::iterator rcit;
551 FD_DF(
"Product: adding all combinations of initial states to todo:");
556 currentstates = std::make_pair(*lit1, *lit2);
557 todo.push(currentstates);
558 rCompositionMap[currentstates] = pResGen->
InsInitState();
559 FD_DF(
"Product: (" << *lit1 <<
"|" << *lit2 <<
") -> "
560 << rCompositionMap[currentstates]);
565 FD_DF(
"Product: processing reachable states:");
566 while (! todo.empty()) {
570 FD_WPC(rCompositionMap.size(),rCompositionMap.size()+todo.size(),
"Product(): processing");
572 currentstates = todo.top();
574 FD_DF(
"Product: processing (" << currentstates.first <<
"|"
575 << currentstates.second <<
") -> " << rCompositionMap[currentstates]);
580 tit2_end = rGen2.
TransRelEnd(currentstates.second);
581 while((tit1 != tit1_end) && (tit2 != tit2_end)) {
583 if(tit1->Ev < tit2->Ev) {
588 if(tit1->Ev > tit2->Ev) {
594 while(tit2 != tit2_end) {
596 if(tit1->Ev != tit2->Ev)
break;
598 newstates = std::make_pair(tit1->X2, tit2->X2);
600 rcit = rCompositionMap.find(newstates);
601 if(rcit == rCompositionMap.end()) {
602 todo.push(newstates);
604 rCompositionMap[newstates] = tmpstate;
606 FD_DF(
"Product: todo push: (" << newstates.first <<
"|"
607 << newstates.second <<
") -> " << rCompositionMap[newstates] <<
" todo #" << todo.size());
609 tmpstate = rcit->second;
612 pResGen->
SetTransition(rCompositionMap[currentstates], tit1->Ev, tmpstate);
613 FD_DF(
"Product: add transition to new generator: "
614 << rCompositionMap[currentstates] <<
"-" << tit1->Ev <<
"-" << tmpstate);
621 if(tit1->Ev == tit2_begin->Ev)
628 rcit=rCompositionMap.begin();
629 while(rcit!=rCompositionMap.end()) {
638 if(pResGen != &rResGen) {
648 FD_DF(
"Product(...): done");
656 const std::map< std::pair<Idx,Idx>,
Idx>& rCompositionMap,
659 std::map< std::pair<Idx,Idx>,
Idx>::const_iterator rcit;
660 for(rcit=rCompositionMap.begin(); rcit!=rCompositionMap.end(); rcit++) {
661 Idx x1=rcit->first.first;
662 Idx x2=rcit->first.second;
663 Idx x12=rcit->second;
669 std::string name12= name1 +
"|" + name2;
678 const std::map< std::pair<Idx,Idx>,
Idx>& rCompositionMap,
679 std::map<Idx,Idx>& rCompositionMap1)
681 rCompositionMap1.clear();
682 std::map< std::pair<Idx,Idx>,
Idx>::const_iterator rcit;
683 for(rcit=rCompositionMap.begin(); rcit!=rCompositionMap.end(); rcit++)
684 rCompositionMap1.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.first));
690 const std::map< std::pair<Idx,Idx>,
Idx>& rCompositionMap,
691 std::map<Idx,Idx>& rCompositionMap2)
693 rCompositionMap2.clear();
694 std::map< std::pair<Idx,Idx>,
Idx>::const_iterator rcit;
695 for(rcit=rCompositionMap.begin(); rcit!=rCompositionMap.end(); rcit++)
696 rCompositionMap2.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.second));
761 std::pair<Idx,Idx> x12(x1,x2);
764 return x12it->second;
772 std::map< std::pair<Idx,Idx>,
Idx>::const_iterator rcit;
774 mArg1Map.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.first));
775 mArg2Map.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.second));
779 std::map< Idx , Idx >::const_iterator x1it=
mArg1Map.find(x1);
789 std::map< std::pair<Idx,Idx>,
Idx>::const_iterator rcit;
791 mArg1Map.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.first));
792 mArg2Map.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.second));
796 std::map< Idx , Idx >::const_iterator x2it=
mArg2Map.find(x2);
#define FD_WPC(cntnow, contdone, message)
Application callback: optional write progress report to console or application, incl count
#define FD_DF(message)
Debug: optional report on user functions.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Idx Insert(void)
Insert new index to set.
Set of indices with symbolic names.
bool Exists(const Idx &rIndex) const
Test existence of index.
Rti-wrapper for composition maps.
bool DoEqual(const ProductCompositionMap &rOther) const
virtual void Clear(void)
Clear configuration data.
virtual ~ProductCompositionMap(void)
Idx Arg1State(Idx s12) const
std::map< Idx, Idx > mArg2Map
std::map< Idx, Idx > mArg1Map
void DoAssign(const ProductCompositionMap &rSrc)
const std::map< std::pair< Idx, Idx >, Idx > & StlMap(void) const
ProductCompositionMap(void)
Rti wrapper class implementation.
Idx CompState(Idx s1, Idx s2) const
Idx Arg2State(Idx s12) const
std::map< std::pair< Idx, Idx >, Idx > mCompositionMap
std::vector< int >::size_type Position
convenience typedef for positions
virtual const T & At(const Position &pos) const
Access element.
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator on transition.
Base class of all libFAUDES objects that participate in the run-time interface.
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
Idx Size(void) const
Get size of vector.
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.
std::string MarkedStatesToString(void) const
Write set of marked states to a string (no re-indexing)
TransSet::Iterator TransRelBegin(void) const
Iterator to Begin() of transition relation.
EventSet::Iterator AlphabetBegin(void) const
Iterator to Begin() of alphabet.
virtual vGenerator * New(void) const
Construct on heap.
void ClearStateNames(void)
Remove all names from generator's StateSymbolTable.
bool ExistsState(Idx index) const
Test existence of state in state set.
std::string StateName(Idx index) const
State name lookup.
void Name(const std::string &rName)
Set the generator's name.
StateSet::Iterator StatesEnd(void) const
Iterator to End() of state set.
TransSet::Iterator TransRelEnd(void) const
Iterator to End() of transition relation.
Idx InsState(void)
Add new anonymous state to generator.
void SetMarkedState(Idx index)
Set an existing state as marked state by index.
Idx InsInitState(void)
Create new anonymous state and set as initial state.
virtual void EventAttributes(const EventSet &rEventSet)
Set attributes for existing events.
bool StateNamesEnabled(void) const
Whether libFAUEDS functions are requested to generate state names.
bool InsEvent(Idx index)
Add an existing event to alphabet by index.
StateSet::Iterator InitStatesEnd(void) const
Iterator to End() of mInitStates.
EventSet::Iterator AlphabetEnd(void) const
Iterator to End() of alphabet.
Idx Size(void) const
Get generator size (number of states)
virtual void Clear(void)
Clear generator data.
bool ExistsMarkedState(Idx index) const
Test existence of state in mMarkedStates.
std::string AlphabetToString(void) const
Write generators alphabet to string.
std::string UniqueStateName(const std::string &rName) const
Create a new unique symbolic state name.
void InjectAlphabet(const EventSet &rNewalphabet)
Set mpAlphabet without consistency check.
virtual void Clear(void)
Clear all set.
bool EqualAttributes(const TBaseSet &rOtherSet) const
Attribute access.
void Product(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Product composition.
void aParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
void aProduct(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Product composition.
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
void SetComposedStateNames(const Generator &rGen1, const Generator &rGen2, const std::map< std::pair< Idx, Idx >, Idx > &rCompositionMap, Generator &rGen12)
Helper: uses composition map to track state names in a paralell composition.
void CompositionMap1(const std::map< std::pair< Idx, Idx >, Idx > &rCompositionMap, std::map< Idx, Idx > &rCompositionMap1)
std::string CollapsString(const std::string &rString, unsigned int len)
Limit length of string, return head and tail of string.
std::string ToStringInteger(Int number)
integer to string
void CompositionMap2(const std::map< std::pair< Idx, Idx >, Idx > &rCompositionMap, std::map< Idx, Idx > &rCompositionMap2)