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 */ 017 018package de.learnlib.oracles; 019 020import java.util.Collection; 021 022import net.automatalib.words.Word; 023import de.learnlib.api.MembershipOracle; 024import de.learnlib.api.Query; 025import de.learnlib.statistics.Counter; 026import de.learnlib.statistics.StatisticOracle; 027 028/** 029 * Counts queries. 030 * 031 * @author falkhowar 032 */ 033public class CounterOracle<I,O> implements StatisticOracle<I,O> { 034 035 public static class DFACounterOracle<I> extends CounterOracle<I,Boolean> 036 implements DFAMembershipOracle<I> { 037 public DFACounterOracle(MembershipOracle<I, Boolean> nextOracle, 038 String name) { 039 super(nextOracle, name); 040 } 041 } 042 043 public static class MealyCounterOracle<I,O> extends CounterOracle<I,Word<O>> 044 implements MealyMembershipOracle<I,O> { 045 public MealyCounterOracle(MembershipOracle<I, Word<O>> nextOracle, 046 String name) { 047 super(nextOracle, name); 048 } 049 } 050 051 private final Counter counter; 052 053 private MembershipOracle<I,O> nextOracle; 054 055 public CounterOracle(MembershipOracle<I,O> nextOracle, String name) { 056 this.nextOracle = nextOracle; 057 this.counter = new Counter(name, "queries"); 058 } 059 060 @Override 061 public void processQueries(Collection<? extends Query<I, O>> queries) { 062 this.counter.increment(queries.size()); 063 nextOracle.processQueries(queries); 064 } 065 066 @Override 067 public Counter getStatisticalData() { 068 return this.counter; 069 } 070 071 @Override 072 public void setNext(MembershipOracle<I, O> next) { 073 this.nextOracle = next; 074 } 075}