net.automatalib.util.ts.TS Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of automata-util Show documentation
Show all versions of automata-util Show documentation
This artifact provides various common utility operations for analyzing and manipulating
automata and graphs, such as traversal, minimization and copying.
/* Copyright (C) 2013 TU Dortmund
* This file is part of AutomataLib, http://www.automatalib.net/.
*
* AutomataLib is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 3.0 as published by the Free Software Foundation.
*
* AutomataLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with AutomataLib; if not, see
* http://www.gnu.de/documents/lgpl.en.html.
*/
package net.automatalib.util.ts;
import java.util.Collection;
import java.util.Iterator;
import net.automatalib.commons.util.mappings.Mapping;
import net.automatalib.ts.DeterministicTransitionSystem;
import net.automatalib.ts.TransitionSystem;
import net.automatalib.ts.UniversalTransitionSystem;
import net.automatalib.util.ts.TSIterators.AllTransitionsIterator;
import net.automatalib.util.ts.TSIterators.DefinedTransitionsIterator;
import net.automatalib.util.ts.TSIterators.UndefinedTransitionsIterator;
import net.automatalib.util.ts.traversal.BFSOrderIterator;
public abstract class TS {
public static final class TransRef {
public final S state;
public final I input;
public TransRef(S state, I input) {
this.state = state;
this.input = input;
}
}
public static Iterable allTransitions(final TransitionSystem ts,
final S state,
final Collection inputs) {
return new Iterable() {
@Override
public Iterator iterator() {
return new AllTransitionsIterator(ts, state, inputs);
}
};
}
public static Iterable bfsOrder(final TransitionSystem ts, final Collection extends I> inputs) {
return new Iterable() {
@Override
public Iterator iterator() {
return new BFSOrderIterator(ts, inputs);
}
};
}
public static Mapping stateProperties(final UniversalTransitionSystem uts) {
return new Mapping() {
@Override
public SP get(S elem) {
return uts.getStateProperty(elem);
}
};
}
public static Mapping transitionProperties(final UniversalTransitionSystem, ?, T, ?, TP> uts) {
return new Mapping() {
@Override
public TP get(T elem) {
return uts.getTransitionProperty(elem);
}
};
}
public static Iterator definedTransitionsIterator(DeterministicTransitionSystem dts,
S state,
Iterator extends I> inputsIt) {
return new DefinedTransitionsIterator(dts, state, inputsIt);
}
public static Iterable definedTransitions(
final DeterministicTransitionSystem dts,
final S state,
final Iterable extends I> inputs) {
return new Iterable() {
@Override
public Iterator iterator() {
return definedTransitionsIterator(dts, state, inputs.iterator());
}
};
}
public static Iterator> allDefinedTransitionsIterator(
DeterministicTransitionSystem dts,
Iterator extends S> stateIt,
Iterable extends I> inputs) {
return new TSIterators.AllDefinedTransitionsIterator<>(stateIt, dts, inputs);
}
public static Iterable> allDefinedTransitions(
final DeterministicTransitionSystem dts,
final Iterable extends S> states,
final Iterable extends I> inputs) {
return new Iterable>() {
@Override
public Iterator> iterator() {
return allDefinedTransitionsIterator(dts, states.iterator(), inputs);
}
};
}
public static Iterator undefinedTransitionsIterator(DeterministicTransitionSystem dts,
S state,
Iterator extends I> inputsIt) {
return new UndefinedTransitionsIterator(dts, state, inputsIt);
}
public static Iterable undefinedTransitions(
final DeterministicTransitionSystem dts,
final S state,
final Iterable extends I> inputs) {
return new Iterable() {
@Override
public Iterator iterator() {
return undefinedTransitionsIterator(dts, state, inputs.iterator());
}
};
}
public static Iterator> allUndefinedTransitionsIterator(
DeterministicTransitionSystem dts,
Iterator extends S> stateIt,
Iterable extends I> inputs) {
return new TSIterators.AllUndefinedTransitionsIterator<>(stateIt, dts, inputs);
}
public static Iterable> allUndefinedTransitions(
final DeterministicTransitionSystem dts,
final Iterable extends S> states,
final Iterable extends I> inputs) {
return new Iterable>() {
@Override
public Iterator> iterator() {
return allUndefinedTransitionsIterator(dts, states.iterator(), inputs);
}
};
}
}