001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of AutomataLib, http://www.automatalib.net/. 003 * 004 * AutomataLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * AutomataLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with AutomataLib; if not, see 015 * http://www.gnu.de/documents/lgpl.en.html. 016 */ 017package net.automatalib.automata.graphs; 018 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.List; 022 023import net.automatalib.automata.Automaton; 024import net.automatalib.automata.FiniteAlphabetAutomaton; 025import net.automatalib.automata.UniversalAutomaton; 026import net.automatalib.automata.abstractimpl.AbstractAutomaton; 027import net.automatalib.commons.util.mappings.MutableMapping; 028import net.automatalib.graphs.UniversalGraph; 029import net.automatalib.graphs.concepts.NodeIDs; 030 031public abstract class AbstractAutomatonGraph<S,I,T,SP,TP> 032 extends AbstractAutomaton<S, I, T> implements FiniteAlphabetAutomaton<S,I,T>, UniversalAutomaton<S,I,T,SP,TP>, UniversalGraph<S,TransitionEdge<I,T>,SP,TransitionEdge.Property<I,TP>> { 033 034 035 public static <S,I,T> Collection<TransitionEdge<I,T>> createOutgoingEdges(Automaton<S,I,T> automaton, Collection<? extends I> inputs, S state) { 036 List<TransitionEdge<I,T>> result 037 = new ArrayList<TransitionEdge<I,T>>(); 038 039 040 for(I input : inputs) { 041 Collection<T> transitions = automaton.getTransitions(state, input); 042 if(transitions == null) 043 continue; 044 for(T t : transitions) 045 result.add(new TransitionEdge<>(input, t)); 046 } 047 048 return result; 049 } 050 051 052 public static <S,I,T> Collection<S> getNodes(Automaton<S,I,T> $this) { 053 return $this.getStates(); 054 } 055 056 public static <S,I,T> NodeIDs<S> nodeIDs(Automaton<S,I,T> $this) { 057 return new StateAsNodeIDs<>($this.stateIDs()); 058 } 059 060 public static <S,I,T> Collection<TransitionEdge<I,T>> getOutgoingEdges(FiniteAlphabetAutomaton<S,I,T> $this, S node) { 061 return createOutgoingEdges($this, $this.getInputAlphabet(), node); 062 } 063 064 public static <S,I,T> S getTarget(Automaton<S,I,T> $this, TransitionEdge<I,T> edge) { 065 return $this.getSuccessor(edge.getTransition()); 066 } 067 068 public static <S,I,T,V> MutableMapping<S, V> createStaticNodeMapping(Automaton<S,I,T> $this) { 069 return $this.createStaticStateMapping(); 070 } 071 072 public static <S,I,T,V> MutableMapping<S, V> createDynamicNodeMapping(Automaton<S,I,T> $this) { 073 return $this.createDynamicStateMapping(); 074 } 075 076 public static <S,I,T,SP,TP> SP getNodeProperties(UniversalAutomaton<S, I, T, SP, TP> $this, S node) { 077 return $this.getStateProperty(node); 078 } 079 080 081 public static <S,I,T,SP,TP> TransitionEdge.Property<I, TP> getEdgeProperties(UniversalAutomaton<S,I,T,SP,TP> $this, TransitionEdge<I, T> edge) { 082 return edge.property($this); 083 } 084 085 @Override 086 public Collection<S> getNodes() { 087 return getNodes(this); 088 } 089 090 @Override 091 public NodeIDs<S> nodeIDs() { 092 return nodeIDs(this); 093 } 094 095 @Override 096 public Collection<TransitionEdge<I, T>> getOutgoingEdges(S node) { 097 return getOutgoingEdges(this, node); 098 } 099 100 @Override 101 public S getTarget(TransitionEdge<I, T> edge) { 102 return getTarget(this, edge); 103 } 104 105 @Override 106 public <V> MutableMapping<S, V> createStaticNodeMapping() { 107 return createStaticNodeMapping(this); 108 } 109 110 @Override 111 public <V> MutableMapping<S, V> createDynamicNodeMapping() { 112 return createDynamicNodeMapping(this); 113 } 114 115 116 @Override 117 public SP getNodeProperty(S node) { 118 return getNodeProperties(this, node); 119 } 120 121 122 @Override 123 public TransitionEdge.Property<I, TP> getEdgeProperty(TransitionEdge<I, T> edge) { 124 return getEdgeProperties(this, edge); 125 } 126 127 128}