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

net.automatalib.util.ts.TS Maven / Gradle / Ivy

Go to download

This artifact provides various common utility operations for analyzing and manipulating automata and graphs, such as traversal, minimization and copying.

There is a newer version: 0.11.0
Show newest version
/* Copyright (C) 2013-2019 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.util.ts;

import java.util.Collection;
import java.util.Iterator;
import java.util.function.Function;

import net.automatalib.ts.DeterministicTransitionSystem;
import net.automatalib.ts.TransitionSystem;
import net.automatalib.ts.UniversalTransitionSystem;
import net.automatalib.util.ts.iterators.AllDefinedInputsIterator;
import net.automatalib.util.ts.iterators.AllUndefinedInputsIterator;
import net.automatalib.util.ts.iterators.DefinedInputsIterator;
import net.automatalib.util.ts.iterators.UndefinedInputsIterator;
import net.automatalib.util.ts.traversal.BFSOrderIterator;

public class TS {

    protected TS() {
    }

    public static  Iterable bfsOrder(TransitionSystem ts, Collection inputs) {
        return () -> bfsOrderIterator(ts, inputs);
    }

    public static  Iterator bfsOrderIterator(TransitionSystem ts, Collection inputs) {
        return new BFSOrderIterator<>(ts, inputs);
    }

    public static  Function stateProperties(final UniversalTransitionSystem uts) {
        return uts::getStateProperty;
    }

    public static  Function transitionProperties(final UniversalTransitionSystem uts) {
        return uts::getTransitionProperty;
    }

    public static  Iterable definedInputs(final DeterministicTransitionSystem dts,
                                                   final S state,
                                                   final Iterable inputs) {
        return () -> definedInputsIterator(dts, state, inputs.iterator());
    }

    public static  Iterator definedInputsIterator(TransitionSystem ts,
                                                           S state,
                                                           Iterator inputsIt) {
        return new DefinedInputsIterator<>(ts, state, inputsIt);
    }

    public static  Iterable> allDefinedInputs(final TransitionSystem ts,
                                                                      final Iterable states,
                                                                      final Iterable inputs) {
        return () -> allDefinedInputsIterator(ts, states.iterator(), inputs);
    }

    public static  Iterator> allDefinedInputsIterator(TransitionSystem ts,
                                                                              Iterator stateIt,
                                                                              Iterable inputs) {
        return new AllDefinedInputsIterator<>(stateIt, ts, inputs);
    }

    public static  Iterable undefinedInputs(final TransitionSystem ts,
                                                     final S state,
                                                     final Iterable inputs) {
        return () -> undefinedInputsIterator(ts, state, inputs.iterator());
    }

    public static  Iterator undefinedInputsIterator(TransitionSystem ts,
                                                             S state,
                                                             Iterator inputsIt) {
        return new UndefinedInputsIterator<>(ts, state, inputsIt);
    }

    public static  Iterable> allUndefinedTransitions(final TransitionSystem ts,
                                                                             final Iterable states,
                                                                             final Iterable inputs) {
        return () -> allUndefinedTransitionsIterator(ts, states.iterator(), inputs);
    }

    public static  Iterator> allUndefinedTransitionsIterator(TransitionSystem ts,
                                                                                     Iterator stateIt,
                                                                                     Iterable inputs) {
        return new AllUndefinedInputsIterator<>(stateIt, ts, inputs);
    }

    public static final class TransRef {

        public final S state;
        public final I input;
        public final T transition;

        public TransRef(S state, I input) {
            this(state, input, null);
        }

        public TransRef(S state, I input, T transition) {
            this.state = state;
            this.input = input;
            this.transition = transition;
        }
    }

}