001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of AutomataLib, http://www.automatalib.net/.
003 * 
004 * AutomataLib is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Lesser General Public
006 * License version 3.0 as published by the Free Software Foundation.
007 * 
008 * AutomataLib is distributed in the hope that it will be useful,
009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
011 * Lesser General Public License for more details.
012 * 
013 * You should have received a copy of the GNU Lesser General Public
014 * License along with AutomataLib; if not, see
015 * http://www.gnu.de/documents/lgpl.en.html.
016 */
017package net.automatalib.util.automata.random;
018
019import java.util.Collection;
020import java.util.Random;
021
022import net.automatalib.automata.MutableDeterministic;
023import net.automatalib.util.automata.Automata;
024
025public abstract class RandomAutomata {
026
027        public static <S,I,T,SP,TP,A extends MutableDeterministic<S, I, T, SP, TP>>
028        A randomDeterministic(
029                        Random rand,
030                        int numStates,
031                        Collection<? extends I> inputs,
032                        Collection<? extends SP> stateProps,
033                        Collection<? extends TP> transProps,
034                        A out) {
035                return randomDeterministic(rand, numStates, inputs, stateProps, transProps, out, true);
036        }
037        
038        public static <S,I,T,SP,TP,A extends MutableDeterministic<S, I, T, SP, TP>>
039        A randomDeterministic(
040                        Random rand,
041                        int numStates,
042                        Collection<? extends I> inputs,
043                        Collection<? extends SP> stateProps,
044                        Collection<? extends TP> transProps,
045                        A out, boolean minimize) {
046                
047                RandomDeterministicAutomatonGenerator<S, I, T, SP, TP, A> gen
048                        = new RandomDeterministicAutomatonGenerator<>(rand, inputs, stateProps, transProps, out);
049                        
050                gen.addStates(numStates);
051                gen.addTransitions();
052                gen.chooseInitial();
053                
054                
055                if(minimize)
056                        Automata.invasiveMinimize(out, inputs);
057                
058                return out;
059        }
060        
061        // Prevent inheritance
062        private RandomAutomata() {}
063
064}