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

LearnLib / learnlib / 13181815301

06 Feb 2025 03:00PM CUT coverage: 94.368%. Remained the same
13181815301

push

github

mtf90
[maven-release-plugin] prepare for next development iteration

12484 of 13229 relevant lines covered (94.37%)

1.72 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.filter.statistic.Counter;
23
import de.learnlib.query.DefaultQuery;
24
import de.learnlib.statistic.StatisticLearner;
25
import de.learnlib.statistic.StatisticLearner.DFAStatisticLearner;
26
import de.learnlib.statistic.StatisticLearner.MealyStatisticLearner;
27
import de.learnlib.statistic.StatisticLearner.MooreStatisticLearner;
28
import de.learnlib.tooling.annotation.refinement.GenerateRefinement;
29
import de.learnlib.tooling.annotation.refinement.Generic;
30
import de.learnlib.tooling.annotation.refinement.Interface;
31
import de.learnlib.tooling.annotation.refinement.Mapping;
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
 *         automaton type
45
 * @param <I>
46
 *         input symbol type
47
 * @param <D>
48
 *         output domain type
49
 */
50
@GenerateRefinement(name = "DFARefinementCounterLearner",
51
                    generics = @Generic(value = "I", desc = "input symbol type"),
52
                    parentGenerics = {@Generic(clazz = DFA.class, generics = {"?", "I"}),
53
                                      @Generic("I"),
54
                                      @Generic(clazz = Boolean.class)},
55
                    typeMappings = @Mapping(from = LearningAlgorithm.class,
56
                                            to = DFALearner.class,
57
                                            generics = @Generic("I")),
58
                    interfaces = @Interface(clazz = DFAStatisticLearner.class, generics = @Generic("I")))
59
@GenerateRefinement(name = "MealyRefinementCounterLearner",
60
                    generics = {@Generic(value = "I", desc = "input symbol type"),
61
                                @Generic(value = "O", desc = "output symbol type")},
62
                    parentGenerics = {@Generic(clazz = MealyMachine.class, generics = {"?", "I", "?", "O"}),
63
                                      @Generic("I"),
64
                                      @Generic(clazz = Word.class, generics = "O")},
65
                    typeMappings = @Mapping(from = LearningAlgorithm.class,
66
                                            to = MealyLearner.class,
67
                                            generics = {@Generic("I"), @Generic("O")}),
68
                    interfaces = @Interface(clazz = MealyStatisticLearner.class,
69
                                            generics = {@Generic("I"), @Generic("O")}))
70
@GenerateRefinement(name = "MooreRefinementCounterLearner",
71
                    generics = {@Generic(value = "I", desc = "input symbol type"),
72
                                @Generic(value = "O", desc = "output symbol type")},
73
                    parentGenerics = {@Generic(clazz = MooreMachine.class, generics = {"?", "I", "?", "O"}),
74
                                      @Generic("I"),
75
                                      @Generic(clazz = Word.class, generics = "O")},
76
                    typeMappings = @Mapping(from = LearningAlgorithm.class,
77
                                            to = MooreLearner.class,
78
                                            generics = {@Generic("I"), @Generic("O")}),
79
                    interfaces = @Interface(clazz = MooreStatisticLearner.class,
80
                                            generics = {@Generic("I"), @Generic("O")}))
81
public class RefinementCounterLearner<M, I, D> implements StatisticLearner<M, I, D> {
82

83
    private final LearningAlgorithm<M, I, D> learningAlgorithm;
84

85
    private final Counter counter;
86

87
    public RefinementCounterLearner(LearningAlgorithm<M, I, D> learningAlgorithm) {
×
88
        this.learningAlgorithm = learningAlgorithm;
×
89
        this.counter = new Counter("Refinements", "#");
×
90
    }
×
91

92
    @Override
93
    public void startLearning() {
94
        learningAlgorithm.startLearning();
×
95
    }
×
96

97
    @Override
98
    public boolean refineHypothesis(DefaultQuery<I, D> ceQuery) {
99
        final boolean refined = learningAlgorithm.refineHypothesis(ceQuery);
×
100
        if (refined) {
×
101
            counter.increment();
×
102
        }
103
        return refined;
×
104
    }
105

106
    @Override
107
    public M getHypothesisModel() {
108
        return learningAlgorithm.getHypothesisModel();
×
109
    }
110

111
    @Override
112
    public Counter getStatisticalData() {
113
        return counter;
×
114
    }
115
}
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