Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
SynchronizingWordExistence.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <alib/set>
27#include <queue>
28
29#include <automaton/FSM/DFA.h>
31
32namespace automaton::properties {
33
38public:
45 template < class SymbolType, class StateType >
46 static bool exists ( const automaton::DFA < SymbolType, StateType > & dfa );
47};
48
49template < class SymbolType, class StateType >
51 /*
52 * It must hold that (1) <=> (2)
53 * (1) DFA is synchronizing
54 * (2) Foreach q1, q2 in Q, exists a word w such that \delta(q1, w) = \delta(q2, w)
55 */
56
57 /* Therefore the algorithm is as follows:
58 * Create a parallel run of the automaton with itseld
59 * All pairs (q1, q2) \in Q x Q MUST have a path to some state-pair (q, q).
60 * -> For every pair (q,q) run a BFS search and check that all pairs (q1, q2) are visited
61 */
62
64
65 std::queue < ext::pair < StateType, StateType > > q;
67
68 for ( const ext::pair < StateType, StateType > & state: cart.getStates ( ) ) {
69 if ( state.first != state.second )
70 continue;
71
72 visited.insert ( state );
73 q.push ( state );
74 }
75
76 while ( ! q.empty ( ) ) {
77 const ext::pair < StateType, StateType > cstate = std::move ( q.front ( ) );
78 q.pop ( );
79
80 for ( const auto & transition : cart.getTransitionsToState ( cstate ) ) {
81 const auto & srcState = transition.first.first;
82
83 if ( visited.count ( srcState ) == 0 ) {
84 visited.insert ( srcState );
85 q.push ( srcState );
86 }
87 }
88 }
89
90 return visited == cart.getStates ( );
91}
92
93} /* namespace automaton::properties */
94
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
const ext::set< StateType > & getStates() const &
Definition: DFA.h:134
ext::map< ext::pair< StateType, SymbolType >, StateType > getTransitionsToState(const StateType &to) const
Definition: DFA.h:494
Definition: SynchronizingWordExistence.h:37
static bool exists(const automaton::DFA< SymbolType, StateType > &dfa)
Definition: SynchronizingWordExistence.h:50
static automaton::NFA< SymbolType, ext::pair< StateType1, StateType2 > > intersection(const automaton::NFA< SymbolType, StateType1 > &first, const automaton::NFA< SymbolType, StateType2 > &second)
Definition: AutomataIntersectionCartesianProduct.h:95
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Definition: set.hpp:44
Definition: AllEpsilonClosure.h:44
q
Definition: SingleInitialStateEpsilonTransition.h:85
ext::set< ext::tuple< StateType, StateType, SymbolType > > visited
Definition: Compaction.h:81