Class AbstractCompact<I,T,SP,TP>

java.lang.Object
net.automatalib.automaton.base.AbstractCompact<I,T,SP,TP>
Type Parameters:
I - input symbol type
T - transition type
SP - state property type
TP - transition property type
All Implemented Interfaces:
Iterable<Integer>, SupportsGrowingAlphabet<I>, Automaton<Integer,I,T>, FiniteRepresentation, InitialStates<Integer>, InputAlphabetHolder<I>, StateIDs<Integer>, StateLocalInput<Integer,I>, FiniteAlphabetAutomaton<Integer,I,T>, MutableAutomaton<Integer,I,T,SP,TP>, SimpleAutomaton<Integer,I>, UniversalAutomaton<Integer,I,T,SP,TP>, UniversalFiniteAlphabetAutomaton<Integer,I,T,SP,TP>, GraphViewable, SimpleTS<Integer,I>, TransitionSystem<Integer,I,T>, UniversalTransitionSystem<Integer,I,T,SP,TP>
Direct Known Subclasses:
AbstractCompactDeterministic, AbstractCompactMTS, AbstractCompactSimpleNondet

public abstract class AbstractCompact<I,T,SP,TP> extends Object implements MutableAutomaton<Integer,I,T,SP,TP>, StateIDs<Integer>, UniversalFiniteAlphabetAutomaton<Integer,I,T,SP,TP>, SupportsGrowingAlphabet<I>, StateLocalInput<Integer,I>
Abstract super class for compact automata representations. Compactness is achieved by representing states as integers, such that each state can be conveniently used to address a memory location. As a result most of the relevant automata data (such as successors, state- or transition properties) can be stored in compact arrays.

This class provides basic implementations (as far as possible on this abstract level) for several of the implemented concepts and offers utility methods to subclasses, for updating their array-based automata data.

  • Field Details

  • Constructor Details

    • AbstractCompact

      public AbstractCompact(Alphabet<I> alphabet, AbstractCompact<?,?,?,?> other)
    • AbstractCompact

      public AbstractCompact(Alphabet<I> alphabet, int stateCapacity, float resizeFactor)
  • Method Details

    • getStates

      public Collection<Integer> getStates()
      Description copied from interface: SimpleAutomaton
      Retrieves all states of the transition system. Implementing classes should return an unmodifiable collection
      Specified by:
      getStates in interface SimpleAutomaton<I,T>
      Returns:
      all states in the transition system
    • stateIDs

      public StateIDs<Integer> stateIDs()
      Specified by:
      stateIDs in interface SimpleAutomaton<I,T>
    • size

      public int size()
      Description copied from interface: SimpleAutomaton
      Retrieves the size (number of states) of this transition system.
      Specified by:
      size in interface FiniteRepresentation
      Specified by:
      size in interface SimpleAutomaton<I,T>
      Returns:
      the number of states of this transition system
    • getStateId

      public int getStateId(Integer state)
      Description copied from interface: StateIDs
      Returns for a given state of the automaton an integer uniquely identifying the state. The returned ids should be within the range of the number of states of the automaton so that they can be used for array-based indexing.
      Specified by:
      getStateId in interface StateIDs<I>
      Parameters:
      state - the state whose id should be retrieved
      Returns:
      the (positive) id of the given automaton state
    • getState

      public Integer getState(int id)
      Description copied from interface: StateIDs
      Return for a given id the state of the automaton identified by it.
      Specified by:
      getState in interface StateIDs<I>
      Parameters:
      id - the id of the state to be returned
      Returns:
      the automaton state identified by the given id.
    • clear

      public void clear()
      Description copied from interface: MutableAutomaton
      Removes all states and transitions.
      Specified by:
      clear in interface MutableAutomaton<Integer,I,T,SP,TP>
    • addState

      public final Integer addState(@Nullable SP property)
      Description copied from interface: MutableAutomaton
      Adds a new state with the given property to the automaton.
      Specified by:
      addState in interface MutableAutomaton<Integer,I,T,SP,TP>
      Parameters:
      property - the property of the new state
      Returns:
      the newly created state
    • addIntState

      public int addIntState(@Nullable SP property)
    • getInputAlphabet

      public Alphabet<I> getInputAlphabet()
      Specified by:
      getInputAlphabet in interface InputAlphabetHolder<I>
    • addAlphabetSymbol

      public final void addAlphabetSymbol(I symbol)
      Description copied from interface: SupportsGrowingAlphabet
      Notifies the data structure that a new symbol should be added to the alphabet. Behavior depends on the implementation:
      • After adding a new symbol, the symbol-related data may either be initialized with default values or undefined.
      • Duplicate symbols may: (1) be handled accordingly, (2) be ignored or (3) result in an error.
      Some data structures may need to be properly initialized (e.g. with a GrowingAlphabet) to handle potentially shared state across multiple instances. If the needed requirements are not met, a GrowingAlphabetNotSupportedException can be thrown.
      Specified by:
      addAlphabetSymbol in interface SupportsGrowingAlphabet<I>
      Parameters:
      symbol - the symbol to add to the alphabet.
    • getLocalInputs

      public Collection<I> getLocalInputs(Integer state)
      Description copied from interface: StateLocalInput
      Returns the collection of input symbols for which a successor state is defined.
      Specified by:
      getLocalInputs in interface StateLocalInput<I,T>
      Parameters:
      state - the state for which the defined inputs should be returned
      Returns:
      the collection of input symbols for which a successor state is defined.
    • setStateProperty

      public void setStateProperty(Integer state, SP property)
      Specified by:
      setStateProperty in interface MutableAutomaton<Integer,I,T,SP,TP>
    • setStateProperty

      public abstract void setStateProperty(int state, SP property)
    • getStateProperty

      public SP getStateProperty(Integer state)
      Description copied from interface: UniversalTransitionSystem
      Retrieves the state property for the given state.
      Specified by:
      getStateProperty in interface UniversalTransitionSystem<Integer,I,T,SP,TP>
      Parameters:
      state - the state.
      Returns:
      the corresponding property.
    • getStateProperty

      public abstract SP getStateProperty(int state)
    • updateStateStorage

      protected void updateStateStorage(AbstractCompact.Payload payload)
      Implementing classes should override this method in order to react to changes to the layout of their array-based state data, e.g. due to calls to MutableAutomaton.addState().

      Subclasses may use one of the updateStateStorage(Object[], Object, Payload)... methods to conveniently delegate this task to this base class. This leaves subclasses only with the task to invoke the provided update methods for each of their local array storages.

      Parameters:
      payload - the payload containing the necessary information for the update operation. This object must be passed as-is to the updateStateStorage(Object[], Object, Payload)... methods.
    • updateStateStorage

      protected final Object[] updateStateStorage(@Nullable Object[] oldStorage, @Nullable Object defaultValue, AbstractCompact.Payload payload)
      Return a copy of the provided array with updated memory layout.
      Parameters:
      oldStorage - the current array
      defaultValue - default value for newly allocated array positions
      payload - the payload object
      Returns:
      a copy of the provided array with updated memory layout.
    • updateTransitionStorage

      protected void updateTransitionStorage(AbstractCompact.Payload payload)
      Implementing classes should override this method in order to react to changes to the layout of their array-based transition data, e.g. due to calls to MutableAutomaton.addState() or addAlphabetSymbol(Object).

      Subclasses may use one of the updateTransitionStorage(Object[], IntFunction, Object, Payload)... methods to conveniently delegate this task to this base class. This leaves subclasses only with the task to invoke the provided update methods for each of their local array storages.

      Parameters:
      payload - the payload containing the necessary information for the update operation. This object must be passed as-is to the updateTransitionStorage(Object[], IntFunction, Object, Payload)... methods.
    • updateTransitionStorage

      protected final int[] updateTransitionStorage(int[] oldStorage, int defaultValue, AbstractCompact.Payload payload)
      Return a copy of the provided array with updated memory layout.
      Parameters:
      oldStorage - the current array
      defaultValue - default value for newly allocated array positions
      payload - the payload object
      Returns:
      a copy of the provided array with updated memory layout.
      See Also:
    • updateTransitionStorage

      protected final @Nullable Object[] updateTransitionStorage(@Nullable Object[] oldStorage, @Nullable Object defaultValue, AbstractCompact.Payload payload)
      Return a copy of the provided array with updated memory layout.
      Parameters:
      oldStorage - the current array
      defaultValue - default value for newly allocated array positions
      payload - the payload object
      Returns:
      a copy of the provided array with updated memory layout.
      See Also:
    • updateTransitionStorage

      protected final <S> @Nullable S[] updateTransitionStorage(@Nullable S[] oldStorage, IntFunction<@Nullable S[]> arrayConstructor, @Nullable S defaultValue, AbstractCompact.Payload payload)
      Return a copy of the provided array with updated memory layout.
      Type Parameters:
      S - the storage type
      Parameters:
      oldStorage - the current array
      arrayConstructor - the constructor for creating the new array
      defaultValue - default value for newly allocated array positions
      payload - the payload object
      Returns:
      a copy of the provided array with updated memory layout.
      See Also:
    • toState

      protected static @Nullable Integer toState(int id)
    • toId

      protected static int toId(@Nullable Integer id)
    • toMemoryIndex

      protected final int toMemoryIndex(int stateId, int inputId)
      Returns for a given state id and input symbol index, the memory location for its associated data.
      Parameters:
      stateId - the state id
      inputId - the index of input symbol
      Returns:
      the memory location for the given state id and input symbol index
      See Also:
    • getSymbolIndex

      protected final int getSymbolIndex(I input)
    • numInputs

      public final int numInputs(@UnknownInitialization(AbstractCompact.class) AbstractCompact<I,T,SP,TP> this)