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.util.automata.copy;
018
019import java.util.Collection;
020
021import net.automatalib.automata.Automaton;
022import net.automatalib.automata.MutableAutomaton;
023import net.automatalib.automata.UniversalAutomaton;
024import net.automatalib.commons.util.mappings.Mapping;
025import net.automatalib.commons.util.mappings.Mappings;
026import net.automatalib.ts.TransitionSystem;
027import net.automatalib.ts.UniversalTransitionSystem;
028import net.automatalib.util.traversal.TraversalOrder;
029import net.automatalib.util.ts.TS;
030import net.automatalib.util.ts.traversal.TSTraversal;
031
032public abstract class AutomatonCopy {
033
034        
035        
036        public static <S1,I1,T1,S2,I2,T2,SP2,TP2>
037        Mapping<S1,S2> copyPlain(Automaton<S1,I1,T1> in,
038                        Collection<? extends I1> inputs,
039                        MutableAutomaton<S2,I2,T2,SP2,TP2> out,
040                        Mapping<? super I1,? extends I2> inputsMapping,
041                        Mapping<? super S1,? extends SP2> spMapping,
042                        Mapping<? super T1,? extends TP2> tpMapping) {
043                PlainAutomatonCopy<S1,I1,T1,S2,I2,T2,SP2,TP2> copy = new PlainAutomatonCopy<>(in, inputs, out, inputsMapping, spMapping, tpMapping);
044                copy.doCopy();
045                return copy.stateMapping;
046        }
047        
048        public static <S1,I1 extends I2,T1,S2,I2,SP2,TP2>
049        Mapping<S1,S2> copyPlain(Automaton<S1,I1,T1> in,
050                        Collection<? extends I1> inputs,
051                        MutableAutomaton<S2,I2,?,SP2,TP2> out,
052                        Mapping<? super S1,? extends SP2> spMapping,
053                        Mapping<? super T1,? extends TP2> tpMapping) {
054                return copyPlain(in, inputs, out, Mappings.<I1>identity(), spMapping, tpMapping);
055        }
056        
057        public static <S1,I1,T1,SP1,TP1,S2,I2,SP2,TP2>
058        Mapping<S1,S2> copyUniversalPlain(UniversalAutomaton<S1,I1,T1,SP1,TP1> in,
059                        Collection<? extends I1> inputs,
060                        MutableAutomaton<S2,I2,?,SP2,TP2> out,
061                        Mapping<? super I1,? extends I2> inputsMapping,
062                        Mapping<? super SP1,? extends SP2> spConversion,
063                        Mapping<? super TP1,? extends TP2> tpConversion) {
064                Mapping<? super S1,? extends SP2> spMapping = Mappings.compose(TS.stateProperties(in), spConversion);
065                Mapping<? super T1,? extends TP2> tpMapping = Mappings.compose(TS.transitionProperties(in), tpConversion);
066                return copyPlain(in, inputs, out, inputsMapping, spMapping, tpMapping);
067        }
068        
069        public static <S1,I1,SP1,TP1,S2,SP2,TP2>
070        Mapping<S1,S2> copyUniversalPlain(UniversalAutomaton<S1,I1,?,SP1,TP1> in,
071                        Collection<? extends I1> inputs,
072                        MutableAutomaton<S2,? super I1,?,SP2,TP2> out,
073                        Mapping<? super SP1,? extends SP2> spConversion,
074                        Mapping<? super TP1,? extends TP2> tpConversion) {
075                return copyUniversalPlain(in, inputs, out, Mappings.<I1>identity(), spConversion, tpConversion);
076        }
077        
078        public static <S1,I1,T1,SP1,TP1,S2,I2>
079        Mapping<S1,S2> copyUniversalPlain(UniversalAutomaton<S1,I1,T1,SP1,TP1> in,
080                        Collection<? extends I1> inputs,
081                        MutableAutomaton<S2,I2,?,? super SP1,? super TP1> out,
082                        Mapping<? super I1,? extends I2> inputsMapping) {
083                return copyPlain(in, inputs, out, inputsMapping, TS.stateProperties(in), TS.transitionProperties(in));
084        }
085        
086        public static <S1,I1,T1,SP1,TP1,S2>
087        Mapping<S1,S2> copyUniversalPlain(UniversalAutomaton<S1,I1,T1,SP1,TP1> in,
088                        Collection<? extends I1> inputs,
089                        MutableAutomaton<S2,? super I1,?,? super SP1,? super TP1> out) {
090                return copyPlain(in, inputs, out, Mappings.<I1>identity(), TS.stateProperties(in), TS.transitionProperties(in));
091        }
092        
093        
094        public static <S1,I1,T1,S2,I2,T2,SP2,TP2>
095        Mapping<S1,S2> copyTraversal(
096                        TraversalOrder order,
097                        int limit,
098                        TransitionSystem<S1,I1,T1> in,
099                        Collection<? extends I1> inputs,
100                        MutableAutomaton<S2,I2,T2,SP2,TP2> out,
101                        Mapping<? super I1,? extends I2> inputsMapping,
102                        Mapping<? super S1,? extends SP2> spMapping,
103                        Mapping<? super T1,? extends TP2> tpMapping) {
104                TraversalAutomatonCopy<S1,I1,T1,S2,I2,T2,SP2,TP2> copy = new TraversalAutomatonCopy<>(order, limit, in, inputs, out, inputsMapping, spMapping, tpMapping);
105                copy.doCopy();
106                return copy.stateMapping;
107        }
108        
109        public static <S1,I1 extends I2,T1,S2,I2,SP2,TP2>
110        Mapping<S1,S2> copyDfs(TransitionSystem<S1,I1,T1> in,
111                        Collection<? extends I1> inputs,
112                        MutableAutomaton<S2,I2,?,SP2,TP2> out,
113                        Mapping<? super S1,? extends SP2> spMapping,
114                        Mapping<? super T1,? extends TP2> tpMapping) {
115                return copyTraversal(TraversalOrder.DEPTH_FIRST, TSTraversal.NO_LIMIT, in, inputs, out, Mappings.<I1>identity(), spMapping, tpMapping);
116        }
117        
118        public static <S1,I1,T1,SP1,TP1,S2,I2,SP2,TP2>
119        Mapping<S1,S2> copyUniversalDfs(UniversalTransitionSystem<S1,I1,T1,SP1,TP1> in,
120                        Collection<? extends I1> inputs,
121                        MutableAutomaton<S2,I2,?,SP2,TP2> out,
122                        Mapping<? super I1,? extends I2> inputsMapping,
123                        Mapping<? super SP1,? extends SP2> spConversion,
124                        Mapping<? super TP1,? extends TP2> tpConversion) {
125                Mapping<? super S1,? extends SP2> spMapping = Mappings.compose(TS.stateProperties(in), spConversion);
126                Mapping<? super T1,? extends TP2> tpMapping = Mappings.compose(TS.transitionProperties(in), tpConversion);
127                return copyTraversal(TraversalOrder.DEPTH_FIRST, TSTraversal.NO_LIMIT, in, inputs, out, inputsMapping, spMapping, tpMapping);
128        }
129        
130        public static <S1,I1,SP1,TP1,S2,SP2,TP2>
131        Mapping<S1,S2> copyUniversalDfs(UniversalTransitionSystem<S1,I1,?,SP1,TP1> in,
132                        Collection<? extends I1> inputs,
133                        MutableAutomaton<S2,? super I1,?,SP2,TP2> out,
134                        Mapping<? super SP1,? extends SP2> spConversion,
135                        Mapping<? super TP1,? extends TP2> tpConversion) {
136                return copyUniversalDfs(in, inputs, out, Mappings.<I1>identity(), spConversion, tpConversion);
137        }
138        
139        public static <S1,I1,T1,SP1,TP1,S2,I2>
140        Mapping<S1,S2> copyUniversalDfs(UniversalTransitionSystem<S1,I1,T1,SP1,TP1> in,
141                        Collection<? extends I1> inputs,
142                        MutableAutomaton<S2,I2,?,? super SP1,? super TP1> out,
143                        Mapping<? super I1,? extends I2> inputsMapping) {
144                return copyTraversal(TraversalOrder.DEPTH_FIRST, TSTraversal.NO_LIMIT, in, inputs, out, inputsMapping, TS.stateProperties(in), TS.transitionProperties(in));
145        }
146        
147        public static <S1,I1,T1,SP1,TP1,S2>
148        Mapping<S1,S2> copyUniversalDfs(UniversalTransitionSystem<S1,I1,T1,SP1,TP1> in,
149                        Collection<? extends I1> inputs,
150                        MutableAutomaton<S2,? super I1,?,? super SP1,? super TP1> out) {
151                return copyTraversal(TraversalOrder.DEPTH_FIRST, TSTraversal.NO_LIMIT, in, inputs, out, Mappings.<I1>identity(), TS.stateProperties(in), TS.transitionProperties(in));
152        }
153        
154
155        
156        // TODO: Traversal copy
157        
158        
159        private AutomatonCopy() {
160        }
161
162}