Skip to content
Snippets Groups Projects
RandomAutomatonFactory.h 2.63 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*
     * RandomAutomatonFactory.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. 2014
    
    Jan Trávníček's avatar
    Jan Trávníček committed
     *	  Author: Tomas Pecka
    
     */
    
    #ifndef RANDOM_AUTOMATON_FACTORY_H_
    #define RANDOM_AUTOMATON_FACTORY_H_
    
    
    #include <alib/deque>
    #include <alib/set>
    
    
    #include <automaton/FSM/NFA.h>
    
    
    namespace automaton {
    
    namespace generate {
    
    /**
     * Generator of random automata.
     *
     * @details
     * The underlying generation algorithm is from Leslie, T: Efficient Approaches to Subset Construction, 1995.
     */
    
    class RandomAutomatonFactory {
    public:
    
    	/**
    	 * Generates a random finite automaton.
    	 * @param statesCount number of states in the generated automaton
    	 * @param alphabet Input alphabet of the automaton
    	 * @param density density of the transition function
    	 * @return random nondeterministic finite automaton
    	 */
    	static automaton::NFA < > generateNFA( size_t statesCount, const ext::set<DefaultSymbolType> & alphabet, double density );
    
    	/**
    	 * \overload
    	 *
    	 * Generates a random finite automaton.
    	 * @param statesCount number of states in the generated automaton
    	 * @param alphabetSize size of the alphabet (1-26)
    	 * @param randomizedAlphabet selects random symbols from a-z range if true
    	 * @param density density of the transition function (0-1). 1 means every possible transition is created
    	 * @return random nondeterministic finite automaton
    	 */
    
    	static automaton::NFA < > generateNFA( size_t statesCount, size_t alphabetSize, bool randomizedAlphabet, double density );
    
    
    private:
    
    	/**
    	 * Leslie's connected NFA algorithm
    	 * @param n number of states
    	 * @param alphabet input alphabet
    	 * @param density density of the transition function (0-1). 1 means every possible transition is created
    	 */
    
    	static automaton::NFA < > LeslieConnectedNFA( size_t n, const ext::deque<DefaultSymbolType> & alphabet, double density );
    
    } /* namespace generate */
    
    } /* namespace automaton */
    
    
    #endif /* RANDOM_AUTOMATON_FACTORY_H_ */