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.ts.DeterministicTransitionSystem;
import net.automatalib.ts.TransitionSystem;
import net.automatalib.ts.UniversalTransitionSystem;
import net.automatalib.util.ts.TSIterators.DefinedInputsIterator;
import net.automatalib.util.ts.TSIterators.UndefinedInputsIterator;
import net.automatalib.util.ts.traversal.BFSOrderIterator;
import com.google.common.base.Function;
public abstract class TS {
public static final class TransRef {
public final S state;
public final I input;
public final T transition;
public TransRef(S state, I input, T transition) {
this.state = state;
this.input = input;
this.transition = transition;
}
public TransRef(S state, I input) {
this(state, input, null);
}
}
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 Function stateProperties(final UniversalTransitionSystem uts) {
return new Function() {
@Override
public SP apply(S elem) {
return uts.getStateProperty(elem);
}
};
}
public static Function transitionProperties(final UniversalTransitionSystem, ?, T, ?, TP> uts) {
return new Function() {
@Override
public TP apply(T elem) {
return uts.getTransitionProperty(elem);
}
};
}
public static Iterator definedInputsIterator(TransitionSystem ts,
S state,
Iterator extends I> inputsIt) {
return new DefinedInputsIterator(ts, state, inputsIt);
}
public static Iterable definedInputs(
final DeterministicTransitionSystem dts,
final S state,
final Iterable extends I> inputs) {
return new Iterable() {
@Override
public Iterator iterator() {
return definedInputsIterator(dts, state, inputs.iterator());
}
};
}
public static Iterator> allDefinedInputsIterator(
TransitionSystem ts,
Iterator extends S> stateIt,
Iterable extends I> inputs) {
return new TSIterators.AllDefinedInputsIterator<>(stateIt, ts, inputs);
}
public static Iterable> allDefinedInputs(
final TransitionSystem ts,
final Iterable extends S> states,
final Iterable extends I> inputs) {
return new Iterable>() {
@Override
public Iterator> iterator() {
return allDefinedInputsIterator(ts, states.iterator(), inputs);
}
};
}
public static Iterator undefinedInputsIterator(TransitionSystem ts,
S state,
Iterator extends I> inputsIt) {
return new UndefinedInputsIterator(ts, state, inputsIt);
}
public static Iterable undefinedInputs(
final TransitionSystem ts,
final S state,
final Iterable extends I> inputs) {
return new Iterable() {
@Override
public Iterator iterator() {
return undefinedInputsIterator(ts, state, inputs.iterator());
}
};
}
public static Iterator> allUndefinedTransitionsIterator(
TransitionSystem ts,
Iterator extends S> stateIt,
Iterable extends I> inputs) {
return new TSIterators.AllUndefinedInputsIterator<>(stateIt, ts, inputs);
}
public static Iterable> allUndefinedTransitions(
final TransitionSystem ts,
final Iterable extends S> states,
final Iterable extends I> inputs) {
return new Iterable>() {
@Override
public Iterator> iterator() {
return allUndefinedTransitionsIterator(ts, states.iterator(), inputs);
}
};
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy