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

libFAUDES 2.28a --- 2016.09.13 --- c++ api documentaion by doxygen