37 if(!inconsistent.
Empty()) {
38 std::stringstream errstr;
39 errstr <<
"mtcParallel: inconsistent controllability flags";
40 throw Exception(
"mtcParallel::inconsistent controllability flags", errstr.str(), 500);
46 std::map< std::pair<Idx,Idx>,
Idx> rcmap;
59 std::map< std::pair<Idx,Idx>,
Idx>& rReverseCompositionMap,
61 FD_DF(
"mtcParallel(" << &rGen1 <<
"," << &rGen2 <<
")");
67 FD_DF(
"mtcParallel: shared events: " << sharedalphabet.
ToString());
70 EventSet::Iterator eit;
77 FD_DF(
"mtcParallel: inserted indices in rResGen.alphabet( "
81 std::stack< std::pair<Idx,Idx> > todo;
83 std::pair<Idx,Idx> currentstates, newstates;
87 StateSet::Iterator lit1, lit2;
89 std::map< std::pair<Idx,Idx>,
Idx>::iterator rcit;
91 ColorSet colors1, colors2, composedSet;
96 FD_DF(
"mtcParallel: adding all combinations of initial states to todo:");
99 currentstates = std::make_pair(*lit1, *lit2);
100 todo.push(currentstates);
101 tmpstate = rReverseCompositionMap[currentstates] = rResGen.
InsInitState();
102 ComposedColorSet(rGen1, *lit1, colors1, rGen2, *lit2, colors2, composedSet);
103 rResGen.
InsColors(tmpstate, composedSet);
104 FD_DF(
"mtcParallel: (" << *lit1 <<
"|" << *lit2 <<
") -> "
105 << rReverseCompositionMap[currentstates]);
110 FD_DF(
"mtcParallel: processing reachable states:");
111 while (! todo.empty()) {
113 currentstates = todo.top();
115 FD_DF(
"mtcParallel: processing (" << currentstates.first <<
"|"
116 << currentstates.second <<
") -> "
117 << rReverseCompositionMap[currentstates]);
122 for (; tit1 != tit1_end; ++tit1) {
124 if (! sharedalphabet.
Exists(tit1->Ev)) {
125 FD_DF(
"mtcParallel: exists only in rGen1");
126 newstates = std::make_pair(tit1->X2, currentstates.second);
128 rcit = rReverseCompositionMap.find(newstates);
129 if (rcit == rReverseCompositionMap.end()) {
130 todo.push(newstates);
132 ComposedColorSet(rGen1, tit1->X2, colors1, rGen2, currentstates.second, colors2, composedSet);
133 rResGen.
InsColors(tmpstate, composedSet);
134 rReverseCompositionMap[newstates] = tmpstate;
135 FD_DF(
"mtcParallel: todo push: (" << newstates.first <<
"|"
136 << newstates.second <<
") -> "
137 << rReverseCompositionMap[newstates]);
140 tmpstate = rcit->second;
142 rResGen.
SetTransition(rReverseCompositionMap[currentstates], tit1->Ev,
144 FD_DF(
"mtcParallel: add transition to new generator: "
145 << rReverseCompositionMap[currentstates] <<
"-" << tit1->Ev <<
"-"
150 FD_DF(
"mtcParallel: common event");
153 tit2_end = rGen2.
TransRelEnd(currentstates.second, tit1->Ev);
154 for (; tit2 != tit2_end; ++tit2) {
155 newstates = std::make_pair(tit1->X2, tit2->X2);
157 rcit = rReverseCompositionMap.find(newstates);
158 if (rcit == rReverseCompositionMap.end()) {
159 todo.push(newstates);
161 ComposedColorSet(rGen1, tit1->X2, colors1, rGen2, tit2->X2, colors2, composedSet);
162 rResGen.
InsColors(tmpstate, composedSet);
163 rReverseCompositionMap[newstates] = tmpstate;
164 FD_DF(
"mtcParallel: todo push: (" << newstates.first <<
"|"
165 << newstates.second <<
") -> "
166 << rReverseCompositionMap[newstates]);
169 tmpstate = rcit->second;
173 FD_DF(
"mtcParallel: add transition to new generator: "
174 << rReverseCompositionMap[currentstates] <<
"-"
175 << tit1->Ev <<
"-" << tmpstate);
182 tit2_end = rGen2.
TransRelEnd(currentstates.second);
183 for (; tit2 != tit2_end; ++tit2) {
184 if (! sharedalphabet.
Exists(tit2->Ev)) {
185 FD_DF(
"mtcParallel: exists only in rGen2");
186 newstates = std::make_pair(currentstates.first, tit2->X2);
188 rcit = rReverseCompositionMap.find(newstates);
189 if (rcit == rReverseCompositionMap.end()) {
190 todo.push(newstates);
192 ComposedColorSet(rGen1, currentstates.first, colors1, rGen2, tit2->X2, colors2, composedSet);
193 rResGen.
InsColors(tmpstate, composedSet);
194 rReverseCompositionMap[newstates] = tmpstate;
195 FD_DF(
"mtcParallel: todo push: (" << newstates.first <<
"|"
196 << newstates.second <<
") -> "
197 << rReverseCompositionMap[newstates]);
200 tmpstate = rcit->second;
204 FD_DF(
"mtcParallel: add transition to new generator: "
205 << rReverseCompositionMap[currentstates] <<
"-"
206 << tit2->Ev <<
"-" << tmpstate);
220 ColorSet::Iterator cit;
222 #ifdef FAUDES_CHECKED
224 attr1 = rGen1.
States().Attribute(sidx1);
227 std::stringstream errstr;
228 errstr <<
"Index " << sidx1 <<
" not member of set" << std::endl;
229 throw Exception(
"mtcparallel: ComposedColorSet(rGen1, sidx1, rColors1, rGen2, sidx2, rColors2, composedSet)",
233 attr2 = rGen2.
States().Attribute(sidx2);
236 std::stringstream errstr;
237 errstr <<
"Index " << sidx2 <<
" not member of set" << std::endl;
238 throw Exception(
"mtcparallel: ComposedColorSet(rGen1, sidx1, rColors1, rGen2, sidx2, rColors2, composedSet)",
242 attr1 = rGen1.
States().Attribute(sidx1);
243 attr2 = rGen2.
States().Attribute(sidx2);
249 #ifdef FAUDES_CHECKED
250 if (!rColors1.
Exists(*cit))
251 throw Exception(
"mtcparallel: ComposedColorSet(rGen1, sidx1, rColors1, rGen2, sidx2, rColors2, rGenRes, sidxRes)",
252 "Color index \""+
ToStringInteger(*cit)+
"\" not found in generator's color set rColors1", 201);
254 if(rColors2.
Exists(*cit)) {
273 #ifdef FAUDES_CHECKED
274 if (!rColors2.
Exists(*cit))
275 throw Exception(
"mtcparallel: ComposedColorSet(rGen1, sidx1, rColors1, rGen2, sidx2, rColors2, rGenRes, sidxRes)",
276 "Color index \""+
ToStringInteger(*cit)+
"\" not found in generator's color set rColors2", 201);
278 if (!rColors1.
Exists(*cit)) {
#define FD_DF(message)
Debug: optional report on user functions.
State attributes for multitasking automata.
NameSet::Iterator ColorsEnd() const
Iterator for last entry in mColors.
const ColorSet & Colors(void) const
Read access to color set.
NameSet::Iterator ColorsBegin() const
Iterator for first entry in mColors.
bool IsDefault(void) const
Test for default value.
Container for colors: this is a NameSet with its own static symboltable.
Set of indices with symbolic names.
bool Exists(const Idx &rIndex) const
Test existence of index.
bool Insert(const Idx &rIndex)
Add an element by index.
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.
bool InsEvent(Idx index)
Add an existing event to alphabet by index.
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.
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)
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.
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.
TransSet::Iterator TransRelBegin(void) const
Iterator to Begin() of transition relation.
EventSet::Iterator AlphabetBegin(void) const
Iterator to Begin() of alphabet.
void Name(const std::string &rName)
Set the generator's name.
TransSet::Iterator TransRelEnd(void) const
Iterator to End() of transition relation.
Idx InsInitState(void)
Create new anonymous state and set as initial state.
StateSet::Iterator InitStatesEnd(void) const
Iterator to End() of mInitStates.
EventSet::Iterator AlphabetEnd(void) const
Iterator to End() of alphabet.
std::string AlphabetToString(void) const
Write generators alphabet to string.
bool Empty(void) const
Test whether if the TBaseSet is Empty.
virtual void Clear(void)
Clear all set.
void mtcParallel(const MtcSystem &rGen1, const MtcSystem &rGen2, MtcSystem &rResGen)
Parallel composition of two colored marking generators, controllability status is observed.
Methods for parallel composition of multitasking generators.
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.
std::string ToStringInteger(Int number)
integer to string