From 038558a6f3ab3263cb94257142fa5655fbc90f1b Mon Sep 17 00:00:00 2001
From: Tomas Pecka <peckato1@fit.cvut.cz>
Date: Wed, 27 Mar 2019 12:40:07 +0100
Subject: [PATCH] Algo: Compute partitions of undistinguishable states

---
 .../properties/UndistinguishableStates.cpp    | 24 ++++++
 .../properties/UndistinguishableStates.h      | 85 +++++++++++++++++++
 2 files changed, 109 insertions(+)
 create mode 100644 alib2algo/src/automaton/properties/UndistinguishableStates.cpp
 create mode 100644 alib2algo/src/automaton/properties/UndistinguishableStates.h

diff --git a/alib2algo/src/automaton/properties/UndistinguishableStates.cpp b/alib2algo/src/automaton/properties/UndistinguishableStates.cpp
new file mode 100644
index 0000000000..bff0d7afa0
--- /dev/null
+++ b/alib2algo/src/automaton/properties/UndistinguishableStates.cpp
@@ -0,0 +1,24 @@
+/*
+* UndistinguishableStates.cpp
+ *
+ *  Created on: 27. 3. 2019
+ *	  Author: Tomas Pecka
+ */
+
+#include "UndistinguishableStates.h"
+#include <registration/AlgoRegistration.hpp>
+
+namespace automaton {
+
+namespace properties {
+
+auto UndistinguishableStatesDFA = registration::AbstractRegister < UndistinguishableStates, ext::set < ext::set < DefaultStateType > >, const automaton::DFA < > & > ( UndistinguishableStates::undistinguishable, "fsm" ).setDocumentation (
+"Computes the partitions of undistinguishable states states in given DFA.\n\
+\n\
+@param dfa finite automaton.\n\
+@return set of blocks of undistinguishable states" );
+
+} /* namespace properties */
+
+} /* namespace automaton */
+
diff --git a/alib2algo/src/automaton/properties/UndistinguishableStates.h b/alib2algo/src/automaton/properties/UndistinguishableStates.h
new file mode 100644
index 0000000000..fa3fba0fb3
--- /dev/null
+++ b/alib2algo/src/automaton/properties/UndistinguishableStates.h
@@ -0,0 +1,85 @@
+/*
+ * UndistinguishableStates.h
+ *
+ * This file is part of Algorithms library toolkit.
+ * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
+
+ * Algorithms library toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * Algorithms library toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with Algorithms library toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  Created on: 27. 3. 2019
+ *	  Author: Tomas Pecka
+ */
+
+#ifndef DISTINGUISHABLE_STATES_PARTITIONING_H_
+#define DISTINGUISHABLE_STATES_PARTITIONING_H_
+
+#include <alib/set>
+#include <alib/map>
+
+#include <automaton/FSM/DFA.h>
+
+#include <automaton/Automaton.h>
+
+#include <automaton/properties/DistinguishableStates.h>
+
+namespace automaton {
+
+namespace properties {
+
+/**
+ * Partition undistinguishable states in automata
+ *
+ * @sa DistinguishableStates
+ */
+class UndistinguishableStates {
+public:
+	/**
+	 * Creates state partitioning of undistinguishable states using DistinguishableStates algorithm
+	 *
+	 * @tparam SymbolType Type for input symbols.
+	 * @tparam StateType Type for states.
+	 * @param dfa automaton which states are to be partitioned
+	 *
+	 * @sa DistinguishableStates
+	 *
+	 * @return state partitioning of undistinguishable states
+	 */
+
+	template < class SymbolType, class StateType >
+	static ext::set < ext::set < StateType > > undistinguishable ( const automaton::DFA < SymbolType, StateType > & fsm );
+};
+
+template < class SymbolType, class StateType >
+ext::set < ext::set < StateType > > UndistinguishableStates::undistinguishable ( const automaton::DFA < SymbolType, StateType > & fsm ) {
+	const ext::set < ext::pair < StateType, StateType > > distinguishable = automaton::properties::DistinguishableStates::distinguishableStates ( fsm );
+	ext::set < ext::set < StateType > > res;
+
+	for ( const StateType & state : fsm.getStates ( ) ) {
+		ext::set < StateType > partition;
+
+		for ( const StateType & other : fsm.getStates ( ) )
+			if ( distinguishable.count ( ext::make_pair ( state, other ) ) == 0 )
+				partition.insert ( other );
+
+		res.insert ( partition );
+	}
+
+	return res;
+}
+
+} /* namespace properties */
+
+} /* namespace automaton */
+
+#endif /* DISTINGUISHABLE_STATES_H_ */
-- 
GitLab