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.eqtests.basic;
018
019import java.util.Collection;
020
021import net.automatalib.automata.UniversalDeterministicAutomaton;
022import net.automatalib.automata.concepts.Output;
023import net.automatalib.util.automata.Automata;
024import net.automatalib.words.Word;
025import de.learnlib.api.EquivalenceOracle;
026import de.learnlib.oracles.DefaultQuery;
027
028
029
030public class SimulatorEQOracle<I,O>
031        implements EquivalenceOracle<UniversalDeterministicAutomaton<?, I, ?, ?, ?>, I, O> {
032        
033        private final UniversalDeterministicAutomaton<?, I, ?, ?, ?> reference;
034        private final Output<I, O> output;
035        
036        public <S,T,R extends UniversalDeterministicAutomaton<?, I, ?, ?, ?> & Output<I, O>>
037                        SimulatorEQOracle(R reference) {
038                this.reference = reference;
039                this.output = reference;
040        }
041
042        @Override
043        public DefaultQuery<I, O> findCounterExample(UniversalDeterministicAutomaton<?, I, ?, ?, ?> hypothesis, Collection<? extends I> alphabet) {
044                Word<I> sep = Automata.findSeparatingWord(reference, hypothesis, alphabet);
045                if(sep == null)
046                        return null;
047                O out = output.computeOutput(sep);
048                DefaultQuery<I,O> qry = new DefaultQuery<>(sep);
049                qry.answer(out);
050                return qry;
051        }
052        
053}