con_decomposability.cpp
Go to the documentation of this file.
1 /** @file con_decomposability.cpp Conditionaldecomposability */
2 
3 /*
4  * Implementation of the Conditionally decomposable algorithm
5  *
6  * Copyright (C) 2011 Tomas Masopust
7  *
8  */
9 
10 
11 #include "con_decomposability.h"
12 #include <vector>
13 
14 namespace faudes {
15 
16 bool IsConditionalDecomposable(const Generator& gen, const EventSetVector& rAlphabets, const EventSet& ek, Generator& proof) {
17  FD_DF("Conditionaldecomposability checking...");
18 
19  // the generator must be deterministic
20  if (gen.IsDeterministic() == false) {
21  std::stringstream errstr;
22  errstr << "Generator must be deterministic, but is nondeterministic";
23  throw Exception("ConditionalDecomposability", errstr.str(), 201);
24  }
25 
26  // at least two alphabets in the vector
27  if (rAlphabets.Size() < 2) {
28  std::stringstream errstr;
29  errstr << "At least two alphabets must be included in the EventSetVector";
30  throw Exception("ConditionalDecomposability", errstr.str(), 201);
31  }
32 
33  Idx i;
34  EventSetVector ee = rAlphabets; // Vector of input alphabets
35  EventSet unionset; // contains union of Ei
36  EventSet shared; // contains union of intersections
37 
38  // Compute unionset
39  for (i = 0; i < ee.Size(); i++) {
40  SetUnion(unionset,ee.At(i),unionset);
41  }
42 
43  // Compute the set of shared events
44  for (i = 0; i < ee.Size(); i++) {
45  for (Idx j = 0; j < ee.Size(); j++) {
46  if (j != i) {
47  EventSet eHelpInt;
48  SetIntersection(ee.At(i),ee.At(j),eHelpInt);
49  SetUnion(shared,eHelpInt,shared);
50  }
51  }
52  }
53 
54  // Alphabet of the generator must be under union Ei
55  bool ok = SetInclusion(gen.Alphabet(),unionset);
56  if (ok == false) {
57  std::stringstream errstr;
58  errstr << "Generator alphabet is not included in union of the alphabets";
59  throw Exception("ConditionalDecomposability", errstr.str(), 100);
60  }
61 
62  // Alphabet of the generator must contain Ek
63  ok = SetInclusion(ek,gen.Alphabet());
64  if (ok == false) {
65  std::stringstream errstr;
66  errstr << "Generator alphabet does not include the alphabet ek";
67  throw Exception("ConditionalDecomposability", errstr.str(), 100);
68  }
69 
70  // Ek must contain all shared events
71  ok = SetInclusion(shared,ek);
72  if (ok == false) {
73  std::stringstream errstr;
74  errstr << "Ek does not include all shared events";
75  throw Exception("ConditionalDecomposability", errstr.str(), 100);
76  }
77 
78  // Make copies of the generator
79  GeneratorVector copies;
80  EventSet unionsetNew = unionset; // unionset with new events
81  EventSet::Iterator eit;
82 
83  for (i = 0; i < ee.Size(); i++) {
84  EventSet uEiEk;
85  SetUnion(ee.At(i),ek,uEiEk);
86  EventSet EiEkdifUnionset;
87  SetDifference(unionset,uEiEk,EiEkdifUnionset);
88  Generator copy = gen;
89  for (eit = EiEkdifUnionset.Begin(); eit != EiEkdifUnionset.End(); ++eit) {
90  copy.EventRename(*eit,copy.UniqueEventName(""));
91  }
92  copies.Append(copy);
93  SetUnion(unionsetNew,copy.Alphabet(),unionsetNew);
94  }
95 
96  // Compute tilde G
97  Generator tildeG = copies.At(0);
98  for (i = 1; i < copies.Size(); i++) {
99  Parallel(tildeG,copies.At(i),tildeG);
100  }
101 
102  // Compute Inverse image of G
103  Generator invGen;
104  aInvProject(gen,unionsetNew,invGen);
105  Trim(tildeG);
106  Trim(invGen);
107  if (LanguageInclusion(tildeG,invGen)) {
108  Generator p;
109  proof = p; // the proof language is empty
110  return true;
111  }
112 
113  // Save proof automaton showing that it is not CD
114  LanguageComplement(invGen);
115  Generator proofGen;
116  LanguageIntersection(invGen,tildeG,proofGen);
117  Trim(proofGen);
118  //StateMin(proofGen,proofGen);
119  proofGen.ClearStateNames();
120  proof = proofGen;
121 
122  return false;
123 }
124 
125 
126 } // name space
127 
128 
129 

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