001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of LearnLib, http://www.learnlib.de/.
003 * 
004 * LearnLib 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 * LearnLib 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 LearnLib; if not, see
015 * <http://www.gnu.de/documents/lgpl.en.html>.
016 */
017package de.learnlib.oracles;
018
019import net.automatalib.automata.concepts.SuffixOutput;
020import net.automatalib.automata.fsa.DFA;
021import net.automatalib.automata.transout.MealyMachine;
022import net.automatalib.words.Word;
023
024/**
025 * A membership oracle backed by an automaton. The automaton must implement
026 * the {@link SuffixOutput} concept, allowing to identify a suffix part in the output
027 * (relative to a prefix/suffix subdivision in the input).
028 *   
029 * @author Malte Isberner <malte.isberner@gmail.com>
030 *
031 * @param <I> input symbol class
032 * @param <O> (suffix) output class
033 */
034public class SimulatorOracle<I, O> extends AbstractSingleQueryOracle<I, O> {
035        
036        
037        public static class DFASimulatorOracle<I> extends SimulatorOracle<I,Boolean>
038                        implements DFAMembershipOracle<I> {
039                public DFASimulatorOracle(DFA<?,I> dfa) {
040                        super(dfa);
041                }
042        }
043        
044        public static class MealySimulatorOracle<I,O> extends SimulatorOracle<I,Word<O>>
045                        implements MealyMembershipOracle<I,O> {
046                public MealySimulatorOracle(MealyMachine<?,I,?,O> mealy) {
047                        super(mealy);
048                }
049        }
050        
051        
052        private final SuffixOutput<I, O> automaton;
053        
054        /**
055         * Constructor.
056         * @param automaton the suffix-observable automaton
057         */
058        public SimulatorOracle(SuffixOutput<I,O> automaton) {
059                this.automaton = automaton;
060        }
061        
062        /*
063         * (non-Javadoc)
064         * @see de.learnlib.api.MembershipOracle#processQueries(java.util.Collection)
065         */
066        @Override
067        public O answerQuery(Word<I> prefix, Word<I> suffix) {
068                return automaton.computeSuffixOutput(prefix, suffix);
069        }
070        
071}