All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.automatalib.ts.comp.TSComposition Maven / Gradle / Ivy

Go to download

The core artifact of AutomataLib. This library contains concrete implementations for many of the automaton model interfaces defined in the API artifact, as well as abstract base classes that facilitate implementing new automaton model classes. Note that concrete algorithms (traversal, reachability analysis etc.) are not in the scope of this artifact.

There is a newer version: 0.11.0
Show newest version
/* Copyright (C) 2013-2018 TU Dortmund
 * This file is part of AutomataLib, http://www.automatalib.net/.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.automatalib.ts.comp;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import net.automatalib.commons.util.IPair;
import net.automatalib.ts.TransitionSystem;

public class TSComposition, TS2 extends TransitionSystem>
        implements TransitionSystem, I, IPair> {

    protected final TS1 ts1;
    protected final TS2 ts2;

    /**
     * Constructor.
     *
     * @param ts1
     *         first transition system
     * @param ts2
     *         second transition system
     */
    public TSComposition(TS1 ts1, TS2 ts2) {
        this.ts1 = ts1;
        this.ts2 = ts2;
    }

    @Override
    public Set> getInitialStates() {
        Collection init1 = ts1.getInitialStates();
        Collection init2 = ts2.getInitialStates();

        Set> result = new HashSet<>(init1.size() * init2.size());

        for (S1 s1 : init1) {
            for (S2 s2 : init2) {
                result.add(new IPair<>(s1, s2));
            }
        }

        return result;
    }

    @Override
    public Collection> getTransitions(IPair state, I input) {
        S1 s1 = state.first;
        S2 s2 = state.second;
        Collection trans1 = ts1.getTransitions(s1, input);
        Collection trans2 = ts2.getTransitions(s2, input);

        if (trans1.isEmpty() || trans2.isEmpty()) {
            return Collections.emptySet();
        }

        List> result = new ArrayList<>(trans1.size() * trans2.size());

        for (T1 t1 : trans1) {
            for (T2 t2 : trans2) {
                result.add(new IPair<>(t1, t2));
            }
        }

        return result;
    }

    @Override
    public IPair getSuccessor(IPair transition) {
        T1 t1 = transition.first;
        T2 t2 = transition.second;
        return new IPair<>(ts1.getSuccessor(t1), ts2.getSuccessor(t2));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy