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

LearnLib / automatalib / 6673214172

27 Oct 2023 11:30PM UTC coverage: 89.166% (-0.6%) from 89.796%
6673214172

push

github

mtf90
cleanup release configuration

15399 of 17270 relevant lines covered (89.17%)

1.67 hits per line

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

71.43
/api/src/main/java/net/automatalib/automaton/vpa/SEVPAGraphView.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of AutomataLib, http://www.automatalib.net/.
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 net.automatalib.automaton.vpa;
17

18
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.Collections;
21
import java.util.List;
22
import java.util.Map;
23

24
import net.automatalib.alphabet.VPAlphabet;
25
import net.automatalib.automaton.vpa.SEVPAGraphView.SevpaViewEdge;
26
import net.automatalib.graph.Graph;
27
import net.automatalib.visualization.DefaultVisualizationHelper;
28
import net.automatalib.visualization.VisualizationHelper;
29
import org.checkerframework.checker.nullness.qual.Nullable;
30

31
public class SEVPAGraphView<L, I> implements Graph<L, SevpaViewEdge<L, I>> {
32

33
    private final SEVPA<L, I> sevpa;
34
    private final VPAlphabet<I> alphabet;
35

36
    public SEVPAGraphView(SEVPA<L, I> sevpa) {
1✔
37
        this.sevpa = sevpa;
1✔
38
        this.alphabet = sevpa.getInputAlphabet();
1✔
39
    }
1✔
40

41
    @Override
42
    public Collection<L> getNodes() {
43
        return Collections.unmodifiableCollection(sevpa.getLocations());
1✔
44
    }
45

46
    @Override
47
    public Collection<SevpaViewEdge<L, I>> getOutgoingEdges(L location) {
48

49
        final List<SevpaViewEdge<L, I>> result = new ArrayList<>();
1✔
50

51
        // all call transitions
52
        for (I i : alphabet.getCallAlphabet()) {
1✔
53
            final L succ = sevpa.getModuleEntry(i);
1✔
54
            if (succ != null) {
1✔
55
                result.add(new SevpaViewEdge<>(i, succ));
1✔
56
            }
57
        }
1✔
58

59
        // all internal transitions
60
        for (I i : alphabet.getInternalAlphabet()) {
1✔
61
            final L succ = sevpa.getInternalSuccessor(location, i);
1✔
62
            if (succ != null) {
1✔
63
                result.add(new SevpaViewEdge<>(i, succ));
1✔
64
            }
65
        }
1✔
66

67
        // all return transitions for every possible stack contents
68
        for (I i : alphabet.getReturnAlphabet()) {
1✔
69
            for (L loc : sevpa.getLocations()) {
1✔
70
                for (I stackSymbol : alphabet.getCallAlphabet()) {
1✔
71
                    final int sym = sevpa.encodeStackSym(loc, stackSymbol);
1✔
72
                    final L succ = sevpa.getReturnSuccessor(location, i, sym);
1✔
73

74
                    if (succ != null) {
1✔
75
                        result.add(new SevpaViewEdge<>(i, succ, sevpa.getLocationId(loc), stackSymbol));
1✔
76
                    }
77
                }
1✔
78
            }
1✔
79
        }
1✔
80

81
        return result;
1✔
82
    }
83

84
    @Override
85
    public L getTarget(SevpaViewEdge<L, I> edge) {
86
        return edge.target;
×
87
    }
88

89
    @Override
90
    public VisualizationHelper<L, SevpaViewEdge<L, I>> getVisualizationHelper() {
91
        return new DefaultVisualizationHelper<L, SevpaViewEdge<L, I>>() {
×
92

93
            @Override
94
            protected Collection<L> initialNodes() {
95
                return Collections.singleton(sevpa.getInitialLocation());
×
96
            }
97

98
            @Override
99
            public boolean getNodeProperties(L node, Map<String, String> properties) {
100
                super.getNodeProperties(node, properties);
×
101

102
                if (sevpa.isAcceptingLocation(node)) {
×
103
                    properties.put(NodeAttrs.SHAPE, NodeShapes.DOUBLECIRCLE);
×
104
                }
105
                properties.put(NodeAttrs.LABEL, "L" + sevpa.getLocationId(node));
×
106

107
                return true;
×
108
            }
109

110
            @Override
111
            public boolean getEdgeProperties(L src, SevpaViewEdge<L, I> edge, L tgt, Map<String, String> properties) {
112
                super.getEdgeProperties(src, edge, tgt, properties);
×
113

114
                final I input = edge.input;
×
115
                if (alphabet.isReturnSymbol(input)) {
×
116
                    properties.put(EdgeAttrs.LABEL, input + "/(L" + edge.callLocId + ',' + edge.callSymbol + ')');
×
117
                } else {
118
                    properties.put(EdgeAttrs.LABEL, String.valueOf(input));
×
119
                }
120

121
                return true;
×
122
            }
123
        };
124
    }
125

126
    public static class SevpaViewEdge<S, I> {
127

128
        public final I input;
129
        public final S target;
130

131
        public final int callLocId;
132
        public final @Nullable I callSymbol;
133

134
        SevpaViewEdge(I internalAction, S target) {
135
            this(internalAction, target, -1, null);
1✔
136
        }
1✔
137

138
        SevpaViewEdge(I returnAction, S target, int callLocId, @Nullable I callSymbol) {
1✔
139
            this.input = returnAction;
1✔
140
            this.target = target;
1✔
141
            this.callLocId = callLocId;
1✔
142
            this.callSymbol = callSymbol;
1✔
143
        }
1✔
144

145
    }
146
}
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