omg_pseudodet.h
Go to the documentation of this file.
1 /** @file omg_pseudodet.h Pseudo-determinization algorithm for Rabin automata
2  *
3  * @ingroup OmegaautPlugin
4  */
5 
6 /*
7 
8  FAU Discrete Event Systems Library (libfaudes)
9 
10  Copyright (C) 2025 Thomas Moor
11  Exclusive copyright is granted to Klaus Schmidt
12 
13  This library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU Lesser General Public
15  License as published by the Free Software Foundation; either
16  version 2.1 of the License, or (at your option) any later version.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 
27 
28  This module implements the pseudo-determinization algorithm that converts
29  nondeterministic Rabin automata to deterministic Rabin automata.
30 
31  Copyrigth Changming Yang 2025
32  Non-exclusive copyright is granted to Thomas Moor
33 
34 */
35 
36 
37  #ifndef FAUDES_OMG_PSEUDODET_H
38  #define FAUDES_OMG_PSEUDODET_H
39 
40  #include "libfaudes.h"
41  #include "omg_rabinacc.h"
42  #include <cmath>
43  #include <vector>
44  #include <sstream>
45  #include <map>
46  #include <queue>
47  #include <functional>
48  #include <stack>
49  #include <set>
50 
51  namespace faudes {
52 
53  /**
54  * Enhanced state structure that includes deleted node information
55  */
57  public:
58  Idx originalState; ///< Original state ID
59  std::set<int> deletedNodesInPrevStep; ///< Node numbers deleted in previous step
60 
61  /// Default constructor
62  EnhancedState();
63 
64  /// Comparison operator
65  bool operator<(const EnhancedState& other) const;
66 
67  /// Equality operator
68  bool operator==(const EnhancedState& other) const;
69 
70  /// Debug string representation
71  std::string ToString() const;
72  };
73 
74  /**
75  * Tree node structure for labeled tree used in pseudo-determinization
76  */
78  public:
79  StateSet stateLabel; ///< S: state label
80  std::set<int> aSet; ///< A-set (using node numbers 1..N)
81  std::set<int> rSet; ///< R-set (using node numbers 1..N)
82  std::vector<Idx> children; ///< child nodes
83  int nodeNumber; ///< Fixed node number (1 to N)
84 
85  /// Node color for Rabin acceptance condition tracking
86  enum Color { WHITE, RED, GREEN } color;
87 
88  /// Default constructor
89  TreeNode();
90 
91  /// Constructor with node number
92  TreeNode(int number);
93 
94  /// Comparison operator for ordering
95  bool operator<(const TreeNode& other) const;
96 
97  /// Equality operator
98  bool operator==(const TreeNode& other) const;
99 
100  /// Debug string representation
101  std::string ToString() const;
102  };
103 
104  /**
105  * Labeled tree class for pseudo-determinization algorithm (Fixed N nodes)
106  *
107  * @ingroup OmgPlugin
108  */
110  public:
111  std::map<Idx, TreeNode> nodes; ///< Tree nodes (ID -> node)
112  std::map<int, Idx> numberToId; ///< Node number -> ID mapping
113  std::map<Idx, int> idToNumber; ///< ID -> node number mapping
114  std::set<int> deletedNodeNumbers; ///< Node numbers deleted in this step
115  Idx rootNode; ///< Root node ID
116  Idx nextNodeId; ///< Next available node ID
117  int maxNodeCount; ///< Maximum number of nodes (N)
118  std::vector<bool> nodeNumberUsed; ///< Track which node numbers are used
119 
120  static const Idx INVALID_NODE = 0; ///< Invalid node constant
121 
122  /// Default constructor
123  LabeledTree();
124 
125  /// Constructor with fixed node count
126  LabeledTree(int N);
127 
128  /// Create a new node with specific number, return its ID
129  Idx createNodeWithNumber(int nodeNumber);
130 
131  /// Create a new node with auto-assigned number, return its ID
132  Idx createNode();
133 
134  /// Delete a node and clean up references
135  void deleteNode(Idx nodeId);
136 
137  /// Get node number from ID
138  int getNodeNumber(Idx nodeId) const;
139 
140  /// Get node ID from number
141  Idx getNodeId(int nodeNumber) const;
142 
143  /// Check if node number exists in tree
144  bool hasNodeNumber(int nodeNumber) const;
145 
146  /// Debug string representation
147  std::string ToString() const;
148 
149  /// Comparison operator for ordering
150  bool operator<(const LabeledTree& other) const;
151 
152  /// Equality operator
153  bool operator==(const LabeledTree& other) const;
154  };
155 
156  /**
157  * Pseudo-determinization algorithm for Rabin automata (Paper Algorithm)
158  *
159  * This function converts a nondeterministic Rabin automaton to an equivalent
160  * deterministic Rabin automaton using the pseudo-determinization algorithm
161  * from the paper, with fixed node numbering and enhanced state tracking.
162  *
163  * @param rGen
164  * Input nondeterministic Rabin automaton
165  * @return
166  * Equivalent deterministic Rabin automaton
167  *
168  * @exception Exception
169  * - Input automaton has no initial states (id 201)
170  * - Algorithm complexity limits exceeded (id 202)
171  *
172  * @ingroup OmgPlugin
173  */
174  FAUDES_API void PseudoDet(const RabinAutomaton& rGen, RabinAutomaton& rRes);
175 
176  /**
177  * Compute tree signature for state equivalence checking (Enhanced)
178  *
179  * @param tree
180  * Input labeled tree
181  * @param deletedNodes
182  * Set of deleted node numbers
183  * @return
184  * String signature representing the tree structure and deleted nodes
185  *
186  * @ingroup OmgPlugin
187  */
188  FAUDES_API std::string ComputeTreeSignature(const LabeledTree& tree, const std::set<int>& deletedNodes);
189 
190 /**
191  * Remove epsilon transitions from a Rabin automaton
192  *
193  * This function removes epsilon transitions from a Rabin automaton by:
194  * 1. Removing epsilon self-loops
195  * 2. Merging epsilon transitions with other transitions
196  *
197  * @param rGen
198  * Input Rabin automaton with epsilon transitions
199  * @param rRes
200  * Output Rabin automaton without epsilon transitions
201  *
202  * @ingroup OmgPlugin
203  */
204 FAUDES_API void RemoveEps(const RabinAutomaton& rGen, RabinAutomaton& rRes);
205 
206  } // namespace faudes
207 
208  #endif // FAUDES_OMG_PSEUDODET_H
#define FAUDES_API
Definition: cfl_platform.h:85
Idx originalState
Original state ID.
Definition: omg_pseudodet.h:58
std::set< int > deletedNodesInPrevStep
Node numbers deleted in previous step.
Definition: omg_pseudodet.h:59
Idx nextNodeId
Next available node ID.
std::set< int > deletedNodeNumbers
Node numbers deleted in this step.
std::map< int, Idx > numberToId
Node number -> ID mapping.
std::map< Idx, int > idToNumber
ID -> node number mapping.
Idx rootNode
Root node ID.
std::vector< bool > nodeNumberUsed
Track which node numbers are used.
std::map< Idx, TreeNode > nodes
Tree nodes (ID -> node)
int maxNodeCount
Maximum number of nodes (N)
Color
Node color for Rabin acceptance condition tracking.
Definition: omg_pseudodet.h:86
std::vector< Idx > children
child nodes
Definition: omg_pseudodet.h:82
int nodeNumber
Fixed node number (1 to N)
Definition: omg_pseudodet.h:83
std::set< int > rSet
R-set (using node numbers 1..N)
Definition: omg_pseudodet.h:81
StateSet stateLabel
S: state label.
Definition: omg_pseudodet.h:79
std::set< int > aSet
A-set (using node numbers 1..N)
Definition: omg_pseudodet.h:80
void PseudoDet(const RabinAutomaton &rGen, RabinAutomaton &rRes)
std::string ComputeTreeSignature(const LabeledTree &tree, const std::set< int > &deletedNodes)
void RemoveEps(const RabinAutomaton &rGen, RabinAutomaton &rRes)
uint32_t Idx

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