- java.lang.Object
-
- net.automatalib.util.automaton.fsa.DFAs
-
public final class DFAs extends Object
Operations onDFA
s.Note that the methods provided by this class do not modify their input arguments. Such methods are instead provided by the
MutableDFAs
class. Furthermore, results are copied into new datastructures. For read-only views you may use the more genericAcceptors
factory.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <S> boolean
acceptsEmptyLanguage(DFA<S,?> dfa)
Computes whether the givenDFA
accepts the empty language.static <I,S,A extends MutableDFA<S,I>>
Aand(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the conjunction ("and") of two DFAs via product construction and stores the result in a given mutable DFA.static <I> CompactDFA<I>
and(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the conjunction ("and") of two DFAs via product construction and returns the result as a new DFA.static <I,S,A extends MutableDFA<S,I>>
Acombine(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out, AcceptanceCombiner combiner)
Most general way of combining two DFAs via product construction.static <I> CompactDFA<I>
combine(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet, AcceptanceCombiner combiner)
Most general way of combining two DFAs via product construction.static <I,S,A extends MutableDFA<S,I>>
Acomplement(DFA<?,I> dfa, Collection<? extends I> inputs, A out)
Calculates the complement (negation) of a DFA, and stores the result in a given mutable DFA.static <I> CompactDFA<I>
complement(DFA<?,I> dfa, Alphabet<I> inputAlphabet)
Calculates the complement (negation) of a DFA and returns the result as a new DFA.static <I,S,A extends MutableDFA<S,I>>
Acomplete(DFA<?,I> dfa, Collection<? extends I> inputs, A out)
static <I> CompactDFA<I>
complete(DFA<?,I> dfa, Alphabet<I> inputs)
static <I,S,A extends MutableDFA<S,I>>
Aequiv(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the equivalence ("<=>") of two DFAs via product construction and stores the result in a given mutable DFA.static <I> CompactDFA<I>
equiv(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the equivalence ("<=>") of two DFAs via product construction and returns the result as a new DFA.static <I,S,A extends MutableDFA<S,I>>
Aimpl(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the implication ("=>") of two DFAs via product construction and stores the result in a given mutable DFA.static <I> CompactDFA<I>
impl(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the implication ("=>") of two DFAs via product construction and returns the result as a new DFA.static <S,I>
booleanisPrefixClosed(DFA<S,I> dfa, Collection<I> inputs)
Computes whether the language of the given DFA is prefix-closed.static <S,I,A extends DFA<S,I> & InputAlphabetHolder<I>>
CompactDFA<I>minimize(A dfa)
Minimizes the given DFA.static <I> CompactDFA<I>
minimize(DFA<?,I> dfa, Alphabet<I> alphabet)
Minimizes the given DFA over the given alphabet.static <I,S,A extends MutableDFA<S,I>>
Aor(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the disjunction ("or") of two DFAs via product construction and stores the result in a given mutable DFA.static <I> CompactDFA<I>
or(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the disjunction ("or") of two DFAs via product construction and returns the result as a new DFA.static <I> CompactDFA<I>
trim(DFA<?,I> dfa, Alphabet<I> inputAlphabet)
Creates a trim DFA from the given input DFA.static <SI,I,SO,A extends MutableDFA<SO,I>>
Atrim(DFA<SI,I> dfa, Collection<? extends I> inputs, A out)
Creates a trim DFA from the given input DFA and writes it to the given output DFA.static <I,S,A extends MutableDFA<S,I>>
Axor(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the exclusive-or ("xor") of two DFAs via product construction and stores the result in a given mutable DFA.static <I> CompactDFA<I>
xor(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the exclusive-or ("xor") of two DFAs via product construction and returns the result as a new DFA.
-
-
-
Method Detail
-
combine
public static <I> CompactDFA<I> combine(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet, AcceptanceCombiner combiner)
Most general way of combining two DFAs via product construction. The behavior is the same as of the abovecombine(DFA, DFA, Collection, MutableDFA, AcceptanceCombiner)
, but the result automaton is automatically created as aCompactDFA
.- Type Parameters:
I
- input symbol type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputAlphabet
- the input alphabetcombiner
- combination method for acceptance values- Returns:
- a new DFA representing the combination of the specified DFA
-
combine
public static <I,S,A extends MutableDFA<S,I>> A combine(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out, AcceptanceCombiner combiner)
Most general way of combining two DFAs via product construction. TheAcceptanceCombiner
specified via thecombiner
parameter specifies how acceptance values of the DFAs will be combined to an acceptance value in the result DFA.- Type Parameters:
I
- input symbol typeS
- state typeA
- automaton type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputs
- the input symbols to considerout
- the mutable DFA for storing the resultcombiner
- combination method for acceptance values- Returns:
out
, for convenience
-
and
public static <I> CompactDFA<I> and(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the conjunction ("and") of two DFAs via product construction and returns the result as a new DFA.- Type Parameters:
I
- input symbol type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputAlphabet
- the input alphabet- Returns:
- a new DFA representing the conjunction of the specified DFA
-
and
public static <I,S,A extends MutableDFA<S,I>> A and(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the conjunction ("and") of two DFAs via product construction and stores the result in a given mutable DFA.- Type Parameters:
I
- input symbol typeS
- state typeA
- automaton type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputs
- the input symbols to considerout
- a mutable DFA for storing the result- Returns:
out
, for convenience
-
or
public static <I> CompactDFA<I> or(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the disjunction ("or") of two DFAs via product construction and returns the result as a new DFA.- Type Parameters:
I
- input symbol type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputAlphabet
- the input alphabet- Returns:
- a new DFA representing the conjunction of the specified DFA
-
or
public static <I,S,A extends MutableDFA<S,I>> A or(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the disjunction ("or") of two DFAs via product construction and stores the result in a given mutable DFA.- Type Parameters:
I
- input symbol typeS
- state typeA
- automaton type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputs
- the input symbols to considerout
- a mutable DFA for storing the result- Returns:
out
, for convenience
-
xor
public static <I> CompactDFA<I> xor(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the exclusive-or ("xor") of two DFAs via product construction and returns the result as a new DFA.- Type Parameters:
I
- input symbol type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputAlphabet
- the input alphabet- Returns:
- a new DFA representing the conjunction of the specified DFA
-
xor
public static <I,S,A extends MutableDFA<S,I>> A xor(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the exclusive-or ("xor") of two DFAs via product construction and stores the result in a given mutable DFA.- Type Parameters:
I
- input symbol typeS
- state typeA
- automaton type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputs
- the input symbols to considerout
- a mutable DFA for storing the result- Returns:
out
, for convenience
-
equiv
public static <I> CompactDFA<I> equiv(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the equivalence ("<=>") of two DFAs via product construction and returns the result as a new DFA.- Type Parameters:
I
- input symbol type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputAlphabet
- the input alphabet- Returns:
- a new DFA representing the conjunction of the specified DFA
-
equiv
public static <I,S,A extends MutableDFA<S,I>> A equiv(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the equivalence ("<=>") of two DFAs via product construction and stores the result in a given mutable DFA.- Type Parameters:
I
- input symbol typeS
- state typeA
- automaton type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputs
- the input symbols to considerout
- a mutable DFA for storing the result- Returns:
out
, for convenience
-
impl
public static <I> CompactDFA<I> impl(DFA<?,I> dfa1, DFA<?,I> dfa2, Alphabet<I> inputAlphabet)
Calculates the implication ("=>") of two DFAs via product construction and returns the result as a new DFA.- Type Parameters:
I
- input symbol type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputAlphabet
- the input alphabet- Returns:
- a new DFA representing the conjunction of the specified DFA
-
impl
public static <I,S,A extends MutableDFA<S,I>> A impl(DFA<?,I> dfa1, DFA<?,I> dfa2, Collection<? extends I> inputs, A out)
Calculates the implication ("=>") of two DFAs via product construction and stores the result in a given mutable DFA.- Type Parameters:
I
- input symbol typeS
- state typeA
- automaton type- Parameters:
dfa1
- the first DFAdfa2
- the second DFAinputs
- the input symbols to considerout
- a mutable DFA for storing the result- Returns:
out
, for convenience
-
trim
public static <I> CompactDFA<I> trim(DFA<?,I> dfa, Alphabet<I> inputAlphabet)
Creates a trim DFA from the given input DFA. A DFA is trim if all of its states are accessible and co-accessible.- Type Parameters:
I
- input symbol type- Parameters:
dfa
- the input DFAinputAlphabet
- the input alphabet- Returns:
- the trim DFA
- See Also:
NFAs.accessibleStates(NFA, Collection)
,NFAs.coaccessibleStates(NFA, Collection)
-
trim
public static <SI,I,SO,A extends MutableDFA<SO,I>> A trim(DFA<SI,I> dfa, Collection<? extends I> inputs, A out)
Creates a trim DFA from the given input DFA and writes it to the given output DFA. A DFA is trim if all of its states are accessible and co-accessible.- Type Parameters:
SI
- (input) state typeI
- input symbol typeSO
- (output) state typeA
- (output) automaton type- Parameters:
dfa
- the input DFAinputs
- the input symbols to considerout
- the output NFA- Returns:
out
for convenience- See Also:
NFAs.accessibleStates(NFA, Collection)
,NFAs.coaccessibleStates(NFA, Collection)
-
complement
public static <I> CompactDFA<I> complement(DFA<?,I> dfa, Alphabet<I> inputAlphabet)
Calculates the complement (negation) of a DFA and returns the result as a new DFA.Note that unlike
MutableFSA.flipAcceptance()
, undefined transitions are treated as leading to a rejecting sink state (and are thus turned into an accepting sink).- Type Parameters:
I
- input symbol type- Parameters:
dfa
- the DFA to complementinputAlphabet
- the input alphabet- Returns:
- a new DFA representing the complement of the specified DFA
-
complement
public static <I,S,A extends MutableDFA<S,I>> A complement(DFA<?,I> dfa, Collection<? extends I> inputs, A out)
Calculates the complement (negation) of a DFA, and stores the result in a given mutable DFA.Note that unlike
MutableFSA.flipAcceptance()
, undefined transitions are treated as leading to a rejecting sink state (and are thus turned into an accepting sink).- Type Parameters:
I
- input symbol typeS
- state typeA
- automaton type- Parameters:
dfa
- the DFA to complementinputs
- the input symbols to considerout
- a mutable DFA for storing the result- Returns:
out
, for convenience
-
complete
public static <I> CompactDFA<I> complete(DFA<?,I> dfa, Alphabet<I> inputs)
-
complete
public static <I,S,A extends MutableDFA<S,I>> A complete(DFA<?,I> dfa, Collection<? extends I> inputs, A out)
-
minimize
public static <I> CompactDFA<I> minimize(DFA<?,I> dfa, Alphabet<I> alphabet)
Minimizes the given DFA over the given alphabet. This method does not modify the given DFA, but returns the minimized version as a new instance.Note: the DFA must be completely specified.
- Type Parameters:
I
- input symbol type- Parameters:
dfa
- the DFA to be minimizedalphabet
- the input alphabet to consider for minimization (this will also be the input alphabet of the resulting automaton)- Returns:
- a minimized version of the specified DFA
-
minimize
public static <S,I,A extends DFA<S,I> & InputAlphabetHolder<I>> CompactDFA<I> minimize(A dfa)
Minimizes the given DFA. This method does not modify the given DFA, but returns the minimized version as a new instance.Note: the DFA must be completely specified
- Type Parameters:
I
- input symbol typeS
- state typeA
- automaton type- Parameters:
dfa
- the DFA to be minimized- Returns:
- a minimized version of the specified DFA
-
isPrefixClosed
public static <S,I> boolean isPrefixClosed(DFA<S,I> dfa, Collection<I> inputs)
Computes whether the language of the given DFA is prefix-closed.Assumes all states in the given
DFA
are reachable from the initial state.- Type Parameters:
I
- input symbol typeS
- state type- Parameters:
dfa
- the DFA to checkinputs
- the input symbols to consider- Returns:
- whether the DFA is prefix-closed
-
acceptsEmptyLanguage
public static <S> boolean acceptsEmptyLanguage(DFA<S,?> dfa)
-
-