Skip to content

Commit a7065b9

Browse files
committed
generalize Det{Suffix,}OutputAutomaton concepts to transition systems
1 parent f283852 commit a7065b9

File tree

30 files changed

+536
-224
lines changed

30 files changed

+536
-224
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2424
* The following class hierarchies have been made `sealed`:
2525
* `CommonAttrs`
2626
* `CommonStyles`
27+
* The `compute{State,Suffix,}Output` concepts from `Det{Suffix,}OutputAutomaton` have been lifted to infinite-state transition systems. As part of this refactoring, some inconsistencies have been addressed. Previously, for `Word`-output systems, `computeSuffixOutput` threw an `UndefinedPropertyAccessException` if the prefix traversed an undefined transition but not if the suffix did (here, the output would only be cut short). Now, both methods simply early-exit output computation. Furthermore, these changes also include the following renamings:
28+
* `DetOutputAutomaton` -> `DeterministicOutputAutomaton`
29+
* `DetSuffixOutputAutomaton` -> `DeterministicSuffixOutputAutomaton`
30+
* `DeterministicOutputTS` -> `DeterministicTraceableTS`
2731
* `ProcessUtil#invokeProcess` now handles consumers for stdout and stderr separately.
2832

2933
### Removed

api/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
exports net.automatalib.symbol.time;
6666
exports net.automatalib.ts;
6767
exports net.automatalib.ts.acceptor;
68+
exports net.automatalib.ts.concept;
6869
exports net.automatalib.ts.modal;
6970
exports net.automatalib.ts.modal.transition;
7071
exports net.automatalib.ts.output;

api/src/main/java/net/automatalib/automaton/concept/DetSuffixOutputAutomaton.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

api/src/main/java/net/automatalib/automaton/concept/DetOutputAutomaton.java renamed to api/src/main/java/net/automatalib/automaton/concept/DeterministicOutputAutomaton.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@
1616
package net.automatalib.automaton.concept;
1717

1818
import net.automatalib.automaton.DeterministicAutomaton;
19+
import net.automatalib.ts.concept.DeterministicOutputTS;
1920

2021
/**
21-
* An automaton which deterministically produces an output for an input word. Here, output refers to the <i>complete</i>
22-
* output that is made when an input word is read, not a single symbol.
22+
* A deterministic output automaton is a {@link DeterministicAutomaton deterministic automaton} that can produce
23+
* {@link OutputAutomaton outputs}.
2324
*
2425
* @param <S>
25-
* state class
26+
* state type
2627
* @param <I>
27-
* input symbol class
28+
* input symbol type
2829
* @param <T>
29-
* transition class
30+
* transition type
3031
* @param <D>
31-
* output domain class
32+
* output domain type
3233
*/
33-
public interface DetOutputAutomaton<S, I, T, D> extends OutputAutomaton<S, I, T, D>, DeterministicAutomaton<S, I, T> {}
34+
public interface DeterministicOutputAutomaton<S, I, T, D>
35+
extends OutputAutomaton<S, I, T, D>, DeterministicAutomaton<S, I, T>, DeterministicOutputTS<S, I, T, D> {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* Copyright (C) 2013-2025 TU Dortmund University
2+
* This file is part of AutomataLib <https://automatalib.net>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.automatalib.automaton.concept;
17+
18+
import net.automatalib.ts.concept.DeterministicSuffixOutputTS;
19+
20+
/**
21+
* A deterministic suffix output automaton is a {@link DeterministicOutputAutomaton deterministic output automaton} that
22+
* can produce {@link DeterministicSuffixOutputTS suffix outputs}.
23+
*
24+
* @param <S>
25+
* state type
26+
* @param <I>
27+
* input symbol type
28+
* @param <T>
29+
* transition type
30+
* @param <D>
31+
* output domain type
32+
*/
33+
public interface DeterministicSuffixOutputAutomaton<S, I, T, D>
34+
extends DeterministicOutputAutomaton<S, I, T, D>, DeterministicSuffixOutputTS<S, I, T, D> {}

api/src/main/java/net/automatalib/automaton/concept/Output.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
import java.util.Collection;
1919

20+
import net.automatalib.exception.UndefinedPropertyAccessException;
2021
import net.automatalib.word.Word;
2122
import net.automatalib.word.WordBuilder;
2223

2324
/**
24-
* Feature for automata that compute an output.
25+
* Feature for transition systems that compute an output. Here, output refers to the <i>complete</i> output that is made
26+
* when an input word is read, not a single symbol.
2527
*
2628
* @param <I>
2729
* input symbol type
@@ -31,13 +33,53 @@
3133
@FunctionalInterface
3234
public interface Output<I, D> {
3335

36+
/**
37+
* Computes the output for the given sequence of input symbols.
38+
*
39+
* @param input
40+
* the sequence of input symbols
41+
*
42+
* @return the computed output
43+
*
44+
* @throws UndefinedPropertyAccessException
45+
* if the computation encountered undefined transitions that would have been required for computing the
46+
* output
47+
*/
3448
D computeOutput(Iterable<? extends I> input);
3549

50+
/**
51+
* Convenience method for {@link #getBuilderFor(Iterable, int)} which uses {@code 0} for
52+
* {@code additionalElements}.
53+
*
54+
* @param iterable
55+
* the sequence of input symbols
56+
* @param <T>
57+
* symbol type
58+
*
59+
* @return a pre-sized builder (may use the default size if no information could be extracted from the iterable)
60+
*/
3661
static <T> WordBuilder<T> getBuilderFor(Iterable<?> iterable) {
62+
return getBuilderFor(iterable, 0);
63+
}
64+
65+
/**
66+
* Utility method for constructing a pre-sized builder (if possible) for storing responses generated when applying
67+
* the provided sequence of input symbols.
68+
*
69+
* @param iterable
70+
* the sequence of input symbols
71+
* @param additionalElements
72+
* number of elements that is added to the size of the iterable
73+
* @param <T>
74+
* symbol type
75+
*
76+
* @return a pre-sized builder (may use the default size if no information could be extracted from the iterable)
77+
*/
78+
static <T> WordBuilder<T> getBuilderFor(Iterable<?> iterable, int additionalElements) {
3779
if (iterable instanceof Word<?> w) {
38-
return new WordBuilder<>(w.length());
80+
return new WordBuilder<>(w.length() + additionalElements);
3981
} else if (iterable instanceof Collection<?> c) {
40-
return new WordBuilder<>(c.size());
82+
return new WordBuilder<>(c.size() + additionalElements);
4183
} else {
4284
return new WordBuilder<>();
4385
}

api/src/main/java/net/automatalib/automaton/concept/OutputAutomaton.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,18 @@
1616
package net.automatalib.automaton.concept;
1717

1818
import net.automatalib.automaton.Automaton;
19+
import net.automatalib.ts.concept.OutputTS;
1920

20-
public interface OutputAutomaton<S, I, T, D> extends Automaton<S, I, T>, Output<I, D> {}
21+
/**
22+
* An output automaton is a {@link Automaton finite state} {@link OutputTS output transition system}.
23+
*
24+
* @param <S>
25+
* state type
26+
* @param <I>
27+
* input symbol type
28+
* @param <T>
29+
* transition type
30+
* @param <D>
31+
* output domain type
32+
*/
33+
public interface OutputAutomaton<S, I, T, D> extends Automaton<S, I, T>, OutputTS<S, I, T, D> {}

api/src/main/java/net/automatalib/automaton/concept/SuffixOutput.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
*/
1616
package net.automatalib.automaton.concept;
1717

18+
import net.automatalib.exception.UndefinedPropertyAccessException;
1819
import net.automatalib.word.Word;
1920

2021
/**
21-
* Feature for automata that compute a <i>suffix-observable</i> output function, i.e., they compute an output containing
22-
* a part that can be attributed to a suffix of the input.
22+
* Feature for transition systems that compute a <i>suffix-observable</i> output function, i.e., they compute an output
23+
* containing a part that can be attributed to a suffix of the input.
2324
* <p>
2425
* Note that this is a special case of the {@link Output} feature, as
25-
* {@code computeOutput(input) = computeSuffixOutput(epsilon, input)}.
26+
* {@code computeOutput(input) = computeSuffixOutput(ε, input)}.
2627
*
2728
* @param <I>
2829
* input symbol type
@@ -37,5 +38,19 @@ default D computeOutput(Iterable<? extends I> input) {
3738
return computeSuffixOutput(Word.epsilon(), input);
3839
}
3940

41+
/**
42+
* Computes the output for the given suffix from the state reached by the given prefix.
43+
*
44+
* @param prefix
45+
* the sequence of input symbols for reaching the state from which the output computation should start
46+
* @param suffix
47+
* the sequence of input symbols that should be considered for computing the output
48+
*
49+
* @return the computed output
50+
*
51+
* @throws UndefinedPropertyAccessException
52+
* if the computation encountered undefined transitions that would have been required for computing the
53+
* output
54+
*/
4055
D computeSuffixOutput(Iterable<? extends I> prefix, Iterable<? extends I> suffix);
4156
}

api/src/main/java/net/automatalib/automaton/fsa/DFA.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,17 @@
1818
import java.util.Collection;
1919

2020
import net.automatalib.automaton.UniversalDeterministicAutomaton;
21-
import net.automatalib.automaton.concept.DetSuffixOutputAutomaton;
21+
import net.automatalib.automaton.concept.DeterministicSuffixOutputAutomaton;
2222
import net.automatalib.ts.acceptor.DeterministicAcceptorTS;
2323

2424
/**
2525
* Deterministic finite state acceptor.
2626
*/
2727
public interface DFA<S, I> extends UniversalDeterministicAutomaton<S, I, S, Boolean, Void>,
2828
DeterministicAcceptorTS<S, I>,
29-
DetSuffixOutputAutomaton<S, I, S, Boolean>,
29+
DeterministicSuffixOutputAutomaton<S, I, S, Boolean>,
3030
NFA<S, I> {
3131

32-
@Override
33-
default Boolean computeSuffixOutput(Iterable<? extends I> prefix, Iterable<? extends I> suffix) {
34-
S tgt = getState(prefix);
35-
return tgt != null && computeStateOutput(tgt, suffix);
36-
}
37-
38-
@Override
39-
default Boolean computeStateOutput(S state, Iterable<? extends I> input) {
40-
S tgt = getSuccessor(state, input);
41-
return tgt != null && isAccepting(tgt);
42-
}
43-
44-
@Override
45-
default Boolean computeOutput(Iterable<? extends I> input) {
46-
return accepts(input);
47-
}
48-
4932
@Override
5033
default boolean isAccepting(Collection<? extends S> states) {
5134
return DeterministicAcceptorTS.super.isAccepting(states);

api/src/main/java/net/automatalib/automaton/fsa/FiniteStateAcceptor.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import net.automatalib.automaton.graph.TransitionEdge;
2727
import net.automatalib.automaton.graph.UniversalAutomatonGraphView;
2828
import net.automatalib.automaton.visualization.FSAVisualizationHelper;
29-
import net.automatalib.common.util.collection.IterableUtil;
3029
import net.automatalib.graph.UniversalGraph;
3130
import net.automatalib.ts.acceptor.AcceptorTS;
3231
import net.automatalib.visualization.VisualizationHelper;
@@ -42,17 +41,6 @@ public interface FiniteStateAcceptor<S, I> extends AcceptorTS<S, I>,
4241
List<Boolean> STATE_PROPERTIES = Arrays.asList(Boolean.FALSE, Boolean.TRUE);
4342
List<Void> TRANSITION_PROPERTIES = Collections.singletonList(null);
4443

45-
@Override
46-
default Boolean computeSuffixOutput(Iterable<? extends I> prefix, Iterable<? extends I> suffix) {
47-
Iterable<I> input = IterableUtil.concat(prefix, suffix);
48-
return computeOutput(input);
49-
}
50-
51-
@Override
52-
default Boolean computeOutput(Iterable<? extends I> input) {
53-
return accepts(input);
54-
}
55-
5644
@Override
5745
default UniversalGraph<S, TransitionEdge<I, S>, Boolean, TransitionEdge.Property<I, Void>> transitionGraphView(
5846
Collection<? extends I> inputs) {

0 commit comments

Comments
 (0)