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