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.cache.mealy; 018 019import java.util.Collection; 020 021import net.automatalib.automata.transout.MealyMachine; 022import net.automatalib.incremental.mealy.IncrementalMealyBuilder; 023import net.automatalib.words.Word; 024import net.automatalib.words.WordBuilder; 025import de.learnlib.api.EquivalenceOracle; 026import de.learnlib.api.EquivalenceOracle.MealyEquivalenceOracle; 027import de.learnlib.oracles.DefaultQuery; 028 029/** 030 * An {@link EquivalenceOracle} that tests an hypothesis for consistency with the 031 * contents of a {@link MealyCacheOracle}. 032 * 033 * @author Malte Isberner <malte.isberner@gmail.com> 034 * 035 * @param <I> input symbol class 036 * @param <O> output symbol class 037 */ 038public class MealyCacheConsistencyTest<I, O> implements 039 MealyEquivalenceOracle<I,O> { 040 041 private final IncrementalMealyBuilder<I, O> incMealy; 042 043 /** 044 * Constructor. 045 * @param incMealy the {@link IncrementalMealyBuilder} data structure underlying the 046 * cache. 047 */ 048 public MealyCacheConsistencyTest(IncrementalMealyBuilder<I, O> incMealy) { 049 this.incMealy = incMealy; 050 } 051 052 /* 053 * (non-Javadoc) 054 * @see de.learnlib.api.EquivalenceOracle#findCounterExample(java.lang.Object, java.util.Collection) 055 */ 056 @Override 057 public DefaultQuery<I, Word<O>> findCounterExample( 058 MealyMachine<?, I, ?, O> hypothesis, Collection<? extends I> inputs) { 059 Word<I> w = incMealy.findSeparatingWord(hypothesis, inputs, false); 060 if(w == null) 061 return null; 062 WordBuilder<O> wb = new WordBuilder<O>(w.length()); 063 incMealy.lookup(w, wb); 064 DefaultQuery<I,Word<O>> result = new DefaultQuery<>(w); 065 result.answer(wb.toWord()); 066 return result; 067 } 068 069}