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.automata.transout.impl;
018
019import java.util.List;
020
021import net.automatalib.automata.base.fast.FastMutableDet;
022import net.automatalib.automata.dot.DOTHelperMealy;
023import net.automatalib.automata.dot.DOTPlottableAutomaton;
024import net.automatalib.automata.graphs.TransitionEdge;
025import net.automatalib.automata.transout.MutableMealyMachine;
026import net.automatalib.automata.transout.abstractimpl.AbstractTransOutAutomaton;
027import net.automatalib.graphs.dot.GraphDOTHelper;
028import net.automatalib.words.Alphabet;
029import net.automatalib.words.Word;
030
031
032
033/**
034 * A fast implementation of a Mealy machine.
035 * 
036 * @author Malte Isberner <malte.isberner@cs.uni-dortmund.de>
037 *
038 * @param <I> input symbol class.
039 * @param <O> output symbol class.
040 */
041public class FastMealy<I,O> extends FastMutableDet<FastMealyState<O>,I,MealyTransition<FastMealyState<O>,O>,Void,O>
042        implements MutableMealyMachine<FastMealyState<O>, I, MealyTransition<FastMealyState<O>,O>, O>, DOTPlottableAutomaton<FastMealyState<O>,I,MealyTransition<FastMealyState<O>,O>> {
043
044
045        /**
046         * Constructor. Initializes a new (empty) Mealy machine with
047         * the given input alphabet.
048         * @param alphabet the input alphabet.
049         */
050        public FastMealy(Alphabet<I> alphabet) {
051                super(alphabet);
052        }
053
054        /*
055         * (non-Javadoc)
056         * @see de.ls5.ts.TransitionSystem#getSuccessor(java.lang.Object)
057         */
058        @Override
059        public FastMealyState<O> getSuccessor(
060                        MealyTransition<FastMealyState<O>, O> transition) {
061                return transition.getSuccessor();
062        }
063
064        /*
065         * (non-Javadoc)
066         * @see de.ls5.automata.transout.TransitionOutputAutomaton#trace(java.lang.Iterable, java.util.List)
067         */
068        @Override
069        public void trace(Iterable<I> input, List<O> output) {
070                AbstractTransOutAutomaton.trace(this, input, output);
071        }
072
073        /*
074         * (non-Javadoc)
075         * @see de.ls5.automata.transout.TransitionOutputAutomaton#trace(java.lang.Object, java.lang.Iterable, java.util.List)
076         */
077        @Override
078        public void trace(FastMealyState<O> state, Iterable<I> input, List<O> output) {
079                AbstractTransOutAutomaton.trace(this, state, input, output);
080        }
081
082        /*
083         * (non-Javadoc)
084         * @see de.ls5.automata.features.TransitionOutput#getTransitionOutput(java.lang.Object)
085         */
086        @Override
087        public O getTransitionOutput(
088                        MealyTransition<FastMealyState<O>, O> transition) {
089                return transition.getOutput();
090        }
091
092        /*
093         * (non-Javadoc)
094         * @see de.ls5.ts.UniversalTransitionSystem#getStateProperty(java.lang.Object)
095         */
096        @Override
097        public Void getStateProperty(FastMealyState<O> state) {
098                return null;
099        }
100
101        /*
102         * (non-Javadoc)
103         * @see de.ls5.ts.UniversalTransitionSystem#getTransitionProperty(java.lang.Object)
104         */
105        @Override
106        public O getTransitionProperty(
107                        MealyTransition<FastMealyState<O>, O> transition) {
108                return transition.getOutput();
109        }
110
111        /*
112         * (non-Javadoc)
113         * @see de.ls5.automata.MutableAutomaton#setStateProperty(java.lang.Object, java.lang.Object)
114         */
115        @Override
116        public void setStateProperty(FastMealyState<O> state, Void property) {
117        }
118
119        /*
120         * (non-Javadoc)
121         * @see de.ls5.automata.MutableAutomaton#setTransitionProperty(java.lang.Object, java.lang.Object)
122         */
123        @Override
124        public void setTransitionProperty(
125                        MealyTransition<FastMealyState<O>, O> transition, O property) {
126                transition.setOutput(property);
127        }
128
129        /*
130         * (non-Javadoc)
131         * @see de.ls5.automata.MutableAutomaton#createTransition(java.lang.Object, java.lang.Object)
132         */
133        @Override
134        public MealyTransition<FastMealyState<O>, O> createTransition(
135                        FastMealyState<O> successor, O properties) {
136                return new MealyTransition<FastMealyState<O>, O>(successor, properties);
137        }
138
139        /*
140         * (non-Javadoc)
141         * @see de.ls5.automata.MutableAutomaton#copyTransition(java.lang.Object, java.lang.Object)
142         */
143        @Override
144        public MealyTransition<FastMealyState<O>, O> copyTransition(
145                        MealyTransition<FastMealyState<O>, O> trans, FastMealyState<O> succ) {
146                return new MealyTransition<FastMealyState<O>,O>(succ, trans.getOutput());
147        }
148
149        /*
150         * (non-Javadoc)
151         * @see de.ls5.automata.features.MutableTransitionOutput#setTransitionOutput(java.lang.Object, java.lang.Object)
152         */
153        @Override
154        public void setTransitionOutput(
155                        MealyTransition<FastMealyState<O>, O> transition, O output) {
156                transition.setOutput(output);
157        }
158
159        /*
160         * (non-Javadoc)
161         * @see de.ls5.automata.base.fast.FastMutableDet#createState(java.lang.Object)
162         */
163        @Override
164        protected FastMealyState<O> createState(Void property) {
165                return new FastMealyState<O>(inputAlphabet.size());
166        }
167
168        /*
169         * (non-Javadoc)
170         * @see de.ls5.automata.features.SODetOutputAutomaton#computeSuffixOutput(java.lang.Iterable, java.lang.Iterable)
171         */
172        @Override
173        public Word<O> computeSuffixOutput(Iterable<I> prefix, Iterable<I> suffix) {
174                return AbstractTransOutAutomaton.computeSuffixOutput(this, prefix, suffix);
175        }
176
177        /*
178         * (non-Javadoc)
179         * @see de.ls5.automata.features.OutputAutomaton#computeOutput(java.lang.Iterable)
180         */
181        @Override
182        public Word<O> computeOutput(Iterable<I> input) {
183                return AbstractTransOutAutomaton.computeOutput(this, input);
184        }
185        
186        @Override
187        public FastMealyState<O> addInitialState() {
188                return addInitialState(null);
189        }
190        
191        @Override
192        public FastMealyState<O> addState() {
193                return addState(null);
194        }
195
196        @Override
197        public O getOutput(FastMealyState<O> state, I input) {
198                return AbstractTransOutAutomaton.getOutput(this, state, input);
199        }
200
201        @Override
202        public GraphDOTHelper<FastMealyState<O>, TransitionEdge<I, MealyTransition<FastMealyState<O>, O>>> getDOTHelper() {
203                return new DOTHelperMealy<FastMealyState<O>, I, MealyTransition<FastMealyState<O>,O>, O>(this);
204        }
205}