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 */
017
018package de.learnlib.examples.mealy;
019
020import net.automatalib.automata.transout.MealyMachine;
021import net.automatalib.automata.transout.MutableMealyMachine;
022import net.automatalib.automata.transout.impl.compact.CompactMealy;
023import net.automatalib.words.Alphabet;
024import net.automatalib.words.impl.Alphabets;
025
026/**
027 * This class provides the example used in the paper ''Inferring Mealy Machines'' 
028 * by Muzammil Shahbaz and Roland Groz (see Figure 1).
029 * 
030 * @author Oliver Bauer <oliver.bauer@tu-dortmund.de>
031 */
032public class ExampleShahbazGroz {
033        
034        private static final class InstanceHolder {
035                public static final MealyMachine<?,Character,?,String> INSTANCE;
036                
037                static {
038                        INSTANCE = constructMachine();
039                }
040        }
041        
042    private final static Alphabet<Character> ALPHABET = Alphabets.characters('a', 'b');
043    
044    private final static String out_x = "x";
045    private final static String out_y = "y";
046    
047    public static Alphabet<Character> getInputAlphabet() {
048        return ALPHABET;
049    }
050    
051    public static MealyMachine<?,Character,?,String> getInstance() {
052        return InstanceHolder.INSTANCE;
053    }
054    
055    /**
056     * Construct and return a machine representation of this example
057     * 
058     * @return machine instance of the example
059     */
060    public static <S,A extends MutableMealyMachine<S,Character,?,String>>
061    A constructMachine(A fm) {
062        
063        S q0 = fm.addInitialState();
064        S q1 = fm.addState();
065        S q2 = fm.addState();
066        S q3 = fm.addState();
067        
068        fm.addTransition(q0, 'a', q1, out_x);
069        fm.addTransition(q0, 'b', q3, out_x);
070        
071        fm.addTransition(q1, 'a', q1, out_y);
072        fm.addTransition(q1, 'b', q2, out_x);
073        
074        fm.addTransition(q2, 'a', q3, out_x);
075        fm.addTransition(q2, 'b', q3, out_x);
076        
077        fm.addTransition(q3, 'a', q0, out_x);
078        fm.addTransition(q3, 'b', q0, out_x);
079        
080        /*
081         * In the paper the authors use the following counterexample
082         * to refine the first conjecture from an angluin for mealy machines:
083         * a b a b b a a
084         */
085        
086        return fm;
087    }
088    
089    public static CompactMealy<Character, String> constructMachine() {
090        return constructMachine(new CompactMealy<Character,String>(ALPHABET));
091    }
092}