001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of AutomataLib, http://www.automatalib.net/. 003 * 004 * AutomataLib 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 * AutomataLib 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 AutomataLib; if not, see 015 * http://www.gnu.de/documents/lgpl.en.html. 016 */ 017package net.automatalib.automata.transout.impl; 018 019import net.automatalib.automata.base.fast.FastMutableNondet; 020import net.automatalib.automata.transout.MutableProbabilisticMealy; 021import net.automatalib.commons.util.Pair; 022import net.automatalib.words.Alphabet; 023 024public class FastProbMealy<I, O> 025 extends 026 FastMutableNondet<FastProbMealyState<O>, I, ProbMealyTransition<FastProbMealyState<O>, O>, Void, Pair<Float, O>> 027 implements 028 MutableProbabilisticMealy<FastProbMealyState<O>, I, ProbMealyTransition<FastProbMealyState<O>, O>, O> { 029 030 public FastProbMealy(Alphabet<I> inputAlphabet) { 031 super(inputAlphabet); 032 } 033 034 @Override 035 public FastProbMealyState<O> getSuccessor( 036 ProbMealyTransition<FastProbMealyState<O>, O> transition) { 037 return transition.getSuccessor(); 038 } 039 040 041 042 @Override 043 public O getTransitionOutput( 044 ProbMealyTransition<FastProbMealyState<O>, O> transition) { 045 return transition.getOutput(); 046 } 047 048 049 @Override 050 public Void getStateProperty(FastProbMealyState<O> state) { 051 return null; 052 } 053 054 @Override 055 public Pair<Float, O> getTransitionProperty( 056 ProbMealyTransition<FastProbMealyState<O>, O> transition) { 057 return Pair.make(transition.getProbability(), transition.getOutput()); 058 } 059 060 @Override 061 public void setTransitionOutput( 062 ProbMealyTransition<FastProbMealyState<O>, O> transition, O output) { 063 transition.setOutput(output); 064 } 065 066 @Override 067 public void setTransitionProbability( 068 ProbMealyTransition<FastProbMealyState<O>, O> transition, 069 float probability) { 070 transition.setProbability(probability); 071 } 072 073 @Override 074 public float getTransitionProbability( 075 ProbMealyTransition<FastProbMealyState<O>, O> transition) { 076 return transition.getProbability(); 077 } 078 079 @Override 080 public void setStateProperty(FastProbMealyState<O> state, Void property) { 081 } 082 083 @Override 084 public void setTransitionProperty( 085 ProbMealyTransition<FastProbMealyState<O>, O> transition, 086 Pair<Float, O> property) { 087 transition.setProbability(property.getFirst()); 088 transition.setOutput(property.getSecond()); 089 } 090 091 @Override 092 public ProbMealyTransition<FastProbMealyState<O>, O> createTransition( 093 FastProbMealyState<O> successor, Pair<Float, O> properties) { 094 return new ProbMealyTransition<FastProbMealyState<O>, O>(successor, properties.getSecond(), properties.getFirst()); 095 } 096 097 098 @Override 099 public ProbMealyTransition<FastProbMealyState<O>, O> copyTransition( 100 ProbMealyTransition<FastProbMealyState<O>, O> trans, 101 FastProbMealyState<O> succ) { 102 return new ProbMealyTransition<FastProbMealyState<O>,O>(succ, trans.getOutput(), trans.getProbability()); 103 } 104 105 @Override 106 protected FastProbMealyState<O> createState(Void property) { 107 return new FastProbMealyState<O>(inputAlphabet.size()); 108 } 109 110 111 @Override 112 public FastProbMealyState<O> addState() { 113 return addState((Void)null); 114 } 115 116 @Override 117 public FastProbMealyState<O> addInitialState() { 118 return addInitialState((Void)null); 119 } 120 121 public void addTransition(FastProbMealyState<O> src, I input, FastProbMealyState<O> successor, O output, float prob) { 122 addTransition(src, input, successor, Pair.make(prob, output)); 123 } 124 125}