Skip to content

Commit 13c4755

Browse files
pdev55tupaulmtf90
authored
Code for Mealy machines with local timers. (#96)
* Added MMLT classes * Added basic tests for MMLTs; included sample MMLT model file. * Added serialization test for MMLTs. * Separated more files into API and implementation to enable use from LearnLib. * Removed I prefix for some interfaces for the MMLT automaton. * Updated calculation of MMLT location cover to accept a list of inputs to be considered. * Method for finding a separating word in an MMLT now considers a provided collection of inputs. * Convenience flag for faster location cover calculation. * Added more tests for the reduced semantics. * Parser for MMLTs now accepts an input stream, in addition to a file. * Updated Serialization for MMLTs: resets-attribute for edges is now included when resets cannot be inferred from context. * initial refactorings / cleanups * use InputSymbols directly * use input type I directly * Removed getUntimedAlphabet, as it has the same function as getInputAlphabet. * CompactMMLT: allow for sizeHints * MMLTs: add direct equivalence check * make code-analysis pass * mention MMLTs in README * adjust to LearnLib refactorings * add documentation * add some more test cases * Using LinkedHashMap instead of HashMap in MMLT-Cover for deterministic ordering. * MMLT transition output can no longer be null. * Added more validation tests for the MMLT-parser. * TimerInfo now supports multiple outputs per timer. StringSymbolCombiner expects atomic outputs for its input list when combining symbols. * MMLT parser now parses multiple outputs for one timer. Updated corresponding tests. * fix analysis and adjust to LearnLib refactorings * cleanups * documentation * last de-stream-ifications --------- Co-authored-by: Paul Kogel <[email protected]> Co-authored-by: Markus Frohme <[email protected]>
1 parent f534932 commit 13c4755

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4033
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88

99
### Added
1010

11+
* A new formalism for *Mealy machines with local timers* (MMLTs) including means for conformance testing and equivalence checking has been added (thanks to [Paul Kogel](https://github.com/pdev55)).
1112
* `automata-modelchecking-m3c` now supports ARM-based macOS systems.
1213
* `automata-modelchecking-m3c` can now be included in jlink images.
1314

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Its original purpose is to serve as the automaton framework for the [LearnLib][3
1414
However, it is completely independent of LearnLib and can be used for other projects as well.
1515

1616
AutomataLib supports modeling a variety of graph-based structures.
17-
Currently, it covers generic transition systems, Deterministic Finite Automata (DFAs) and Mealy machines as well as more advanced structures such as Modal Transition Systems (MTSs), Subsequential Transducers (SSTs), Visibly Pushdown Automata (VPAs) and Procedural Systems (SPAs, SBAs, SPMMs).
17+
Currently, it covers generic transition systems like Deterministic Finite Automata (DFAs) and Mealy machines as well as more advanced structures such as Modal Transition Systems (MTSs), Mealy machines with local timers (MMLTs), Visibly Pushdown Automata (VPAs) and Procedural Systems (SPAs, SBAs, SPMMs).
1818

1919
Models of AutomataLib can be (de-)serialized (from) to one of the various supported serialization formats and may be visualized using either the GraphViz or JUNG library.
2020
Furthermore, a plethora of graph-/automata-based algorithms is implemented, covering the following topics:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
exports net.automatalib.automaton.fsa;
4848
exports net.automatalib.automaton.graph;
4949
exports net.automatalib.automaton.helper;
50+
exports net.automatalib.automaton.mmlt;
5051
exports net.automatalib.automaton.procedural;
5152
exports net.automatalib.automaton.simple;
5253
exports net.automatalib.automaton.transducer;
@@ -61,6 +62,7 @@
6162
exports net.automatalib.graph.visualization;
6263
exports net.automatalib.modelchecking;
6364
exports net.automatalib.serialization;
65+
exports net.automatalib.symbol.time;
6466
exports net.automatalib.ts;
6567
exports net.automatalib.ts.acceptor;
6668
exports net.automatalib.ts.modal;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.mmlt;
17+
18+
import java.util.List;
19+
20+
import net.automatalib.automaton.UniversalDeterministicAutomaton;
21+
import net.automatalib.automaton.concept.InputAlphabetHolder;
22+
import net.automatalib.common.util.Triple;
23+
import net.automatalib.graph.Graph;
24+
import net.automatalib.graph.concept.GraphViewable;
25+
import net.automatalib.symbol.time.SymbolicInput;
26+
27+
/**
28+
* Base type for a Mealy Machine with Local Timers (MMLT).
29+
* <p>
30+
* An MMLT extends Mealy machines with local timers. Each location can have multiple timers. A timer can only be active
31+
* in its assigned location. All timers of a location reset when this location is entered from a different location or,
32+
* in case of the initial location, if the location is entered for the first time. There are periodic and one-shot
33+
* timers. Periodic timers reset themselves on timeout. They cannot cause a location change. One-shot timers can cause a
34+
* location change. They reset all timers of the target location at timeout. A location can have arbitrarily many
35+
* periodic timers and up to one one-shot timer. Timers are always reset to their initial value. The initial values must
36+
* be chosen so that a periodic timer never times out at the same time as a one-shot timer (to preserve determinism).
37+
* Multiple periodic timers may time out simultaneously. In this case, their outputs are combined using the provided
38+
* {@link #getOutputCombiner()}.
39+
* <p>
40+
* <b>Implementation note:</b> This class resembles a "structural" view on the MMLT. Timeouts can also be interpreted
41+
* as explicit transitions between locations. For this representation, use the {@link #graphView()} method. For a
42+
* semantic view that supports time-sensitive transductions, see the {@link #getSemantics()} method.
43+
*
44+
* @param <S>
45+
* location type
46+
* @param <I>
47+
* input symbol type (of non-delaying inputs)
48+
* @param <T>
49+
* transition type
50+
* @param <O>
51+
* output symbol type
52+
*/
53+
public interface MMLT<S, I, T, O>
54+
extends UniversalDeterministicAutomaton<S, I, T, Void, O>, InputAlphabetHolder<I>, GraphViewable {
55+
56+
/**
57+
* Returns the symbol used for silent outputs.
58+
*
59+
* @return the silent output symbol
60+
*/
61+
O getSilentOutput();
62+
63+
/**
64+
* Returns the output combiner used when multiple periodic timers time out simultaneously.
65+
*
66+
* @return the output combiner
67+
*/
68+
SymbolCombiner<O> getOutputCombiner();
69+
70+
/**
71+
* Indicates if the provided input performs a local reset in the given location.
72+
*
73+
* @param location
74+
* the location
75+
* @param input
76+
* the input
77+
*
78+
* @return {@code true} if performing a local reset, {@code false} otherwise
79+
*/
80+
boolean isLocalReset(S location, I input);
81+
82+
/**
83+
* Returns the timers of the specified location sorted ascendingly by their initial time.
84+
*
85+
* @param location
86+
* the location
87+
*
88+
* @return sorted list of local timers (may be empty if the location has no timers)
89+
*/
90+
List<TimerInfo<S, O>> getSortedTimers(S location);
91+
92+
/**
93+
* Returns the semantics automaton that describes the behavior of this MMLT.
94+
*
95+
* @return a semantic view of this MMLT
96+
*/
97+
MMLTSemantics<S, I, ?, O> getSemantics();
98+
99+
@Override
100+
default Graph<S, Triple<SymbolicInput<I>, O, S>> graphView() {
101+
return new MMLTGraphView<>(this);
102+
}
103+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.mmlt;
17+
18+
import java.util.ArrayList;
19+
import java.util.Collection;
20+
import java.util.List;
21+
22+
import net.automatalib.alphabet.Alphabet;
23+
import net.automatalib.automaton.visualization.MMLTVisualizationHelper;
24+
import net.automatalib.common.util.Triple;
25+
import net.automatalib.graph.Graph;
26+
import net.automatalib.symbol.time.InputSymbol;
27+
import net.automatalib.symbol.time.SymbolicInput;
28+
import net.automatalib.symbol.time.TimedInput;
29+
import net.automatalib.symbol.time.TimerTimeoutSymbol;
30+
import net.automatalib.visualization.VisualizationHelper;
31+
32+
/**
33+
* A graphview for {@link MMLT}s that explicitly represents timeouts as transitions between locations if possible. For
34+
* this purpose, edges use {@link SymbolicInput}s which include {@link InputSymbol}s and {@link TimerTimeoutSymbol}s.
35+
*
36+
* @param <S>
37+
* location type
38+
* @param <I>
39+
* input symbol type (of non-delaying inputs)
40+
* @param <T>
41+
* transition type
42+
* @param <O>
43+
* output symbol type
44+
*/
45+
public class MMLTGraphView<S, I, T, O> implements Graph<S, Triple<SymbolicInput<I>, O, S>> {
46+
47+
private final MMLT<S, I, T, O> mmlt;
48+
private final SymbolCombiner<O> outputCombiner;
49+
50+
public MMLTGraphView(MMLT<S, I, T, O> mmlt) {
51+
this.mmlt = mmlt;
52+
this.outputCombiner = mmlt.getOutputCombiner();
53+
}
54+
55+
@Override
56+
public Collection<Triple<SymbolicInput<I>, O, S>> getOutgoingEdges(S node) {
57+
58+
Alphabet<I> alphabet = mmlt.getInputAlphabet();
59+
List<TimerInfo<S, O>> timers = mmlt.getSortedTimers(node);
60+
61+
List<Triple<SymbolicInput<I>, O, S>> result = new ArrayList<>(alphabet.size() + timers.size());
62+
63+
for (I i : alphabet) {
64+
T t = mmlt.getTransition(node, i);
65+
if (t != null) {
66+
result.add(Triple.of(TimedInput.input(i), mmlt.getTransitionProperty(t), mmlt.getSuccessor(t)));
67+
}
68+
}
69+
70+
for (TimerInfo<S, O> t : timers) {
71+
result.add(Triple.of(new TimerTimeoutSymbol<>(t.name()),
72+
outputCombiner.combineSymbols(t.outputs()),
73+
t.target()));
74+
}
75+
76+
return result;
77+
}
78+
79+
@Override
80+
public S getTarget(Triple<SymbolicInput<I>, O, S> edge) {
81+
return edge.getThird();
82+
}
83+
84+
@Override
85+
public Collection<S> getNodes() {
86+
return mmlt.getStates();
87+
}
88+
89+
@Override
90+
public VisualizationHelper<S, Triple<SymbolicInput<I>, O, S>> getVisualizationHelper() {
91+
return new MMLTVisualizationHelper<>(mmlt, false, false);
92+
}
93+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.mmlt;
17+
18+
import net.automatalib.automaton.concept.InputAlphabetHolder;
19+
import net.automatalib.automaton.concept.SuffixOutput;
20+
import net.automatalib.symbol.time.InputSymbol;
21+
import net.automatalib.symbol.time.TimeStepSequence;
22+
import net.automatalib.symbol.time.TimedInput;
23+
import net.automatalib.symbol.time.TimedOutput;
24+
import net.automatalib.symbol.time.TimeoutSymbol;
25+
import net.automatalib.ts.output.MealyTransitionSystem;
26+
import net.automatalib.word.Word;
27+
28+
/**
29+
* Defines the semantics of an MMLT.
30+
* <p>
31+
* The semantics of an MMLT are defined with an associated Mealy machine. The {@link State states} of this machine
32+
* represent tuples of an active location and the current valuation of timers of this location. The inputs of the
33+
* machine are {@link InputSymbol non-delaying inputs}, {@link TimeStepSequence discrete time steps}, and the
34+
* {@link TimeoutSymbol symbolic input timeout}, which causes a delay until the next timeout.
35+
* <p>
36+
* The input alphabet of this machine consists of all non-delaying inputs of the associated MMLT, as well as a
37+
* {@link TimeStepSequence time step symbol} and the {@link TimeoutSymbol symbolic input timeout}.
38+
* <p>
39+
* The outputs of this machine are the outputs of the MMLT, extended with a delay. This delay is zero for all
40+
* transitions, except for those with the {@link TimeoutSymbol} input.
41+
*
42+
* @param <S>
43+
* location type
44+
* @param <I>
45+
* input symbol type (of non-delaying inputs)
46+
* @param <T>
47+
* transition type
48+
* @param <O>
49+
* output symbol type
50+
*/
51+
public interface MMLTSemantics<S, I, T, O> extends MealyTransitionSystem<State<S, O>, TimedInput<I>, T, TimedOutput<O>>,
52+
SuffixOutput<TimedInput<I>, Word<TimedOutput<O>>>,
53+
InputAlphabetHolder<TimedInput<I>> {
54+
55+
/**
56+
* Returns the symbol used for silent outputs.
57+
*
58+
* @return the silent output symbol
59+
*/
60+
TimedOutput<O> getSilentOutput();
61+
62+
/**
63+
* Retrieves the transition in the semantics automaton that has the provided input and source configuration.
64+
* <p>
65+
* If the input is a sequence of time steps, the target of the transition is the configuration reached after
66+
* executing all time steps. The output of the transition is the output of the time step that was executed last.
67+
* This output might belong to a timeout or be silence. The delay of this output is set to zero.
68+
* <p>
69+
* Please note that a sequence with more than one time step may trigger multiple timeouts. Regardless of that, only
70+
* the output at the last time step is returned.
71+
*
72+
* @param source
73+
* the source configuration
74+
* @param input
75+
* the input symbol
76+
* @param maxWaitingTime
77+
* the maximum time steps to wait for a timeout
78+
*
79+
* @return the transition in semantics automaton
80+
*/
81+
T getTransition(State<S, O> source, TimedInput<I> input, long maxWaitingTime);
82+
}

0 commit comments

Comments
 (0)