• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / learnlib / 6660471831

26 Oct 2023 10:29PM UTC coverage: 93.327% (-0.001%) from 93.328%
6660471831

push

github

mtf90
cleanup statistics filters

32 of 32 new or added lines in 7 files covered. (100.0%)

11734 of 12573 relevant lines covered (93.33%)

1.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.97
/examples/src/main/java/de/learnlib/example/aaar/AlternatingBitExampleGeneric.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of LearnLib, http://www.learnlib.de/.
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 de.learnlib.example.aaar;
17

18
import java.io.IOException;
19
import java.io.StringWriter;
20
import java.util.Arrays;
21
import java.util.function.Function;
22

23
import de.learnlib.algorithm.aaar.generic.GenericAAARLearnerMealy;
24
import de.learnlib.algorithm.lstar.mealy.ExtensibleLStarMealy;
25
import de.learnlib.algorithm.lstar.mealy.ExtensibleLStarMealyBuilder;
26
import de.learnlib.api.algorithm.LearnerConstructor;
27
import de.learnlib.api.query.DefaultQuery;
28
import de.learnlib.datastructure.observationtable.OTLearner.OTLearnerMealy;
29
import de.learnlib.datastructure.observationtable.writer.ObservationTableASCIIWriter;
30
import de.learnlib.example.aaar.Event.Msg;
31
import de.learnlib.example.aaar.Event.Recv;
32
import net.automatalib.automaton.transducer.MealyMachine;
33
import net.automatalib.common.util.Pair;
34
import net.automatalib.graph.concept.GraphViewable;
35
import net.automatalib.serialization.dot.GraphDOT;
36
import net.automatalib.visualization.dot.DOT;
37
import net.automatalib.word.Word;
38

39
/**
40
 * Example from the paper "Automata Learning with Automated Alphabet Abstraction Refinement" by Howar et al., which uses
41
 * the generic version of the AAAR learner.
42
 */
43
@SuppressWarnings("PMD.SystemPrintln")
44
public final class AlternatingBitExampleGeneric {
45

46
    private static final int ID1 = 72;
47
    private static final int ID2 = 73;
48

49
    private AlternatingBitExampleGeneric() {
50
        // prevent instantiation
51
    }
52

53
    public static void main(String[] args) throws IOException {
54

55
        final Protocol mqo = new Protocol();
1✔
56

57
        final LearnerConstructor<ExtensibleLStarMealy<Event, String>, Event, Word<String>> lstar =
1✔
58
                (alph, mq) -> new ExtensibleLStarMealyBuilder<Event, String>().withAlphabet(alph)
1✔
59
                                                                              .withOracle(mq)
1✔
60
                                                                              .create();
1✔
61

62
        final GenericAAARLearnerMealy<ExtensibleLStarMealy<Event, String>, String, Event, String> learner =
1✔
63
                new GenericAAARLearnerMealy<>(lstar, mqo, new Recv(), new EventAbstractor());
64

65
        learner.startLearning();
1✔
66
        printInfo(learner);
1✔
67

68
        learner.refineHypothesis(new DefaultQuery<>(Word.epsilon(),
1✔
69
                                                    Word.fromSymbols(new Msg<>(0, "d"), new Recv()),
1✔
70
                                                    Word.fromSymbols("ind", "ack(0)")));
1✔
71
        printInfo(learner);
1✔
72

73
        learner.refineHypothesis(new DefaultQuery<>(Word.epsilon(),
1✔
74
                                                    Word.fromSymbols(new Msg<>(ID1, "d'"),
1✔
75
                                                                     new Recv(),
76
                                                                     new Msg<>(ID2, "d''")),
77
                                                    Word.fromSymbols("ind", "ack(0)", "ind")));
1✔
78
        printInfo(learner);
1✔
79
    }
1✔
80

81
    private static <AI, CI, O> void printInfo(GenericAAARLearnerMealy<? extends OTLearnerMealy<CI, O>, AI, CI, O> learner)
82
            throws IOException {
83

84
        System.out.println("-------------------------------------------------------");
1✔
85
        new ObservationTableASCIIWriter<>().write(learner.getLearner().getObservationTable(), System.out);
1✔
86

87
        if (DOT.checkUsable()) {
1✔
88
            final MealyMachine<?, AI, ?, O> hyp = learner.getHypothesisModel();
1✔
89

90
            try (StringWriter hypWriter = new StringWriter();
1✔
91
                 StringWriter treeWriter = new StringWriter()) {
1✔
92

93
                GraphDOT.write(hyp.transitionGraphView(learner.getAbstractAlphabet()), hypWriter);
1✔
94
                GraphDOT.write((GraphViewable) learner.getAbstractionTree(), treeWriter);
1✔
95

96
                DOT.renderDOTStrings(Arrays.asList(Pair.of("Hypothesis", hypWriter.toString()),
1✔
97
                                                   Pair.of("Abstraction Tree", treeWriter.toString())), true);
1✔
98
            }
99
        }
100
    }
1✔
101

102
    private static class EventAbstractor implements Function<Event, String> {
103

104
        private int cnt;
105

106
        @Override
107
        public String apply(Event event) {
108
            if (event instanceof Recv) {
1✔
109
                return "recv";
1✔
110
            } else if (event instanceof Msg) {
1✔
111
                return "msg" + cnt++;
1✔
112
            } else {
113
                throw new IllegalArgumentException("Unknown event: " + event);
×
114
            }
115
        }
116
    }
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc