op_bisimulation.h
Go to the documentation of this file.
1 /** @file op_bisimulation.h
2 
3 Methods to compute bisimulations on dynamic systems (represented
4 by a finite automaton).
5 The relevant algorithms are described in
6 J.-C. Fernandez, "An implementation of an efficient algorithm for
7 bisimulation equivalence", Science of Computer Programming, vol. 13,
8 pp. 219-236, 1990.
9 The class bisimulation supports these methods.
10 */
11 
12 /* FAU Discrete Event Systems Library (libfaudes)
13 
14  Copyright (C) 2006 Bernd Opitz
15  Exclusive copyright is granted to Klaus Schmidt
16 
17  This library is free software; you can redistribute it and/or
18  modify it under the terms of the GNU Lesser General Public
19  License as published by the Free Software Foundation; either
20  version 2.1 of the License, or (at your option) any later version.
21 
22  This library is distributed in the hope that it will be useful,
23  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25  Lesser General Public License for more details.
26 
27  You should have received a copy of the GNU Lesser General Public
28  License along with this library; if not, write to the Free Software
29  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
30 
31 #include "corefaudes.h"
32 #include "op_partition.h"
33 #include "op_debug.h"
34 #include <vector>
35 #include <map>
36 #include <string>
37 #include <sstream>
38 
39 #ifndef FAUDES_OP_BISIMULATION_H
40 #define FAUDES_OP_BISIMULATION_H
41 
42 
43 
44 namespace faudes {
45 
46 /**
47 * Computation of a bisimulation over a given generator.
48 * This funcion reates an instance of the class Bisimulation and starts the computation
49 * of the coarsest quasi-congruence on the given generator by calling the function Bisimulation::partition.
50 * A generator representing the result of the computation is generated.
51 *
52 * @param rGenOrig
53 * Original generator
54 * @param rMapStateToPartition
55 * Maps each state to its equivalence class
56 * @param rGenPart
57 * Quotient automaton representing the result of the computation. Each state corresponds to an
58 * equivalence class
59 * @param rNewPartitions
60 * Holds the indices of all equivalence classes
61 *
62 * @ingroup ObserverPlugin
63 */
64  void calcBisimulation(Generator& rGenOrig, std::map<Idx,Idx>& rMapStateToPartition, Generator& rGenPart, std::vector<Idx>& rNewPartitions);
65 
66 /**
67 * Computation of a bisimulation over a given generator.
68 * This funcion reates an instance of the class Bisimulation and starts the computation
69 * of the coarsest quasi-congruence on the given generator by calling the function Bisimulation::partition.
70 * See J.-C. Fernandez, “An implementation of an efficient algorithm for bisimulation equivalence,” Science of Computer Programming, vol. 13,
71 * pp. 219-236, 1990 for further details.
72 *
73 * @param rGenOrig
74 * Original generator
75 * @param rMapStateToPartition
76 * Maps each state to its equivalence class
77 * @param rNewPartitions
78 * Holds the indices of all equivalence classes
79 *
80 * @ingroup ObserverPlugin
81 */
82 void calcBisimulation(Generator& rGenOrig, std::map<Idx,Idx>& rMapStateToPartition, std::vector<Idx>& rNewPartitions);
83 
84 /**
85 * This class implements the algorithms needed for the computation of
86 * the coarsest quasi-congruence (=Bisimulation) of a given generator.
87 */
88 
89 class Bisimulation {
90 
91  public:
92 
93  /**
94  * Contructor
95  *
96  * @param g
97  * Original generator
98  */
100 
101 
102  /**
103  * Write W-tree to console
104  */
105  void writeW(void);
106 
107  /**
108  * Administration of the various steps of the computation of the coarsest quasi-congruence. An output
109  * generator that represents the resulting quotient automaton is also provided.
110  *
111  * @param rMapStateToPartition
112  * Maps each state to its equivalence class
113  * @param rGenPart
114  * Generator representing the result of the computation. Each state corresponds to an
115  * euivalence class
116  * @param rNewPartitions
117  * Holds the indices of all equivalence classes
118  */
119  void partition(std::map<Idx,Idx>& rMapStateToPartition, Generator& rGenPart, std::vector<Idx>& rNewPartitions);
120 
121 
122  /**
123  * Administration of the various steps of the computation of the coarsest quasi-congruence
124  *
125  * @param rMapStateToPartition
126  * Maps each state to its equivalence class
127  * @param rNewPartitions
128  * Holds the indices of all equivalence classes
129  */
130  void partition(std::map<Idx,Idx>& rMapStateToPartition, std::vector<Idx>& rNewPartitions);
131 
132  /**
133  * Write the current set of equivalence classes to console
134  */
135  void writeRo(void);
136 
137  private:
138 
139  /**
140  * Original Automaton
141  */
143 
144  /**
145  * Compute info-maps for two cosets P1 and P2. The current partition is
146  * stable with respect to their parent coset P.
147  *
148  * @param node
149  * Coset whose states are examined
150  * @param pSmallerPart
151  * Child coset P1 of P with smaller number of states
152  * @param pLargerPart
153  * Child coset P2 of P with larger number of states
154  * @param eIt
155  * Event
156  */
157  void computeInfoMaps(Partition& node, Partition* pSmallerPart, Partition* pLargerPart, EventSet::Iterator eIt);
158 
159  /**
160  * Compute info-maps for coset B
161  *
162  * @param B
163  * Coset for which the info-map is computed
164  * @param Bstates
165  * Coset whose states are examined
166  * @param eIt
167  * iterator to an event in a EventSet
168  * @param tb
169  * StateSet containing all the states that have a *eIt-transition into the coset B
170  */
171  void computeInfoMap(Partition& B, Partition& Bstates, EventSet::Iterator eIt, StateSet& tb);
172 
173  /**
174  * Check if a state has a eIt-transition into a coset denoted as node
175  *
176  * @param state
177  * State to be examined
178  * @param node
179  * Coset
180  * @param eIt
181  * Event
182  */
183  bool stateLeadsToPartition(Idx state, Partition& node, EventSet::Iterator eIt);
184 
185  /**
186  * W-tree. Contains all cosets ever created
187  */
188  std::map<Idx, Partition> W;
189 
190  /**
191  * Counter to assign unique indices to the cosets
192  */
194 
195  /**
196  * Contains the cosets of the current partition
197  */
198  std::vector<Partition*> ro;
199 
200  /**
201  * TransSet of original generator sorted by EvX2X1
202  */
204 
205 
206  /**
207  * Refine current partition with respect to partition B
208  *
209  * @param B
210  * Coset
211  */
212  void partitionClass(Partition& B);
213 
214  /**
215  * Refine current partition with respect to partition B and make use of the fact that
216  * the current partition is stable with respect to the parent coset of B.
217  *
218  * @param B
219  * Coset
220  */
221  void partitionSplitter (Partition& B);
222 
223 
224  /**
225  * Function needed for recursively plotting the W-tree to console. For debugging purpose
226  *
227  * @param node
228  * Coset
229  */
230  void writeNode(Partition& node);
231 
232  /**
233  * Holds the cosets that can possibly split cosets in ro
234  */
235  std::set<Partition*> roDividers;
236 };
237 
238 }
239 
240 #endif
241 

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