Skip to content

add Moore variant #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* Added the OSTIA passive learning algorithm, thanks to [Aleksander Mendoza-Drosik](https://github.com/aleksander-mendoza).
* Added the OML (optimal-MAT-learner) active learning algorithm, thanks to [Falk Howar](https://github.com/fhowar).
* Added a new learning algorithm for systems of procedural automata (SPAs).
* Added Moore versions of the learners `DT`, `TTT`, `LStar`, thanks to [Mohamad Bayram](https://github.com/mohbayram).

### Changed

Expand All @@ -21,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* The `ADT` class is no longer initialized with a `leafSplitter` but the `extendLeaf` and `splitLeaf` methods take an additional argument. This allows for a more customizable behavior.
* The `{DFA,Mealy}CacheOracle`s and the `SULCache` are no longer thread-safe because the intended pipeline of a parallel setup (as suggested by the LearnLib factory methods) consists of a single-threaded cache that delegates to parallel (non-cached) oracles. Here, the synchronization logic only adds unnecessary overhead. In case you want a shared, thread-safe cache (which was currently not conveniently possible to setup) the `learnlib-parallelism` module now contains the `ThreadSafe{DFA,Mealy,SUL}Caches` factories which allow one to construct parallel oracles (whose parameters and return types are tailored towards using our `ParallelOracleBuilders` factory) with a shared cache. See the in-tree `ParallelismExample2` for reference.
* `SymbolQueryCache` now needs to be created via the `MealyCaches` factory.
* `AbstractTTTHypothesis` has received an additional type parameter for its state type.


### Removed
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ While certain features have been stripped for improved modularity, development h
Currently, the following learning algorithms with respective target models are supported:


Algorithm (active) | Target models || Algorithm (passive) | Models
Algorithm (active) | Target models || Algorithm (passive) | Models
--- | --- | --- | --- | ---
ADT | `Mealy` || OSTIA | `SST`
DHC | `Mealy` || RPNI | `DFA` `Mealy`
Discrimination Tree | `DFA` `Mealy` `VPDA` || RPNI (EDSM) | `DFA`
Kearns & Vazirani | `DFA` `Mealy` || RPNI (MDL) | `DFA`
L* (incl. variants) | `DFA` `Mealy`
ADT | `Mealy` || OSTIA | `SST`
DHC | `Mealy` || RPNI | `DFA` `Mealy`
Discrimination Tree | `DFA` `Mealy` `Moore` `VPDA` || RPNI (EDSM) | `DFA`
Kearns & Vazirani | `DFA` `Mealy` || RPNI (MDL) | `DFA`
L* (incl. variants) | `DFA` `Mealy` `Moore`
NL* | `NFA`
OML | `DFA` `Mealy`
SPA | `SPA`
TTT | `DFA` `Mealy` `VPDA`
TTT | `DFA` `Mealy` `Moore` `VPDA`


Additionally, LearnLib offers a variety of tools to ease the practical application of automata learning on real-world systems.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* Copyright (C) 2013-2022 TU Dortmund
* This file is part of LearnLib, http://www.learnlib.de/.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.algorithms.discriminationtree.moore;

import com.github.misberner.buildergen.annotations.GenerateBuilder;
import de.learnlib.algorithms.discriminationtree.AbstractDTLearner;
import de.learnlib.algorithms.discriminationtree.DTLearnerState;
import de.learnlib.algorithms.discriminationtree.hypothesis.HState;
import de.learnlib.algorithms.discriminationtree.hypothesis.HTransition;
import de.learnlib.api.algorithm.LearningAlgorithm.MooreLearner;
import de.learnlib.api.oracle.MembershipOracle;
import de.learnlib.api.query.AbstractQuery;
import de.learnlib.api.query.Query;
import de.learnlib.counterexamples.LocalSuffixFinder;
import de.learnlib.datastructure.discriminationtree.MultiDTree;
import net.automatalib.automata.transducers.MooreMachine;
import net.automatalib.words.Alphabet;
import net.automatalib.words.Word;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* A {@link MooreMachine}-based specialization of the DT learner.
*
* @param <I>
* input symbol type
* @param <O>
* output symbol type
*
* @author bayram
* @author frohme
*/
public class DTLearnerMoore<I, O> extends AbstractDTLearner<MooreMachine<?, I, ?, O>, I, Word<O>, O, Void>
implements MooreLearner<I, O> {

private HypothesisWrapperMoore<I, O> hypWrapper;

@GenerateBuilder(defaults = AbstractDTLearner.BuilderDefaults.class)
public DTLearnerMoore(Alphabet<I> alphabet,
MembershipOracle<I, Word<O>> oracle,
LocalSuffixFinder<? super I, ? super Word<O>> suffixFinder,
boolean repeatedCounterexampleEvaluation) {

super(alphabet, oracle, suffixFinder, repeatedCounterexampleEvaluation, new MultiDTree<>(oracle));
this.hypWrapper = new HypothesisWrapperMoore<>(getHypothesisDS());

}

@Override
protected @Nullable Query<I, Word<O>> spQuery(HState<I, Word<O>, O, Void> state) {
return new AbstractQuery<I, Word<O>>(state.getAccessSequence(), Word.epsilon()) {

@Override
public void answer(Word<O> output) {
state.setProperty(output.firstSymbol());
}
};
}

@Override
protected @Nullable Query<I, Word<O>> tpQuery(HTransition<I, Word<O>, O, Void> transition) {
return null;
}

@Override
public MooreMachine<?, I, ?, O> getHypothesisModel() {
return hypWrapper;
}

@Override
public void resume(DTLearnerState<I, Word<O>, O, Void> state) {
super.resume(state);
this.hypWrapper = new HypothesisWrapperMoore<>(getHypothesisDS());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Copyright (C) 2013-2022 TU Dortmund
* This file is part of LearnLib, http://www.learnlib.de/.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.algorithms.discriminationtree.moore;

import java.util.Collection;

import de.learnlib.algorithms.discriminationtree.hypothesis.DTLearnerHypothesis;
import de.learnlib.algorithms.discriminationtree.hypothesis.HState;
import de.learnlib.algorithms.discriminationtree.hypothesis.HTransition;
import net.automatalib.automata.transducers.MooreMachine;
import net.automatalib.words.Word;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* A {@link MooreMachine}-based specialization of the DT learner hypothesis.
*
* @param <I>
* input symbol type
* @param <O>
* output symbol type
*
* @author bayram
* @author frohme
*/
public class HypothesisWrapperMoore<I, O>
implements MooreMachine<HState<I, Word<O>, O, Void>, I, HTransition<I, Word<O>, O, Void>, O> {

private final DTLearnerHypothesis<I, Word<O>, O, Void> dtHypothesis;

HypothesisWrapperMoore(DTLearnerHypothesis<I, Word<O>, O, Void> dtHypothesis) {
this.dtHypothesis = dtHypothesis;
}

@Override
public O getStateOutput(HState<I, Word<O>, O, Void> state) {
return state.getProperty();
}

@Override
public Collection<HState<I, Word<O>, O, Void>> getStates() {
return dtHypothesis.getStates();
}

@Override
public @Nullable HState<I, Word<O>, O, Void> getInitialState() {
return dtHypothesis.getInitialState();
}

@Override
public @Nullable HTransition<I, Word<O>, O, Void> getTransition(HState<I, Word<O>, O, Void> state, I input) {
return dtHypothesis.getTransition(state, input);
}

@Override
public HState<I, Word<O>, O, Void> getSuccessor(HTransition<I, Word<O>, O, Void> transition) {
return dtHypothesis.getSuccessor(transition);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (C) 2013-2022 TU Dortmund
* This file is part of LearnLib, http://www.learnlib.de/.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.algorithms.discriminationtree;

import de.learnlib.algorithms.discriminationtree.moore.DTLearnerMoore;
import de.learnlib.api.oracle.MembershipOracle;
import de.learnlib.counterexamples.LocalSuffixFinders;
import de.learnlib.testsupport.AbstractGrowingAlphabetMooreTest;
import net.automatalib.words.Alphabet;
import net.automatalib.words.Word;

/**
* @author frohme
*/
public class DTLearnerMooreGrowingAlphabetTest
extends AbstractGrowingAlphabetMooreTest<DTLearnerMoore<Character, Character>> {

@Override
protected DTLearnerMoore<Character, Character> getLearner(MembershipOracle<Character, Word<Character>> oracle,
Alphabet<Character> alphabet) {
return new DTLearnerMoore<>(alphabet, oracle, LocalSuffixFinders.RIVEST_SCHAPIRE, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (C) 2013-2022 TU Dortmund
* This file is part of LearnLib, http://www.learnlib.de/.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.algorithms.discriminationtree;

import de.learnlib.algorithms.discriminationtree.moore.DTLearnerMooreBuilder;
import de.learnlib.api.oracle.MembershipOracle.MooreMembershipOracle;
import de.learnlib.counterexamples.LocalSuffixFinder;
import de.learnlib.counterexamples.LocalSuffixFinders;
import de.learnlib.testsupport.it.learner.AbstractMooreLearnerIT;
import de.learnlib.testsupport.it.learner.LearnerVariantList.MooreLearnerVariantList;
import net.automatalib.words.Alphabet;
import net.automatalib.words.Word;
import org.testng.annotations.Test;

@Test
public class DTLearnerMooreIT extends AbstractMooreLearnerIT {

@Override
protected <I, O> void addLearnerVariants(Alphabet<I> alphabet,
MooreMembershipOracle<I, O> mqOracle,
MooreLearnerVariantList<I, O> variants) {
DTLearnerMooreBuilder<I, O> builder = new DTLearnerMooreBuilder<>();
builder.setAlphabet(alphabet);
builder.setOracle(mqOracle);

for (LocalSuffixFinder<? super I, ? super Word<O>> suffixFinder : LocalSuffixFinders.values()) {
builder.setSuffixFinder(suffixFinder);

String name = "suffixFinder=" + suffixFinder.toString();
variants.addLearnerVariant(name, builder.create());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Copyright (C) 2013-2022 TU Dortmund
* This file is part of LearnLib, http://www.learnlib.de/.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.algorithms.discriminationtree;

import de.learnlib.algorithms.discriminationtree.moore.DTLearnerMoore;
import de.learnlib.algorithms.discriminationtree.moore.DTLearnerMooreBuilder;
import de.learnlib.api.oracle.MembershipOracle;
import de.learnlib.testsupport.AbstractResumableLearnerMooreTest;
import net.automatalib.words.Alphabet;
import net.automatalib.words.Word;

/**
* @author frohme
*/
public class DTLearnerMooreResumableLearnerTest
extends AbstractResumableLearnerMooreTest<DTLearnerMoore<Character, Character>, DTLearnerState<Character, Word<Character>, Character, Void>> {

@Override
protected DTLearnerMoore<Character, Character> getLearner(final MembershipOracle<Character, Word<Character>> oracle,
final Alphabet<Character> alphabet) {
return new DTLearnerMooreBuilder<Character, Character>().withAlphabet(alphabet).withOracle(oracle).create();
}

@Override
protected int getRounds() {
return 5;
}
}
Loading