cfl_parallel.cpp
Go to the documentation of this file.
1 /** @file cfl_parallel.cpp parallel composition */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2006 Bernd Opitz
6  Exclusive copyright is granted to Klaus Schmidt
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 #include "cfl_parallel.h"
24 
25 namespace faudes {
26 
27 // Parallel(rGen1, rGen2, res)
28 void Parallel(const Generator& rGen1, const Generator& rGen2, Generator& rResGen) {
29  // helpers:
30  std::map< std::pair<Idx,Idx>, Idx> cmap;
31  // prepare result
32  Generator* pResGen = &rResGen;
33  if(&rResGen== &rGen1 || &rResGen== &rGen2) {
34  pResGen= rResGen.New();
35  }
36  // doit
37  Parallel(rGen1, rGen2, cmap, *pResGen);
38  // copy result
39  if(pResGen != &rResGen) {
40  pResGen->Move(rResGen);
41  delete pResGen;
42  }
43 }
44 
45 
46 // Parallel for Generators, transparent for event attributes.
47 void aParallel(
48  const Generator& rGen1,
49  const Generator& rGen2,
50  Generator& rResGen)
51 {
52 
53  // inputs have to agree on attributes of shared events:
54  bool careattr=rGen1.Alphabet().EqualAttributes(rGen2.Alphabet());
55 
56  // prepare result
57  Generator* pResGen = &rResGen;
58  if(&rResGen== &rGen1 || &rResGen== &rGen2) {
59  pResGen= rResGen.New();
60  }
61 
62  // make product composition of inputs
63  Parallel(rGen1,rGen2,*pResGen);
64 
65  // copy all attributes of input alphabets
66  if(careattr) {
67  pResGen->EventAttributes(rGen1.Alphabet());
68  pResGen->EventAttributes(rGen2.Alphabet());
69  }
70 
71  // copy result
72  if(pResGen != &rResGen) {
73  pResGen->Move(rResGen);
74  delete pResGen;
75  }
76 
77 }
78 
79 
80 // Parallel for multiple Generators, transparent for event attributes.
81 void aParallel(
82  const GeneratorVector& rGenVec,
83  Generator& rResGen)
84 {
85 
86  // inputs have to agree on attributes of pairwise shared events:
87  bool careattr=true;
88  for(GeneratorVector::Position i=0; i<rGenVec.Size(); i++)
89  for(GeneratorVector::Position j=0; j<i; j++)
90  if(!rGenVec.At(i).Alphabet().EqualAttributes(rGenVec.At(j).Alphabet()))
91  careattr=false;
92 
93  // ignore empty
94  if(rGenVec.Size()==0) {
95  return;
96  }
97 
98  // copy one
99  if(rGenVec.Size()==1) {
100  rResGen=rGenVec.At(0);
101  return;
102  }
103 
104  // run parallel
105  Parallel(rGenVec.At(0),rGenVec.At(1),rResGen);
106  for(GeneratorVector::Position i=2; i<rGenVec.Size(); i++)
107  Parallel(rGenVec.At(i),rResGen,rResGen);
108 
109  // fix alphabet
110  if(careattr) {
111  for(GeneratorVector::Position i=0; i<rGenVec.Size(); i++)
112  rResGen.EventAttributes(rGenVec.At(i).Alphabet());
113  }
114 
115 }
116 
117 
118 // aParallel(rGen1, rGen2, rCompositionMap, res)
120  const Generator& rGen1,
121  const Generator& rGen2,
122  ProductCompositionMap& rCompositionMap,
123  Generator& rResGen)
124 {
125  // inputs have to agree on attributes of shared events:
126  bool careattr=rGen1.Alphabet().EqualAttributes(rGen2.Alphabet());
127 
128  // prepare result
129  Generator* pResGen = &rResGen;
130  if(&rResGen== &rGen1 || &rResGen== &rGen2) {
131  pResGen= rResGen.New();
132  }
133 
134  // make product composition of inputs
135  Parallel(rGen1,rGen2,rCompositionMap.StlMap(),*pResGen);
136 
137  // copy all attributes of input alphabets
138  if(careattr) {
139  pResGen->EventAttributes(rGen1.Alphabet());
140  pResGen->EventAttributes(rGen2.Alphabet());
141  }
142 
143  // copy result
144  if(pResGen != &rResGen) {
145  pResGen->Move(rResGen);
146  delete pResGen;
147  }
148 
149 }
150 
151 // Parallel(rGen1, rGen2, rCompositionMap, res)
152 void Parallel(
153  const Generator& rGen1,
154  const Generator& rGen2,
155  ProductCompositionMap& rCompositionMap,
156  Generator& rResGen)
157 {
158  // make product composition of inputs
159  Parallel(rGen1,rGen2,rCompositionMap.StlMap(),rResGen);
160 }
161 
162 // Parallel(rGen1, rGen2, rCompositionMap, mark1, mark2, res)
163 void Parallel(
164  const Generator& rGen1, const Generator& rGen2,
165  ProductCompositionMap& rCompositionMap,
166  StateSet& rMark1,
167  StateSet& rMark2,
168  Generator& rResGen)
169 {
170 
171  // do the composition
172  Parallel(rGen1,rGen2,rCompositionMap,rResGen);
173 
174  // clear marking
175  rMark1.Clear();
176  rMark2.Clear();
177 
178  /*
179  see tmoor 20110208
180 
181  // catch special cases: a
182  if(rGen1.AlphabetSize()==0) {
183  rMark2=rGen2.MarkedStates();
184  return;
185  }
186 
187  // catch special cases: b
188  if(rGen2.AlphabetSize()==0) {
189  rMark1=rGen1.MarkedStates();
190  return;
191  }
192  */
193 
194  // retrieve marking from reverse composition map
195  StateSet::Iterator sit;
196  for(sit=rResGen.StatesBegin(); sit!=rResGen.StatesEnd(); ++sit) {
197  Idx s1=rCompositionMap.Arg1State(*sit);
198  Idx s2=rCompositionMap.Arg2State(*sit);
199  if(rGen1.ExistsMarkedState(s1)) rMark1.Insert(*sit);
200  if(rGen2.ExistsMarkedState(s2)) rMark1.Insert(*sit);
201  }
202 }
203 
204 
205 // Parallel(rGen1, rGen2, rCompositionMap, res)
206 void Parallel(
207  const Generator& rGen1, const Generator& rGen2,
208  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
209  Generator& rResGen)
210 {
211  FD_DF("Parallel(" << &rGen1 << "," << &rGen2 << ")");
212 
213  /*
214  re-consider the special cases:
215 
216  if Sigma_1=0, we have either
217  -- L_res=L_2 (if L_1!=0)
218  -- L_res=0 (if L_1==0)
219 
220  the below special cases do not handle this correct,
221  nor do they setup the composition map; thus, we drop
222  the special cases; tmoor 20110208
223  */
224 
225  /*
226  // special case: empty alphabet
227  if(rGen1.AlphabetSize()==0) {
228  rResGen=rGen2;
229  rResGen.Name(rGen2.Name());
230  return;
231  }
232 
233  // special case: empty alphabet
234  if(rGen2.AlphabetSize()==0) {
235  rResGen=rGen1;
236  rResGen.Name(rGen1.Name());
237  return;
238  }
239  */
240 
241  // prepare result
242  Generator* pResGen = &rResGen;
243  if(&rResGen== &rGen1 || &rResGen== &rGen2) {
244  pResGen= rResGen.New();
245  }
246  pResGen->Clear();
247  pResGen->Name(CollapsString(rGen1.Name()+"||"+rGen2.Name()));
248  rCompositionMap.clear();
249 
250  // create res alphabet
251  EventSet::Iterator eit;
252  for (eit = rGen1.AlphabetBegin(); eit != rGen1.AlphabetEnd(); ++eit) {
253  pResGen->InsEvent(*eit);
254  }
255  for (eit = rGen2.AlphabetBegin(); eit != rGen2.AlphabetEnd(); ++eit) {
256  pResGen->InsEvent(*eit);
257  }
258  FD_DF("Parallel: inserted indices in rResGen.alphabet( "
259  << pResGen->AlphabetToString() << ")");
260 
261  // shared events
262  EventSet sharedalphabet = rGen1.Alphabet() * rGen2.Alphabet();
263  FD_DF("Parallel: shared events: " << sharedalphabet.ToString());
264 
265  // todo stack
266  std::stack< std::pair<Idx,Idx> > todo;
267  // current pair, new pair
268  std::pair<Idx,Idx> currentstates, newstates;
269  // state
270  Idx tmpstate;
271  StateSet::Iterator lit1, lit2;
272  TransSet::Iterator tit1, tit1_end, tit2, tit2_end;
273  std::map< std::pair<Idx,Idx>, Idx>::iterator rcit;
274 
275  // push all combinations of initial states on todo stack
276  FD_DF("Parallel: adding all combinations of initial states to todo:");
277  for (lit1 = rGen1.InitStatesBegin(); lit1 != rGen1.InitStatesEnd(); ++lit1) {
278  for (lit2 = rGen2.InitStatesBegin(); lit2 != rGen2.InitStatesEnd(); ++lit2) {
279  currentstates = std::make_pair(*lit1, *lit2);
280  todo.push(currentstates);
281  tmpstate = pResGen->InsInitState();
282  rCompositionMap[currentstates] = tmpstate;
283  FD_DF("Parallel: (" << *lit1 << "|" << *lit2 << ") -> "
284  << rCompositionMap[currentstates]);
285  }
286  }
287 
288  // start algorithm
289  FD_DF("Parallel: processing reachable states:");
290  while (! todo.empty()) {
291  // allow for user interrupt
292  // LoopCallback();
293  // allow for user interrupt, incl progress report
294  FD_WPC(rCompositionMap.size(),rCompositionMap.size()+todo.size(),"Parallel(): processing");
295  // get next reachable state from todo stack
296  currentstates = todo.top();
297  todo.pop();
298  FD_DF("Parallel: processing (" << currentstates.first << "|"
299  << currentstates.second << ") -> "
300  << rCompositionMap[currentstates]);
301  // iterate over all rGen1 transitions
302  // (includes execution of shared events)
303  tit1 = rGen1.TransRelBegin(currentstates.first);
304  tit1_end = rGen1.TransRelEnd(currentstates.first);
305  for (; tit1 != tit1_end; ++tit1) {
306  // if event not shared
307  if (! sharedalphabet.Exists(tit1->Ev)) {
308  FD_DF("Parallel: exists only in rGen1");
309  newstates = std::make_pair(tit1->X2, currentstates.second);
310  // add to todo list if composition state is new
311  rcit = rCompositionMap.find(newstates);
312  if (rcit == rCompositionMap.end()) {
313  todo.push(newstates);
314  tmpstate = pResGen->InsState();
315  rCompositionMap[newstates] = tmpstate;
316  FD_DF("Parallel: todo push: (" << newstates.first << "|"
317  << newstates.second << ") -> "
318  << rCompositionMap[newstates]);
319  }
320  else {
321  tmpstate = rcit->second;
322  }
323  pResGen->SetTransition(rCompositionMap[currentstates], tit1->Ev, tmpstate);
324  FD_DF("Parallel: add transition to new generator: "
325  << rCompositionMap[currentstates] << "-" << tit1->Ev << "-"
326  << tmpstate);
327  }
328  // if shared event
329  else {
330  FD_DF("Parallel: common event");
331  // find shared transitions
332  tit2 = rGen2.TransRelBegin(currentstates.second, tit1->Ev);
333  tit2_end = rGen2.TransRelEnd(currentstates.second, tit1->Ev);
334  for (; tit2 != tit2_end; ++tit2) {
335  newstates = std::make_pair(tit1->X2, tit2->X2);
336  // add to todo list if composition state is new
337  rcit = rCompositionMap.find(newstates);
338  if (rcit == rCompositionMap.end()) {
339  todo.push(newstates);
340  tmpstate = pResGen->InsState();
341  rCompositionMap[newstates] = tmpstate;
342  FD_DF("Parallel: todo push: (" << newstates.first << "|"
343  << newstates.second << ") -> "
344  << rCompositionMap[newstates]);
345  }
346  else {
347  tmpstate = rcit->second;
348  }
349  pResGen->SetTransition(rCompositionMap[currentstates],
350  tit1->Ev, tmpstate);
351  FD_DF("Parallel: add transition to new generator: "
352  << rCompositionMap[currentstates] << "-"
353  << tit1->Ev << "-" << tmpstate);
354  }
355  }
356  }
357  // iterate over all rGen2 transitions
358  // (without execution of shared events)
359  tit2 = rGen2.TransRelBegin(currentstates.second);
360  tit2_end = rGen2.TransRelEnd(currentstates.second);
361  for (; tit2 != tit2_end; ++tit2) {
362  if (! sharedalphabet.Exists(tit2->Ev)) {
363  FD_DF("Parallel: exists only in rGen2");
364  newstates = std::make_pair(currentstates.first, tit2->X2);
365  // add to todo list if composition state is new
366  rcit = rCompositionMap.find(newstates);
367  if (rcit == rCompositionMap.end()) {
368  todo.push(newstates);
369  tmpstate = pResGen->InsState();
370  rCompositionMap[newstates] = tmpstate;
371  FD_DF("Parallel: todo push: (" << newstates.first << "|"
372  << newstates.second << ") -> "
373  << rCompositionMap[newstates]);
374  }
375  else {
376  tmpstate = rcit->second;
377  }
378  pResGen->SetTransition(rCompositionMap[currentstates],
379  tit2->Ev, tmpstate);
380  FD_DF("Parallel: add transition to new generator: "
381  << rCompositionMap[currentstates] << "-"
382  << tit2->Ev << "-" << tmpstate);
383  }
384  }
385  }
386 
387  // set marked states
388  for (lit1 = rGen1.MarkedStatesBegin();
389  lit1 != rGen1.MarkedStatesEnd(); ++lit1) {
390  for (lit2 = rGen2.MarkedStatesBegin();
391  lit2 != rGen2.MarkedStatesEnd(); ++lit2) {
392  currentstates = std::make_pair(*lit1, *lit2);
393  rcit = rCompositionMap.find(currentstates);
394  if (rcit != rCompositionMap.end()) {
395  pResGen->SetMarkedState(rcit->second);
396  }
397  }
398  }
399  FD_DF("Parallel: marked states: "
400  << pResGen->MarkedStatesToString());
401  // copy result
402  if(pResGen != &rResGen) {
403  rResGen = *pResGen;
404  delete pResGen;
405  }
406  // set statenames
407  if(rGen1.StateNamesEnabled() && rGen2.StateNamesEnabled() && rResGen.StateNamesEnabled())
408  SetComposedStateNames(rGen1, rGen2, rCompositionMap, rResGen);
409  else
410  rResGen.StateNamesEnabled(false);
411 }
412 
413 
414 // Product(rGen1, rGen2, res)
415 void Product(const Generator& rGen1, const Generator& rGen2, Generator& rResGen) {
416  std::map< std::pair<Idx,Idx>, Idx> cmap;
417  // doit
418  Product(rGen1, rGen2, cmap, rResGen);
419 }
420 
421 
422 // Product for Generators, transparent for event attributes.
423 void aProduct(
424  const Generator& rGen1,
425  const Generator& rGen2,
426  Generator& rResGen)
427 {
428 
429  // inputs have to agree on attributes of shared events:
430  bool careattr=rGen1.Alphabet().EqualAttributes(rGen2.Alphabet());
431 
432  // prepare result
433  Generator* pResGen = &rResGen;
434  if(&rResGen== &rGen1 || &rResGen== &rGen2) {
435  pResGen= rResGen.New();
436  }
437 
438  // make product composition of inputs
439  Product(rGen1,rGen2,*pResGen);
440 
441  // copy all attributes of input alphabets
442  if(careattr) {
443  pResGen->EventAttributes(rGen1.Alphabet());
444  pResGen->EventAttributes(rGen2.Alphabet());
445  }
446 
447  // copy result
448  if(pResGen != &rResGen) {
449  pResGen->Move(rResGen);
450  delete pResGen;
451  }
452 
453 }
454 
455 
456 // aProduct(rGen1, rGen2, rCompositionMap, res)
457 void aProduct(
458  const Generator& rGen1,
459  const Generator& rGen2,
460  ProductCompositionMap& rCompositionMap,
461  Generator& rResGen)
462 {
463  // inputs have to agree on attributes of shared events:
464  bool careattr=rGen1.Alphabet().EqualAttributes(rGen2.Alphabet());
465 
466  // prepare result
467  Generator* pResGen = &rResGen;
468  if(&rResGen== &rGen1 || &rResGen== &rGen2) {
469  pResGen= rResGen.New();
470  }
471 
472  // make product composition of inputs
473  Product(rGen1,rGen2,rCompositionMap.StlMap(),*pResGen);
474 
475  // copy all attributes of input alphabets
476  if(careattr) {
477  pResGen->EventAttributes(rGen1.Alphabet());
478  pResGen->EventAttributes(rGen2.Alphabet());
479  }
480 
481  // copy result
482  if(pResGen != &rResGen) {
483  pResGen->Move(rResGen);
484  delete pResGen;
485  }
486 
487 }
488 
489 // Product(rGen1, rGen2, rCompositionMap, mark1, mark2, res)
490 void Product(
491  const Generator& rGen1, const Generator& rGen2,
492  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
493  StateSet& rMark1,
494  StateSet& rMark2,
495  Generator& rResGen)
496 {
497 
498  // do the composition
499  Product(rGen1,rGen2,rCompositionMap,rResGen);
500 
501  // clear marking
502  rMark1.Clear();
503  rMark2.Clear();
504 
505  // retrieve marking from reverse composition map
506  std::map< std::pair<Idx,Idx>, Idx>::iterator rit;
507  for(rit=rCompositionMap.begin(); rit!=rCompositionMap.end(); ++rit){
508  if(rGen1.ExistsMarkedState(rit->first.first)) rMark1.Insert(rit->second);
509  if(rGen2.ExistsMarkedState(rit->first.second)) rMark2.Insert(rit->second);
510  }
511 }
512 
513 
514 // Product(rGen1, rGen2, rCompositionMap, res)
515 void Product(
516  const Generator& rGen1, const Generator& rGen2,
517  std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
518  Generator& rResGen)
519 {
520  FD_DF("Product(" << &rGen1 << "," << &rGen2 << ")");
521 
522  // prepare result
523  Generator* pResGen = &rResGen;
524  if(&rResGen== &rGen1 || &rResGen== &rGen2) {
525  pResGen= rResGen.New();
526  }
527  pResGen->Clear();
528  rCompositionMap.clear();
529 
530  // shared alphabet
531  pResGen->InjectAlphabet(rGen1.Alphabet() * rGen2.Alphabet());
532  FD_DF("Product: shared alphabet: "
533  << (rGen1.Alphabet() * rGen2.Alphabet()).ToString());
534 
535  // todo stack
536  std::stack< std::pair<Idx,Idx> > todo;
537  // current pair, new pair
538  std::pair<Idx,Idx> currentstates, newstates;
539  // state
540  Idx tmpstate;
541 
542  StateSet::Iterator lit1, lit2;
543  TransSet::Iterator tit1, tit1_end, tit2, tit2_end, tit2_begin;
544  std::map< std::pair<Idx,Idx>, Idx>::iterator rcit;
545 
546  // push all combinations of initial states on todo stack
547  FD_DF("Product: adding all combinations of initial states to todo:");
548  for (lit1 = rGen1.InitStatesBegin();
549  lit1 != rGen1.InitStatesEnd(); ++lit1) {
550  for (lit2 = rGen2.InitStatesBegin();
551  lit2 != rGen2.InitStatesEnd(); ++lit2) {
552  currentstates = std::make_pair(*lit1, *lit2);
553  todo.push(currentstates);
554  rCompositionMap[currentstates] = pResGen->InsInitState();
555  FD_DF("Product: (" << *lit1 << "|" << *lit2 << ") -> "
556  << rCompositionMap[currentstates]);
557  }
558  }
559 
560  // start algorithm
561  FD_DF("Product: processing reachable states:");
562  while (! todo.empty()) {
563  // allow for user interrupt
564  // LoopCallback();
565  // allow for user interrupt, incl progress report
566  FD_WPC(rCompositionMap.size(),rCompositionMap.size()+todo.size(),"Product(): processing");
567  // get next reachable state from todo stack
568  currentstates = todo.top();
569  todo.pop();
570  FD_DF("Product: processing (" << currentstates.first << "|"
571  << currentstates.second << ") -> " << rCompositionMap[currentstates]);
572  // iterate over all rGen1 and rGen2 transitions
573  tit1 = rGen1.TransRelBegin(currentstates.first);
574  tit1_end = rGen1.TransRelEnd(currentstates.first);
575  tit2 = rGen2.TransRelBegin(currentstates.second);
576  tit2_end = rGen2.TransRelEnd(currentstates.second);
577  while((tit1 != tit1_end) && (tit2 != tit2_end)) {
578  // sync event by tit1
579  if(tit1->Ev < tit2->Ev) {
580  ++tit1;
581  continue;
582  }
583  // sync event by tit2
584  if(tit1->Ev > tit2->Ev) {
585  ++tit2;
586  continue;
587  }
588  // shared event: iterate tit2
589  tit2_begin = tit2;
590  while(tit2 != tit2_end) {
591  // break iteration
592  if(tit1->Ev != tit2->Ev) break;
593  // successor composition state
594  newstates = std::make_pair(tit1->X2, tit2->X2);
595  // add to todo list if composition state is new
596  rcit = rCompositionMap.find(newstates);
597  if(rcit == rCompositionMap.end()) {
598  todo.push(newstates);
599  tmpstate = pResGen->InsState();
600  rCompositionMap[newstates] = tmpstate;
601  FD_DF("Product: todo push: (" << newstates.first << "|"
602  << newstates.second << ") -> " << rCompositionMap[newstates]);
603  } else {
604  tmpstate = rcit->second;
605  }
606  // set transition in result
607  pResGen->SetTransition(rCompositionMap[currentstates], tit1->Ev, tmpstate);
608  FD_DF("Product: add transition to new generator: "
609  << rCompositionMap[currentstates] << "-" << tit1->Ev << "-" << tmpstate);
610  ++tit2;
611  }
612  // increment tit1
613  ++tit1;
614  // reset tit2 (needed for non-deterministic case)
615  if(tit1 != tit1_end)
616  if(tit1->Ev == tit2_begin->Ev)
617  tit2=tit2_begin;
618  }
619  } // todo
620 
621  // set marked states
622  for (lit1 = rGen1.MarkedStatesBegin();
623  lit1 != rGen1.MarkedStatesEnd(); ++lit1) {
624  for (lit2 = rGen2.MarkedStatesBegin();
625  lit2 != rGen2.MarkedStatesEnd(); ++lit2) {
626  currentstates = std::make_pair(*lit1, *lit2);
627  rcit = rCompositionMap.find(currentstates);
628  if (rcit != rCompositionMap.end()) {
629  pResGen->SetMarkedState(rcit->second);
630  }
631  }
632  }
633  FD_DF("Product: set marked states: " << pResGen->MarkedStatesToString());
634 
635  // copy result (TODO: use move)
636  if(pResGen != &rResGen) {
637  rResGen = *pResGen;
638  delete pResGen;
639  }
640  // set statenames
641  if(rGen1.StateNamesEnabled() && rGen2.StateNamesEnabled() && rResGen.StateNamesEnabled())
642  SetComposedStateNames(rGen1, rGen2, rCompositionMap, rResGen);
643  else
644  rResGen.ClearStateNames();
645 
646 }
647 
648 
649 
650 // SetParallelStateNames
652  const Generator& rGen1, const Generator& rGen2,
653  const std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
654  Generator& rGen12)
655 {
656  std::map< std::pair<Idx,Idx>, Idx>::const_iterator rcit;
657  for(rcit=rCompositionMap.begin(); rcit!=rCompositionMap.end(); rcit++) {
658  Idx x1=rcit->first.first;
659  Idx x2=rcit->first.second;
660  Idx x12=rcit->second;
661  if(!rGen12.ExistsState(x12)) continue;
662  std::string name1= rGen1.StateName(x1);
663  if(name1=="") name1=ToStringInteger(x1);
664  std::string name2= rGen2.StateName(x2);
665  if(name2=="") name2=ToStringInteger(x2);
666  std::string name12= name1 + "|" + name2;
667  name12=rGen12.UniqueStateName(name12);
668  rGen12.StateName(x12,name12);
669  }
670 }
671 
672 
673 // CompositionMap1
675  const std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
676  std::map<Idx,Idx>& rCompositionMap1)
677 {
678  rCompositionMap1.clear();
679  std::map< std::pair<Idx,Idx>, Idx>::const_iterator rcit;
680  for(rcit=rCompositionMap.begin(); rcit!=rCompositionMap.end(); rcit++)
681  rCompositionMap1.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.first));
682 }
683 
684 
685 // CompositionMap2
687  const std::map< std::pair<Idx,Idx>, Idx>& rCompositionMap,
688  std::map<Idx,Idx>& rCompositionMap2)
689 {
690  rCompositionMap2.clear();
691  std::map< std::pair<Idx,Idx>, Idx>::const_iterator rcit;
692  for(rcit=rCompositionMap.begin(); rcit!=rCompositionMap.end(); rcit++)
693  rCompositionMap2.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.second));
694 }
695 
696 
697 /**
698  * Rti wrapper class implementation
699  */
700 
701 // std faudes type
702 FAUDES_TYPE_IMPLEMENTATION(ProductCompositionMap,ProductCompositionMap,Type)
703 
704 // construct
706  mCompiled=true;
707 }
708 
709 // construct
711  DoAssign(rOther);
712 }
713 
714 // destruct
716 }
717 
718 // clear
720  mCompositionMap.clear();
721  mCompiled=true;
722  mArg1Map.clear();
723  mArg2Map.clear();
724 }
725 
726 // assignment
729  mCompiled=rSrc.mCompiled;
730  mArg1Map=rSrc.mArg1Map;
731  mArg2Map=rSrc.mArg2Map;
732 }
733 
734 // equality
736  return mCompositionMap==rOther.mCompositionMap;
737 }
738 
739 // C++/STL access
740 const std::map< std::pair<Idx,Idx> , Idx >& ProductCompositionMap::StlMap(void) const {
741  return mCompositionMap;
742 }
743 
744 // C++/STL access
745 std::map< std::pair<Idx,Idx> , Idx >& ProductCompositionMap::StlMap(void) {
746  mCompiled=false;
747  return mCompositionMap;
748 }
749 
750 // C++/STL access
751 void ProductCompositionMap::StlMap(const std::map< std::pair<Idx,Idx> , Idx >& rMap) {
752  mCompositionMap=rMap;
753  mCompiled=false;
754 }
755 
756 // access
758  std::pair<Idx,Idx> x12(x1,x2);
759  std::map< std::pair<Idx,Idx> , Idx >::const_iterator x12it=mCompositionMap.find(x12);
760  if(x12it==mCompositionMap.end()) return 0;
761  return x12it->second;
762 }
763 
764 // access
766  if(!mCompiled) {
767  mArg1Map.clear();
768  mArg2Map.clear();
769  std::map< std::pair<Idx,Idx>, Idx>::const_iterator rcit;
770  for(rcit=mCompositionMap.begin(); rcit!=mCompositionMap.end(); rcit++) {
771  mArg1Map.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.first));
772  mArg2Map.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.second));
773  }
774  mCompiled=true;
775  }
776  std::map< Idx , Idx >::const_iterator x1it=mArg1Map.find(x1);
777  if(x1it==mArg1Map.end()) return 0;
778  return x1it->second;
779 }
780 
781 // access
783  if(!mCompiled) {
784  mArg1Map.clear();
785  mArg2Map.clear();
786  std::map< std::pair<Idx,Idx>, Idx>::const_iterator rcit;
787  for(rcit=mCompositionMap.begin(); rcit!=mCompositionMap.end(); rcit++) {
788  mArg1Map.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.first));
789  mArg2Map.insert(std::pair<Idx,Idx>(rcit->second,rcit->first.second));
790  }
791  mCompiled=true;
792  }
793  std::map< Idx , Idx >::const_iterator x2it=mArg2Map.find(x2);
794  if(x2it==mArg2Map.end()) return 0;
795  return x2it->second;
796 }
797 
798 
799 
800 } // name space

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen