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

LearnLib / learnlib / 20198569605

13 Dec 2025 10:10PM UTC coverage: 94.914% (+0.4%) from 94.471%
20198569605

Pull #153

github

web-flow
Merge 6a71fc929 into 879958926
Pull Request #153: Implementation for learning MMLTs, new model for collecting statistics

1823 of 1873 new or added lines in 77 files covered. (97.33%)

1 existing line in 1 file now uncovered.

14258 of 15022 relevant lines covered (94.91%)

1.73 hits per line

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

0.0
/filters/statistics/src/main/java/de/learnlib/filter/statistic/learner/RefinementCounterLearner.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of LearnLib <https://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.filter.statistic.learner;
17

18
import de.learnlib.algorithm.LearningAlgorithm;
19
import de.learnlib.algorithm.LearningAlgorithm.DFALearner;
20
import de.learnlib.algorithm.LearningAlgorithm.MealyLearner;
21
import de.learnlib.algorithm.LearningAlgorithm.MooreLearner;
22
import de.learnlib.query.DefaultQuery;
23
import de.learnlib.statistic.Statistics;
24
import de.learnlib.statistic.StatisticsKey;
25
import de.learnlib.statistic.StatisticsService;
26
import de.learnlib.tooling.annotation.refinement.GenerateRefinement;
27
import de.learnlib.tooling.annotation.refinement.Generic;
28
import de.learnlib.tooling.annotation.refinement.Mapping;
29
import net.automatalib.automaton.fsa.DFA;
30
import net.automatalib.automaton.transducer.MealyMachine;
31
import net.automatalib.automaton.transducer.MooreMachine;
32
import net.automatalib.word.Word;
33
import org.checkerframework.checker.nullness.qual.Nullable;
34

35
/**
36
 * Counts the number of hypothesis refinements.
37
 *
38
 * @param <M>
39
 *         automaton type
40
 * @param <I>
41
 *         input symbol type
42
 * @param <D>
43
 *         output domain type
44
 */
45
@GenerateRefinement(name = "DFARefinementCounterLearner",
46
                    generics = @Generic(value = "I", desc = "input symbol type"),
47
                    parentGenerics = {@Generic(clazz = DFA.class, generics = {"?", "I"}),
48
                                      @Generic("I"),
49
                                      @Generic(clazz = Boolean.class)},
50
                    typeMappings = @Mapping(from = LearningAlgorithm.class,
51
                                            to = DFALearner.class,
52
                                            generics = @Generic("I")))
53
@GenerateRefinement(name = "MealyRefinementCounterLearner",
54
                    generics = {@Generic(value = "I", desc = "input symbol type"),
55
                                @Generic(value = "O", desc = "output symbol type")},
56
                    parentGenerics = {@Generic(clazz = MealyMachine.class, generics = {"?", "I", "?", "O"}),
57
                                      @Generic("I"),
58
                                      @Generic(clazz = Word.class, generics = "O")},
59
                    typeMappings = @Mapping(from = LearningAlgorithm.class,
60
                                            to = MealyLearner.class,
61
                                            generics = {@Generic("I"), @Generic("O")}))
62
@GenerateRefinement(name = "MooreRefinementCounterLearner",
63
                    generics = {@Generic(value = "I", desc = "input symbol type"),
64
                                @Generic(value = "O", desc = "output symbol type")},
65
                    parentGenerics = {@Generic(clazz = MooreMachine.class, generics = {"?", "I", "?", "O"}),
66
                                      @Generic("I"),
67
                                      @Generic(clazz = Word.class, generics = "O")},
68
                    typeMappings = @Mapping(from = LearningAlgorithm.class,
69
                                            to = MooreLearner.class,
70
                                            generics = {@Generic("I"), @Generic("O")}))
71
public class RefinementCounterLearner<M, I, D> implements LearningAlgorithm<M, I, D> {
72

73
    /**
74
     * The {@link StatisticsKey} this class uses for counting the number of
75
     * {@link LearningAlgorithm#refineHypothesis(DefaultQuery) refinements} executed on the learning algorithm.
76
     */
NEW
77
    public static final StatisticsKey KEY_REF = new StatisticsKey("ref-cnt", "Number of refinements");
×
78

79
    private final LearningAlgorithm<M, I, D> delegate;
80
    private final StatisticsService statistics;
81
    private final StatisticsKey keyRef;
82

83
    /**
84
     * Convenience constructor for {@link RefinementCounterLearner#RefinementCounterLearner(LearningAlgorithm, String)}
85
     * which uses {@code null} as {@code id}.
86
     *
87
     * @param delegate
88
     *         the learning algorithm to delegate calls to
89
     */
90
    public RefinementCounterLearner(LearningAlgorithm<M, I, D> delegate) {
NEW
91
        this(delegate, null);
×
NEW
92
    }
×
93

94
    /**
95
     * Constructs a new counter algorithm that writes statistical data to a {@link StatisticsService}. The provided
96
     * {@code id} is used to refine the supported {@link StatisticsKey}s and allows for using multiple instances of this
97
     * class for different purposes.
98
     *
99
     * @param delegate
100
     *         the learning algorithm to delegate calls to
101
     * @param id
102
     *         the id used for specialising the statistics keys
103
     */
NEW
104
    public RefinementCounterLearner(LearningAlgorithm<M, I, D> delegate, @Nullable String id) {
×
NEW
105
        this.delegate = delegate;
×
NEW
106
        this.statistics = Statistics.getService();
×
NEW
107
        this.keyRef = KEY_REF.withId(id);
×
UNCOV
108
    }
×
109

110
    @Override
111
    public void startLearning() {
NEW
112
        delegate.startLearning();
×
113
    }
×
114

115
    @Override
116
    public boolean refineHypothesis(DefaultQuery<I, D> ceQuery) {
NEW
117
        final boolean refined = delegate.refineHypothesis(ceQuery);
×
118
        if (refined) {
×
NEW
119
            statistics.increaseCounter(keyRef, this);
×
120
        }
121
        return refined;
×
122
    }
123

124
    @Override
125
    public M getHypothesisModel() {
NEW
126
        return delegate.getHypothesisModel();
×
127
    }
128
}
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

© 2026 Coveralls, Inc