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.List;
022
023import net.automatalib.commons.util.nid.NumericID;
024import net.automatalib.ts.TransitionSystem;
025import net.automatalib.ts.abstractimpl.AbstractDTS;
026
027
028public class FastPowersetDTS<S extends NumericID, I, T> extends
029                AbstractDTS<FastPowersetState<S>, I, Collection<T>> {
030        
031        private final TransitionSystem<S, I, T> ts;
032        
033        public FastPowersetDTS(TransitionSystem<S,I,T> ts) {
034                this.ts = ts;
035        }
036
037        @Override
038        public FastPowersetState<S> getInitialState() {
039                FastPowersetState<S> result = new FastPowersetState<S>();
040                for(S init : ts.getInitialStates())
041                        result.add(init, init.getId());
042                return result;
043        }
044
045        @Override
046        public Collection<T> getTransition(FastPowersetState<S> state, I input) {
047                List<T> result = new ArrayList<T>();
048                for(S s : state) {
049                        Collection<T> transitions = ts.getTransitions(s, input);
050                        if(transitions != null)
051                                result.addAll(transitions);
052                }
053                return result;
054        }
055
056        @Override
057        public FastPowersetState<S> getSuccessor(Collection<T> transition) {
058                FastPowersetState<S> succ = new FastPowersetState<S>();
059                for(T t : transition) {
060                        S succS = ts.getSuccessor(t);
061                        succ.add(succS, succS.getId());
062                }
063                
064                return succ;
065        }
066
067        @Override
068        public FastPowersetState<S> getSuccessor(FastPowersetState<S> state, I input) {
069                FastPowersetState<S> succ = new FastPowersetState<S>();
070                
071                for(S s : state) {
072                        Collection<S> succs = ts.getSuccessors(s, input);
073                        if(succs == null)
074                                continue;
075                        
076                        for(S succS : succs)
077                                succ.add(succS, succS.getId());
078                }
079                
080                return succ;
081        }
082        
083        
084        
085
086}