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, 2015 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& ee, 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  Idx n = ee.Size(); // the number of components
27  if (n < 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  // Compute the union of all Ei
34  EventSet unionset;
35  for (Idx i = 0; i < ee.Size(); ++i) {
36  unionset = unionset + ee.At(i);
37  }
38 
39  // Compute the set of shared events
40  EventSet shared;
41  for (Idx i = 0; i < ee.Size(); i++) {
42  for (Idx j = 0; j < ee.Size(); j++) {
43  if (j != i) {
44  shared = shared + ( ee.At(i) * ee.At(j) );
45  }
46  }
47  }
48 
49  // Alphabet of the generator must be under union Ei
50  bool ok = SetInclusion(gen.Alphabet(),unionset);
51  if (ok == false) {
52  std::stringstream errstr;
53  errstr << "Generator alphabet is not included in union of the alphabets";
54  throw Exception("ConditionalDecomposability", errstr.str(), 100);
55  }
56 
57  // Alphabet of the generator must contain Ek
58  ok = SetInclusion(ek,gen.Alphabet());
59  if (ok == false) {
60  std::stringstream errstr;
61  errstr << "Generator alphabet does not include the alphabet ek";
62  throw Exception("ConditionalDecomposability", errstr.str(), 100);
63  }
64 
65  // Ek must contain all shared events
66  ok = SetInclusion(shared,ek);
67  if (ok == false) {
68  std::stringstream errstr;
69  errstr << "Ek does not include all shared events";
70  throw Exception("ConditionalDecomposability", errstr.str(), 100);
71  }
72 
73  //call IsCD for each pair (Ei, \cup_{j<>i} Ej)
74  for (Idx i = 0; i < n; ++i) {
75  EventSetVector eev;
76  eev.Append(ee.At(i));
77  //union of Ej for j<>i
78  EventSet uset;
79  for (Idx j = 0; j < n; ++j) {
80  if ( i == j ) continue;
81  uset = uset + ee.At(j);
82  }
83  eev.Append(uset);
84  Generator p;
85  proof = p;
86  if ( IsCD(gen,eev,ek,unionset,proof) == false ) return false;
87  }
88 
89  return true;
90 }
91 
92 //here we have only two alphabets
93 bool IsCD(
94  const Generator& gen,
95  const EventSetVector& ee,
96  const EventSet& ek,
97  const EventSet& unionset,
98  Generator& proof)
99 {
100 
101  Idx i;
102 
103  // Make copies of the generator
104  GeneratorVector copies;
105  EventSet unionsetNew = unionset; // unionset with new events
106  EventSet::Iterator eit;
107 
108  for (i = 0; i < ee.Size(); ++i) {
109  EventSet notInEiEk;
110  notInEiEk = unionset - ( ee.At(i) + ek );
111  Generator copy = gen;
112  for (eit = notInEiEk.Begin(); eit != notInEiEk.End(); ++eit) {
113  copy.EventRename(*eit,copy.UniqueEventName(""));
114  }
115  copies.Append(copy);
116  unionsetNew = unionsetNew + copy.Alphabet();
117  }
118 
119  // Compute tilde G
120  Generator tildeG = copies.At(0);
121  for (i = 1; i < copies.Size(); ++i) {
122  Parallel(tildeG,copies.At(i),tildeG);
123  }
124 
125  // Compute the inverse image of G
126  Generator invGen;
127  aInvProject(gen,unionsetNew,invGen);
128  Trim(tildeG);
129  Trim(invGen);
130  if (LanguageInclusion(tildeG,invGen)) {
131  return true;
132  }
133 
134  // Save proof automaton showing that it is not CD
135  LanguageComplement(invGen);
136  Generator proofGen;
137  LanguageIntersection(invGen,tildeG,proofGen);
138  Trim(proofGen);
139  proofGen.ClearStateNames();
140  proof = proofGen;
141 
142  return false;
143 }
144 
145 
146 } // name space
147 
148 
149 
#define FD_DF(message)
Debug: optional report on user functions.
Faudes exception class.
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
Vector template.
virtual const T & At(const Position &pos) const
Access element.
virtual void Append(const Type &rElem)
Append specified entry.
Idx Size(void) const
Get size of vector.
Base class of all FAUDES generators.
const EventSet & Alphabet(void) const
Return const reference to alphabet.
bool EventRename(Idx event, const std::string &rNewName)
Rename event in this generator.
void ClearStateNames(void)
Remove all names from generator's StateSymbolTable.
bool IsDeterministic(void) const
Check if generator is deterministic.
Conditional Decomposability.
bool SetInclusion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB)
Definition: cfl_baseset.h:1128
Iterator End(void) const
Iterator to the end of set.
Definition: cfl_baseset.h:1896
Iterator Begin(void) const
Iterator to the begin of set.
Definition: cfl_baseset.h:1891
bool IsConditionalDecomposable(const Generator &gen, const EventSetVector &ee, const EventSet &ek, Generator &proof)
Conditionaldecomposability Checking Algorithm.
void Trim(vGenerator &rGen)
RTI wrapper function.
bool LanguageInclusion(const Generator &rGen1, const Generator &rGen2)
Test language inclusion, Lm1<=Lm2.
void aInvProject(Generator &rGen, const EventSet &rProjectAlphabet)
Inverse projection.
void LanguageIntersection(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Language intersection.
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
void LanguageComplement(Generator &rGen, const EventSet &rAlphabet)
Language complement wrt specified alphabet.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
bool IsCD(const Generator &gen, const EventSetVector &ee, const EventSet &ek, const EventSet &unionset, Generator &proof)

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen