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
14namespace faudes {
15
16bool 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) {
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
93bool 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)
virtual const T & At(const Position &pos) const
virtual void Append(const Type &rElem)
const EventSet & Alphabet(void) const
bool EventRename(Idx event, const std::string &rNewName)
bool IsDeterministic(void) const
bool SetInclusion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB)
Iterator End(void) const
Iterator Begin(void) const
bool IsConditionalDecomposable(const Generator &gen, const EventSetVector &ee, const EventSet &ek, Generator &proof)
void Trim(vGenerator &rGen)
bool LanguageInclusion(const Generator &rGen1, const Generator &rGen2)
void aInvProject(Generator &rGen, const EventSet &rProjectAlphabet)
void LanguageIntersection(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void LanguageComplement(Generator &rGen, const EventSet &rAlphabet)
uint32_t Idx
bool IsCD(const Generator &gen, const EventSetVector &ee, const EventSet &ek, const EventSet &unionset, Generator &proof)

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen