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

LearnLib / learnlib / 6877022493

15 Nov 2023 12:04PM CUT coverage: 93.36%. First build
6877022493

push

github

mtf90
[maven-release-plugin] prepare release learnlib-0.17.0

11755 of 12591 relevant lines covered (93.36%)

1.69 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-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.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.buildtool.refinement.annotation.GenerateRefinement;
23
import de.learnlib.buildtool.refinement.annotation.Generic;
24
import de.learnlib.buildtool.refinement.annotation.Interface;
25
import de.learnlib.buildtool.refinement.annotation.Map;
26
import de.learnlib.filter.statistic.Counter;
27
import de.learnlib.query.DefaultQuery;
28
import de.learnlib.statistic.StatisticLearner;
29
import de.learnlib.statistic.StatisticLearner.DFAStatisticLearner;
30
import de.learnlib.statistic.StatisticLearner.MealyStatisticLearner;
31
import de.learnlib.statistic.StatisticLearner.MooreStatisticLearner;
32
import net.automatalib.automaton.fsa.DFA;
33
import net.automatalib.automaton.transducer.MealyMachine;
34
import net.automatalib.automaton.transducer.MooreMachine;
35
import net.automatalib.word.Word;
36

37
/**
38
 * Counts the number of hypothesis refinements.
39
 * <p>
40
 * The value of the {@link Counter} returned by {@link #getStatisticalData()} returns the same value as
41
 * Experiment.getRounds().
42
 *
43
 * @param <M>
44
 *         the automaton type.
45
 * @param <I>
46
 *         the input type.
47
 * @param <D>
48
 *         the output type.
49
 */
50
@GenerateRefinement(name = "DFARefinementCounterLearner",
51
                    generics = "I",
52
                    parentGenerics = {@Generic(clazz = DFA.class, generics = {"?", "I"}),
53
                                      @Generic("I"),
54
                                      @Generic(clazz = Boolean.class)},
55
                    parameterMapping = @Map(from = LearningAlgorithm.class, to = DFALearner.class, withGenerics = "I"),
56
                    interfaces = @Interface(clazz = DFAStatisticLearner.class, generics = "I"))
57
@GenerateRefinement(name = "MealyRefinementCounterLearner",
58
                    generics = {"I", "O"},
59
                    parentGenerics = {@Generic(clazz = MealyMachine.class, generics = {"?", "I", "?", "O"}),
60
                                      @Generic("I"),
61
                                      @Generic(clazz = Word.class, generics = "O")},
62
                    parameterMapping = @Map(from = LearningAlgorithm.class,
63
                                            to = MealyLearner.class,
64
                                            withGenerics = {"I", "O"}),
65
                    interfaces = @Interface(clazz = MealyStatisticLearner.class, generics = {"I", "O"}))
66
@GenerateRefinement(name = "MooreRefinementCounterLearner",
67
                    generics = {"I", "O"},
68
                    parentGenerics = {@Generic(clazz = MooreMachine.class, generics = {"?", "I", "?", "O"}),
69
                                      @Generic("I"),
70
                                      @Generic(clazz = Word.class, generics = "O")},
71
                    parameterMapping = @Map(from = LearningAlgorithm.class,
72
                                            to = MooreLearner.class,
73
                                            withGenerics = {"I", "O"}),
74
                    interfaces = @Interface(clazz = MooreStatisticLearner.class, generics = {"I", "O"}))
75
public class RefinementCounterLearner<M, I, D> implements StatisticLearner<M, I, D> {
76

77
    private final LearningAlgorithm<M, I, D> learningAlgorithm;
78

79
    private final Counter counter;
80

81
    public RefinementCounterLearner(LearningAlgorithm<M, I, D> learningAlgorithm) {
×
82
        this.learningAlgorithm = learningAlgorithm;
×
83
        this.counter = new Counter("Refinements", "#");
×
84
    }
×
85

86
    @Override
87
    public void startLearning() {
88
        learningAlgorithm.startLearning();
×
89
    }
×
90

91
    @Override
92
    public boolean refineHypothesis(DefaultQuery<I, D> ceQuery) {
93
        final boolean refined = learningAlgorithm.refineHypothesis(ceQuery);
×
94
        if (refined) {
×
95
            counter.increment();
×
96
        }
97
        return refined;
×
98
    }
99

100
    @Override
101
    public M getHypothesisModel() {
102
        return learningAlgorithm.getHypothesisModel();
×
103
    }
104

105
    @Override
106
    public Counter getStatisticalData() {
107
        return counter;
×
108
    }
109
}
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