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)) {
NameSet::Iterator ColorsEnd() const
const ColorSet & Colors(void) const
NameSet::Iterator ColorsBegin() const
bool IsDefault(void) const
bool Exists(const Idx &rIndex) const
bool Insert(const Idx &rIndex)
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
const TaStateSet< StateAttr > & States(void) const
const TaEventSet< EventAttr > & Alphabet(void) const
bool SetTransition(Idx x1, Idx ev, Idx x2)
EventSet UncontrollableEvents(void) const
EventSet ControllableEvents(void) const
void SetControllable(Idx index)
void InsColors(Idx stateIndex, const ColorSet &rColors)
void Colors(ColorSet &rColors) const
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
StateSet::Iterator InitStatesBegin(void) const
TransSet::Iterator TransRelBegin(void) const
EventSet::Iterator AlphabetBegin(void) const
void Name(const std::string &rName)
TransSet::Iterator TransRelEnd(void) const
StateSet::Iterator InitStatesEnd(void) const
EventSet::Iterator AlphabetEnd(void) const
std::string AlphabetToString(void) const
void mtcParallel(const MtcSystem &rGen1, const MtcSystem &rGen2, MtcSystem &rResGen)
std::string ToStringInteger(Int number)
void ComposedColorSet(const MtcSystem &rGen1, const Idx sidx1, ColorSet &rColors1, const MtcSystem &rGen2, const Idx sidx2, ColorSet &rColors2, ColorSet &composedSet)