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.comp;
018
019import net.automatalib.commons.util.Pair;
020import net.automatalib.ts.DeterministicTransitionSystem;
021import net.automatalib.ts.abstractimpl.AbstractDTS;
022
023public class DTSComposition<S1, S2, I, T1, T2,
024TS1 extends DeterministicTransitionSystem<S1, I, T1>,
025TS2 extends DeterministicTransitionSystem<S2, I, T2>> extends
026                AbstractDTS<Pair<S1, S2>, I, Pair<T1, T2>> {
027        
028        protected final TS1 ts1;
029        protected final TS2 ts2;
030        
031        public DTSComposition(TS1 ts1, TS2 ts2) {
032                this.ts1 = ts1;
033                this.ts2 = ts2;
034        }
035        
036        public TS1 getFirstTS() {
037                return ts1;
038        }
039        
040        public TS2 getSecondTS() {
041                return ts2;
042        }
043
044        @Override
045        public Pair<S1, S2> getInitialState() {
046                return Pair.make(ts1.getInitialState(), ts2.getInitialState());
047        }
048
049        @Override
050        public Pair<T1, T2> getTransition(Pair<S1, S2> state, I input) {
051                S1 s1 = state.getFirst();
052                S2 s2 = state.getSecond();
053                T1 t1 = ts1.getTransition(s1, input);
054                if(t1 == null)
055                        return null;
056                T2 t2 = ts2.getTransition(s2, input);
057                if(t2 == null)
058                        return null;
059                return Pair.make(t1, t2);
060        }
061
062        @Override
063        public Pair<S1, S2> getSuccessor(Pair<T1, T2> transition) {
064                T1 t1 = transition.getFirst();
065                T2 t2 = transition.getSecond();
066                return Pair.make(ts1.getSuccessor(t1),
067                                ts2.getSuccessor(t2));
068        }
069
070}