con_decomposability.cpp

Go to the documentation of this file.
00001 /** @file con_decomposability.cpp Conditionaldecomposability */
00002 
00003 /*
00004  * Implementation of the Conditionally decomposable algorithm
00005  *
00006  * Copyright (C) 2011  Tomas Masopust
00007  *
00008  */
00009 
00010 
00011 #include "con_decomposability.h"
00012 #include <vector>
00013 
00014 namespace faudes {
00015 
00016 bool IsConditionalDecomposable(const Generator& gen, const EventSetVector& rAlphabets, const EventSet& ek, Generator& proof) {
00017   FD_DF("Conditionaldecomposability checking...");
00018   
00019   // the generator must be deterministic
00020   if (gen.IsDeterministic() == false) {
00021     std::stringstream errstr;
00022     errstr << "Generator must be deterministic, but is nondeterministic";
00023     throw Exception("ConditionalDecomposability", errstr.str(), 201);
00024   }
00025 
00026   // at least two alphabets in the vector
00027   if (rAlphabets.Size() < 2) {
00028     std::stringstream errstr;
00029     errstr << "At least two alphabets must be included in the EventSetVector";
00030     throw Exception("ConditionalDecomposability", errstr.str(), 201);
00031   }
00032 
00033   Idx i;
00034       EventSetVector ee = rAlphabets;   // Vector of input alphabets
00035   EventSet unionset;      // contains union of Ei
00036   EventSet shared;      // contains union of intersections
00037 
00038   // Compute unionset
00039   for (i = 0; i < ee.Size(); i++) {
00040     SetUnion(unionset,ee.At(i),unionset);
00041   }
00042 
00043   // Compute the set of shared events
00044   for (i = 0; i < ee.Size(); i++) {
00045     for (Idx j = 0; j < ee.Size(); j++) {
00046       if (j != i) {
00047     EventSet eHelpInt;
00048     SetIntersection(ee.At(i),ee.At(j),eHelpInt);
00049     SetUnion(shared,eHelpInt,shared);
00050       }
00051     }
00052   }
00053 
00054     // Alphabet of the generator must be under union Ei 
00055   bool ok = SetInclusion(gen.Alphabet(),unionset);
00056     if (ok == false) {
00057     std::stringstream errstr;
00058     errstr << "Generator alphabet is not included in union of the alphabets";
00059     throw Exception("ConditionalDecomposability", errstr.str(), 100);
00060     }
00061 
00062     // Alphabet of the generator must contain Ek
00063   ok = SetInclusion(ek,gen.Alphabet());
00064     if (ok == false) {
00065     std::stringstream errstr;
00066     errstr << "Generator alphabet does not include the alphabet ek";
00067     throw Exception("ConditionalDecomposability", errstr.str(), 100);
00068     }
00069 
00070     // Ek must contain all shared events
00071   ok = SetInclusion(shared,ek);
00072     if (ok == false) {
00073     std::stringstream errstr;
00074     errstr << "Ek does not include all shared events";
00075     throw Exception("ConditionalDecomposability", errstr.str(), 100);
00076     }
00077 
00078   // Make copies of the generator
00079   GeneratorVector copies;
00080   EventSet unionsetNew = unionset;    // unionset with new events
00081   EventSet::Iterator eit;
00082 
00083   for (i = 0; i < ee.Size(); i++) {
00084     EventSet uEiEk;
00085     SetUnion(ee.At(i),ek,uEiEk);
00086     EventSet EiEkdifUnionset;
00087     SetDifference(unionset,uEiEk,EiEkdifUnionset);
00088     Generator copy = gen;
00089     for (eit = EiEkdifUnionset.Begin(); eit != EiEkdifUnionset.End(); ++eit) {
00090       copy.EventRename(*eit,copy.UniqueEventName(""));
00091     }
00092     copies.Append(copy);
00093     SetUnion(unionsetNew,copy.Alphabet(),unionsetNew);
00094   }
00095   
00096   // Compute tilde G
00097   Generator tildeG = copies.At(0);
00098   for (i = 1; i < copies.Size(); i++) {
00099     Parallel(tildeG,copies.At(i),tildeG);
00100   }
00101 
00102   // Compute Inverse image of G
00103   Generator invGen;
00104   aInvProject(gen,unionsetNew,invGen);
00105   Trim(tildeG);
00106   Trim(invGen);
00107   if (LanguageInclusion(tildeG,invGen)) {
00108     Generator p;
00109     proof = p;  // the proof language is empty
00110     return true;
00111   }
00112   
00113   // Save proof automaton showing that it is not CD
00114   LanguageComplement(invGen);
00115   Generator proofGen;
00116   LanguageIntersection(invGen,tildeG,proofGen);
00117   Trim(proofGen);
00118   //StateMin(proofGen,proofGen);
00119   proofGen.ClearStateNames();
00120   proof = proofGen;
00121   
00122   return false;
00123 }
00124 
00125 
00126 } // name space 
00127 
00128 
00129 

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen