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.ts.powerset; 018 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.HashSet; 022import java.util.List; 023import java.util.Set; 024 025import net.automatalib.ts.TransitionSystem; 026import net.automatalib.ts.abstractimpl.AbstractDTS; 027 028 029public class PowersetDTS<S, I, T> extends AbstractDTS<Set<S>, I, Collection<T>> { 030 031 private final TransitionSystem<S, I, T> ts; 032 033 public PowersetDTS(TransitionSystem<S,I,T> ts) { 034 this.ts = ts; 035 } 036 037 @Override 038 public Set<S> getInitialState() { 039 return ts.getInitialStates(); 040 } 041 042 @Override 043 public Collection<T> getTransition(Set<S> state, I input) { 044 List<T> result = new ArrayList<T>(); 045 for(S s : state) { 046 Collection<T> transitions = ts.getTransitions(s, input); 047 if(transitions != null) 048 result.addAll(transitions); 049 } 050 return result; 051 } 052 053 @Override 054 public Set<S> getSuccessor(Collection<T> transition) { 055 Set<S> result = new HashSet<S>(); 056 for(T trans : transition) 057 result.add(ts.getSuccessor(trans)); 058 return result; 059 } 060 061 @Override 062 public Set<S> getSuccessor(Set<S> state, I input) { 063 Set<S> result = new HashSet<S>(); 064 for(S s : state) { 065 Collection<T> transitions = ts.getTransitions(s, input); 066 if(transitions == null) 067 continue; 068 for(T t : transitions) 069 result.add(ts.getSuccessor(t)); 070 } 071 072 return result; 073 } 074}