Skip to content

Commit

Permalink
procedural: add OptimalLStar adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
mtf90 committed Oct 2, 2024
1 parent 9508c3b commit 0c2007f
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract class AbstractOptimalLStar<M extends SuffixOutput<I, D>, I, D> implemen

abstract boolean symbolInconsistency(Word<I> u1, Word<I> u2, I a);

abstract List<D> rowForState(Word<I> input);
protected abstract List<D> rowForState(Word<I> input);

@Override
public void startLearning() {
Expand Down Expand Up @@ -218,7 +218,7 @@ private List<Word<I>> getShortPrefixes(Word<I> prefix) {
return getShortPrefixes(rowData);
}

List<Word<I>> getShortPrefixes(List<D> rowData) {
protected List<Word<I>> getShortPrefixes(List<D> rowData) {
List<Word<I>> shortReps = new ArrayList<>();
for (Entry<Word<I>, List<D>> e : rows.entrySet()) {
if (shortPrefixes.contains(e.getKey()) && rowData.equals(e.getValue())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public int size() {
}

@Override
public List<Boolean> rowForState(Word<I> input) {
protected List<Boolean> rowForState(Word<I> input) {
return hypStateMap.get(hypothesis.getState(input));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public int size() {
}

@Override
public List<Word<O>> rowForState(Word<I> input) {
protected List<Word<O>> rowForState(Word<I> input) {
return hypStateMap.get(hypothesis.getState(input));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (C) 2013-2024 TU Dortmund University
* 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.algorithm.procedural.adapter.dfa;

import java.util.List;

import de.learnlib.AccessSequenceTransformer;
import de.learnlib.algorithm.oml.lstar.OptimalLStarDFA;
import de.learnlib.oracle.MembershipOracle;
import net.automatalib.alphabet.Alphabet;
import net.automatalib.word.Word;

/**
* Adapter for using {@link OptimalLStarDFA} as a procedural learner.
*
* @param <I>
* input symbol type
*/
public class OptimalLStarAdapterDFA<I> extends OptimalLStarDFA<I> implements AccessSequenceTransformer<I> {

public OptimalLStarAdapterDFA(Alphabet<I> alphabet, MembershipOracle<I, Boolean> oracle) {
super(alphabet, oracle);
}

@Override
public Word<I> transformAccessSequence(Word<I> word) {
final List<Boolean> row = super.rowForState(word);
final List<Word<I>> shortPrefixes = super.getShortPrefixes(row);

assert shortPrefixes.size() == 1;

return shortPrefixes.get(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Copyright (C) 2013-2024 TU Dortmund University
* 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.algorithm.procedural.adapter.mealy;

import java.util.List;

import de.learnlib.AccessSequenceTransformer;
import de.learnlib.algorithm.oml.lstar.OptimalLStarMealy;
import de.learnlib.oracle.MembershipOracle;
import net.automatalib.alphabet.Alphabet;
import net.automatalib.word.Word;

/**
* Adapter for using {@link OptimalLStarMealy} as a procedural learner.
*
* @param <I>
* input symbol type
* @param <O>
* output symbol type
*/
public class OptimalLStarAdapterMealy<I, O> extends OptimalLStarMealy<I, O> implements AccessSequenceTransformer<I> {

public OptimalLStarAdapterMealy(Alphabet<I> alphabet, MembershipOracle<I, Word<O>> oracle) {
super(alphabet, oracle);
}

@Override
public Word<I> transformAccessSequence(Word<I> word) {
final List<Word<O>> row = super.rowForState(word);
final List<Word<I>> shortPrefixes = super.getShortPrefixes(row);

assert shortPrefixes.size() == 1;

return shortPrefixes.get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.learnlib.algorithm.procedural.adapter.dfa.KearnsVaziraniAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.LStarBaseAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.ObservationPackAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.OptimalLStarAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.OptimalTTTAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.RivestSchapireAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.TTTAdapterDFA;
Expand All @@ -54,6 +55,7 @@ protected <I> void addLearnerVariants(ProceduralInputAlphabet<I> alphabet,
builder.addLearnerVariant(KearnsVaziraniAdapterDFA::new);
builder.addLearnerVariant(LStarBaseAdapterDFA::new);
builder.addLearnerVariant(ObservationPackAdapterDFA::new);
builder.addLearnerVariant(OptimalLStarAdapterDFA::new);
builder.addLearnerVariant(OptimalTTTAdapterDFA::new);
builder.addLearnerVariant(RivestSchapireAdapterDFA::new);
builder.addLearnerVariant(TTTAdapterDFA::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.learnlib.algorithm.procedural.adapter.dfa.KearnsVaziraniAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.LStarBaseAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.ObservationPackAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.OptimalLStarAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.OptimalTTTAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.RivestSchapireAdapterDFA;
import de.learnlib.algorithm.procedural.adapter.dfa.TTTAdapterDFA;
Expand All @@ -53,6 +54,7 @@ protected <I> void addLearnerVariants(ProceduralInputAlphabet<I> alphabet,
builder.addLearnerVariant(KearnsVaziraniAdapterDFA::new);
builder.addLearnerVariant(LStarBaseAdapterDFA::new);
builder.addLearnerVariant(ObservationPackAdapterDFA::new);
builder.addLearnerVariant(OptimalLStarAdapterDFA::new);
builder.addLearnerVariant(OptimalTTTAdapterDFA::new);
builder.addLearnerVariant(RivestSchapireAdapterDFA::new);
builder.addLearnerVariant(TTTAdapterDFA::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.learnlib.algorithm.procedural.adapter.mealy.KearnsVaziraniAdapterMealy;
import de.learnlib.algorithm.procedural.adapter.mealy.LStarBaseAdapterMealy;
import de.learnlib.algorithm.procedural.adapter.mealy.ObservationPackAdapterMealy;
import de.learnlib.algorithm.procedural.adapter.mealy.OptimalLStarAdapterMealy;
import de.learnlib.algorithm.procedural.adapter.mealy.OptimalTTTAdapterMealy;
import de.learnlib.algorithm.procedural.adapter.mealy.RivestSchapireAdapterMealy;
import de.learnlib.algorithm.procedural.adapter.mealy.TTTAdapterMealy;
Expand Down Expand Up @@ -56,6 +57,7 @@ protected <I, O> void addLearnerVariants(ProceduralInputAlphabet<I> alphabet,
builder.addLearnerVariant(LStarBaseAdapterMealy::new);
builder.addLearnerVariant(MealyDHC::new);
builder.addLearnerVariant(ObservationPackAdapterMealy::new);
builder.addLearnerVariant(OptimalLStarAdapterMealy::new);
builder.addLearnerVariant(OptimalTTTAdapterMealy::new);
builder.addLearnerVariant(RivestSchapireAdapterMealy::new);
builder.addLearnerVariant(TTTAdapterMealy::new);
Expand Down

0 comments on commit 0c2007f

Please sign in to comment.