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 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 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 uts) {
		return new Function() {
			@Override
			public TP apply(T elem) {
				return uts.getTransitionProperty(elem);
			}
		};
	}
	
	public static  Iterator definedInputsIterator(TransitionSystem ts,
			S state,
			Iterator inputsIt) {
		return new DefinedInputsIterator(ts, state, inputsIt);
	}
	
	public static  Iterable definedInputs(
			final DeterministicTransitionSystem dts,
			final S state,
			final Iterable inputs) {
		return new Iterable() {
			@Override
			public Iterator iterator() {
				return definedInputsIterator(dts, state, inputs.iterator());
			}
		};
	}
	
	public static  Iterator> allDefinedInputsIterator(
			TransitionSystem ts,
			Iterator stateIt,
			Iterable inputs) {
		return new TSIterators.AllDefinedInputsIterator<>(stateIt, ts, inputs);
	}
	
	public static  Iterable> allDefinedInputs(
			final TransitionSystem ts,
			final Iterable states,
			final Iterable inputs) {
		return new Iterable>() {
			@Override
			public Iterator> iterator() {
				return allDefinedInputsIterator(ts, states.iterator(), inputs);
			}
		};
	}
	
	
	
	public static  Iterator undefinedInputsIterator(TransitionSystem ts,
			S state,
			Iterator inputsIt) {
		return new UndefinedInputsIterator(ts, state, inputsIt);
	}
	
	public static  Iterable undefinedInputs(
			final TransitionSystem ts,
			final S state,
			final Iterable inputs) {
		return new Iterable() {
			@Override
			public Iterator iterator() {
				return undefinedInputsIterator(ts, state, inputs.iterator());
			}
		};
	}
	
	public static  Iterator> allUndefinedTransitionsIterator(
			TransitionSystem ts,
			Iterator stateIt,
			Iterable inputs) {
		return new TSIterators.AllUndefinedInputsIterator<>(stateIt, ts, inputs);
	}
	
	public static  Iterable> allUndefinedTransitions(
			final TransitionSystem ts,
			final Iterable states,
			final Iterable inputs) {
		return new Iterable>() {
			@Override
			public Iterator> iterator() {
				return allUndefinedTransitionsIterator(ts, states.iterator(), inputs);
			}
		};
	}
	
}