diff --git a/alib2algo/src/automaton/properties/UndistinguishableStates2.cpp b/alib2algo/src/automaton/properties/UndistinguishableStates2.cpp deleted file mode 100644 index f7ff1ea5f1d88f85104601a7ac5c483619c27183..0000000000000000000000000000000000000000 --- a/alib2algo/src/automaton/properties/UndistinguishableStates2.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* -* UndistinguishableStates2.cpp - * - * Created on: 27. 3. 2019 - * Author: Tomas Pecka - */ - -#include "UndistinguishableStates2.h" -#include <registration/AlgoRegistration.hpp> - -namespace { - -auto UndistinguishableStates2DFA = registration::AbstractRegister < automaton::properties::UndistinguishableStates2, ext::set < ext::set < DefaultStateType > >, const automaton::DFA < > & > ( automaton::properties::UndistinguishableStates2::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" ); - -auto UndistinguishableStates2DFTA = registration::AbstractRegister < automaton::properties::UndistinguishableStates2, ext::set < ext::set < DefaultStateType > >, const automaton::DFTA < > & > ( automaton::properties::UndistinguishableStates2::undistinguishable, "fta" ).setDocumentation ( -"Computes the partitions of undistinguishable states states in given DFTA.\n\ -\n\ -@param dfta finite tree automaton.\n\ -@return set of blocks of undistinguishable states" ); - -} /* namespace */ diff --git a/alib2algo/src/automaton/properties/UndistinguishableStates2.h b/alib2algo/src/automaton/properties/UndistinguishableStates2.h deleted file mode 100644 index 7775afe1eb79f67781234ab8faa2346f8f93bc99..0000000000000000000000000000000000000000 --- a/alib2algo/src/automaton/properties/UndistinguishableStates2.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * UndistinguishableStates2.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/TA/DFTA.h> - -#include <automaton/properties/DistinguishableStates.h> - -namespace automaton { - -namespace properties { - -/** - * Partition undistinguishable states in automata - * - * @sa DistinguishableStates - */ -class UndistinguishableStates2 { -public: - /** - * Creates state partitioning of undistinguishable states using DistinguishableStates algorithm - * - * @tparam T Type of the parameter automaton. - * @param dfta automaton which states are to be partitioned - * - * @sa DistinguishableStates - * - * @return state partitioning of undistinguishable states - */ - template < class T > - static ext::set < ext::set < typename T::StateType > > undistinguishable ( const T & fsm ); -}; - -template < class T > -ext::set < ext::set < typename T::StateType > > UndistinguishableStates2::undistinguishable ( const T & fsm ) { - using StateType = typename T::StateType; - - const ext::set < ext::pair < StateType, StateType > > distinguishable = automaton::properties::DistinguishableStates::distinguishable ( 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_ */ diff --git a/alib2aux/src/relation/RelationComplement.cpp b/alib2aux/src/relation/RelationComplement.cpp new file mode 100644 index 0000000000000000000000000000000000000000..31d0de801bc2a453e01c6ad32a85c16b656c423d --- /dev/null +++ b/alib2aux/src/relation/RelationComplement.cpp @@ -0,0 +1,23 @@ +/* +* RelationComplement.cpp + * + * Created on: 2. 10. 2019 + * Author: Jan Travnicek + */ + +#include "RelationComplement.h" +#include <registration/AlgoRegistration.hpp> + +#include <object/Object.h> + +namespace { + +auto RelationComplement = registration::AbstractRegister < relation::RelationComplement, ext::set < ext::pair < object::Object, object::Object > >, const ext::set < ext::pair < object::Object, object::Object > > &, const ext::set < object::Object > & > ( relation::RelationComplement::complement, "relation", "universe" ).setDocumentation ( +"Computes the complement relation in given universe\n\ +\n\ +@param relation the original relation\n\ +@param universe the universe of items participating in the relation\n\ +\n\ +return relation where items in relation are those which that were not in relation and otherwise"); + +} /* namespace */ diff --git a/alib2aux/src/relation/RelationComplement.h b/alib2aux/src/relation/RelationComplement.h new file mode 100644 index 0000000000000000000000000000000000000000..5149d4b4b4555372db9ed9c2659daa93368dd403 --- /dev/null +++ b/alib2aux/src/relation/RelationComplement.h @@ -0,0 +1,65 @@ +/* + * RelationComplement.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: 2. 10. 2019 + * Author: Jan Travnicek + */ + +#ifndef RELATION_COMPLEMENT_H_ +#define RELATION_COMPLEMENT_H_ + +#include <alib/set> +#include <alib/pair> + +namespace relation { + +/** + * Computes the complement relation in given universe. + */ +class RelationComplement { +public: + /** + * Computes the complement relation in given universe + * + * @tparam T Type of the items in relation. + * + * @param relation the original relation + * @param universe the universe of items participating in the relation + * + * @return relation where items in relation are those which that were not in relation and otherwise + */ + template < class T > + static ext::set < ext::pair < T, T > > complement ( const ext::set < ext::pair < T, T > > & relation, const ext::set < T > & universe ); +}; + +template < class T > +ext::set < ext::pair < T, T > > RelationComplement::complement ( const ext::set < ext::pair < T, T > > & relation, const ext::set < T > & universe ) { + ext::set < ext::pair < T, T > > res; + + for ( const T & state : universe ) + for ( const T & other : universe ) + if ( ! relation.contains ( ext::make_pair ( state, other ) ) ) + res.insert ( ext::make_pair ( state, other ) ); + + return res; +} + +} /* namespace relation */ + +#endif /* RELATION_COMPLEMENT_H_ */