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

LearnLib / learnlib / 6433387082

06 Oct 2023 03:10PM UTC coverage: 92.296% (-0.007%) from 92.303%
6433387082

push

github

mtf90
update Falk's developer id

11573 of 12539 relevant lines covered (92.3%)

1.67 hits per line

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

79.17
/algorithms/active/ttt/src/main/java/de/learnlib/algorithms/ttt/base/BaseTTTDiscriminationTree.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.algorithms.ttt.base;
17

18
import java.util.List;
19
import java.util.Map;
20
import java.util.Map.Entry;
21
import java.util.function.Predicate;
22
import java.util.function.Supplier;
23

24
import de.learnlib.api.oracle.MembershipOracle;
25
import de.learnlib.api.query.DefaultQuery;
26
import de.learnlib.datastructure.discriminationtree.model.AbstractDiscriminationTree;
27
import net.automatalib.visualization.VisualizationHelper;
28
import net.automatalib.words.Word;
29

30
/**
31
 * The discrimination tree data structure.
32
 *
33
 * @param <I>
34
 *         input symbol type
35
 */
36
public class BaseTTTDiscriminationTree<I, D>
37
        extends AbstractDiscriminationTree<Word<I>, I, D, TTTState<I, D>, AbstractBaseDTNode<I, D>> {
38

39
    public BaseTTTDiscriminationTree(MembershipOracle<I, D> oracle,
40
                                     Supplier<? extends AbstractBaseDTNode<I, D>> supplier) {
41
        this(oracle, supplier.get());
2✔
42
    }
2✔
43

44
    public BaseTTTDiscriminationTree(MembershipOracle<I, D> oracle, AbstractBaseDTNode<I, D> root) {
45
        super(root, oracle);
2✔
46
    }
2✔
47

48
    /**
49
     * Sifts an access sequence provided by an object into the tree, starting at the root. This can either be a "soft"
50
     * sift, which stops either at the leaf <b>or</b> at the first temporary node, or a "hard" sift, stopping only at a
51
     * leaf.
52
     *
53
     * @param word
54
     *         the object providing the access sequence
55
     * @param hard
56
     *         flag, whether this should be a soft or a hard sift
57
     *
58
     * @return the leaf resulting from the sift operation
59
     */
60
    public AbstractBaseDTNode<I, D> sift(Word<I> word, boolean hard) {
61
        return sift(getRoot(), word, hard);
2✔
62
    }
63

64
    public AbstractBaseDTNode<I, D> sift(AbstractBaseDTNode<I, D> start, Word<I> prefix, boolean hard) {
65
        return super.sift(start, prefix, getSiftPredicate(hard));
2✔
66
    }
67

68
    public List<AbstractBaseDTNode<I, D>> sift(List<AbstractBaseDTNode<I, D>> starts,
69
                                               List<Word<I>> prefixes,
70
                                               boolean hard) {
71
        return super.sift(starts, prefixes, getSiftPredicate(hard));
2✔
72
    }
73

74
    @Override
75
    public AbstractBaseDTNode<I, D> sift(AbstractBaseDTNode<I, D> start, Word<I> prefix) {
76
        return sift(start, prefix, true);
×
77
    }
78

79
    @Override
80
    public List<AbstractBaseDTNode<I, D>> sift(List<AbstractBaseDTNode<I, D>> starts, List<Word<I>> prefixes) {
81
        return sift(starts, prefixes, true);
×
82
    }
83

84
    @Override
85
    protected DefaultQuery<I, D> buildQuery(AbstractBaseDTNode<I, D> node, Word<I> prefix) {
86
        return new DefaultQuery<>(prefix, node.getDiscriminator());
2✔
87
    }
88

89
    private static <I, D> Predicate<AbstractBaseDTNode<I, D>> getSiftPredicate(boolean hard) {
90
        return n -> !n.isLeaf() && (hard || !n.isTemp());
2✔
91
    }
92

93
    @Override
94
    public VisualizationHelper<AbstractBaseDTNode<I, D>, Entry<D, AbstractBaseDTNode<I, D>>> getVisualizationHelper() {
95
        return new VisualizationHelper<AbstractBaseDTNode<I, D>, Entry<D, AbstractBaseDTNode<I, D>>>() {
2✔
96

97
            @Override
98
            public boolean getNodeProperties(AbstractBaseDTNode<I, D> node, Map<String, String> properties) {
99
                if (node.isLeaf()) {
2✔
100
                    properties.put(NodeAttrs.SHAPE, NodeShapes.BOX);
2✔
101
                    properties.put(NodeAttrs.LABEL, String.valueOf(node.getData()));
2✔
102
                } else {
103
                    properties.put(NodeAttrs.LABEL, node.getDiscriminator().toString());
2✔
104
                    if (!node.isTemp()) {
2✔
105
                        properties.put(NodeAttrs.SHAPE, NodeShapes.OVAL);
2✔
106
                    } else if (node.isBlockRoot()) {
×
107
                        properties.put(NodeAttrs.SHAPE, NodeShapes.DOUBLEOCTAGON);
×
108
                    } else {
109
                        properties.put(NodeAttrs.SHAPE, NodeShapes.OCTAGON);
×
110
                    }
111
                }
112

113
                return true;
2✔
114
            }
115

116
            @Override
117
            public boolean getEdgeProperties(AbstractBaseDTNode<I, D> src,
118
                                             Map.Entry<D, AbstractBaseDTNode<I, D>> edge,
119
                                             AbstractBaseDTNode<I, D> tgt,
120
                                             Map<String, String> properties) {
121
                properties.put(EdgeAttrs.LABEL, String.valueOf(edge.getValue().getParentOutcome()));
2✔
122

123
                return true;
2✔
124
            }
125
        };
126
    }
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

© 2025 Coveralls, Inc