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

LearnLib / automatalib / 8878658367

29 Apr 2024 12:35PM UTC coverage: 90.009% (-0.005%) from 90.014%
8878658367

push

github

mtf90
ci: bump versions and OSes

* do not use M1 macOS since M3C does not support it

15846 of 17605 relevant lines covered (90.01%)

1.66 hits per line

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

98.15
/util/src/main/java/net/automatalib/util/automaton/procedural/CFMPSViewSBA.java
1
/* Copyright (C) 2013-2024 TU Dortmund University
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.util.automaton.procedural;
17

18
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.Collections;
21
import java.util.HashMap;
22
import java.util.List;
23
import java.util.Map;
24
import java.util.Map.Entry;
25
import java.util.Set;
26

27
import net.automatalib.alphabet.ProceduralInputAlphabet;
28
import net.automatalib.automaton.fsa.DFA;
29
import net.automatalib.automaton.procedural.SBA;
30
import net.automatalib.common.util.HashUtil;
31
import net.automatalib.graph.ContextFreeModalProcessSystem;
32
import net.automatalib.graph.ProceduralModalProcessGraph;
33
import net.automatalib.ts.modal.transition.ProceduralModalEdgeProperty;
34
import net.automatalib.ts.modal.transition.ProceduralModalEdgeProperty.ProceduralType;
35
import org.checkerframework.checker.nullness.qual.Nullable;
36

37
/**
38
 * This class represents a {@link ContextFreeModalProcessSystem}-based view on the instrumented language of a given
39
 * {@link SBA}, which allows one to model-check language properties of {@link SBA}s with tools such as M3C.
40
 *
41
 * @param <I>
42
 *         input symbol type
43
 */
44
class CFMPSViewSBA<I> implements ContextFreeModalProcessSystem<I, Void> {
45

46
    private final SBA<?, I> sba;
47
    private final Map<I, ProceduralModalProcessGraph<?, I, ?, Void, ?>> pmpgs;
48

49
    CFMPSViewSBA(SBA<?, I> sba) {
2✔
50
        this.sba = sba;
2✔
51

52
        final Map<I, DFA<?, I>> procedures = sba.getProcedures();
2✔
53
        this.pmpgs = new HashMap<>(HashUtil.capacity(procedures.size()));
2✔
54

55
        for (Entry<I, DFA<?, I>> e : procedures.entrySet()) {
2✔
56
            this.pmpgs.put(e.getKey(), new MPGView<>(sba, e.getKey(), e.getValue()));
2✔
57
        }
2✔
58
    }
2✔
59

60
    @Override
61
    public Map<I, ProceduralModalProcessGraph<?, I, ?, Void, ?>> getPMPGs() {
62
        return this.pmpgs;
2✔
63
    }
64

65
    @Override
66
    public @Nullable I getMainProcess() {
67
        return this.sba.getInitialProcedure();
2✔
68
    }
69

70
    private static class MPGView<S, I>
71
            implements ProceduralModalProcessGraph<S, I, PMPGEdge<I, S>, Void, ProceduralModalEdgeProperty> {
72

73
        private static final Object INITIAL = new Object();
2✔
74
        private static final Object FINAL = new Object();
2✔
75

76
        private final ProceduralInputAlphabet<I> alphabet;
77
        private final I procedure;
78
        private final DFA<S, I> dfa;
79
        private final S dfaInit;
80

81
        private final S initialNode;
82
        private final S finalNode;
83
        private final List<S> nodes;
84

85
        // we make sure to handle 'init' correctly
86
        @SuppressWarnings("unchecked")
87
        MPGView(SBA<?, I> sba, I procedure, DFA<S, I> dfa) {
2✔
88

89
            final S dfaInit = dfa.getInitialState();
2✔
90
            if (dfaInit == null) {
2✔
91
                throw new IllegalArgumentException("Empty DFAs cannot be mapped to ModalProcessGraphs");
×
92
            }
93

94
            this.alphabet = sba.getInputAlphabet();
2✔
95
            this.procedure = procedure;
2✔
96
            this.dfa = dfa;
2✔
97
            this.dfaInit = dfaInit;
2✔
98

99
            final List<S> nodes = new ArrayList<>(dfa.size() + 2);
2✔
100
            this.initialNode = (S) INITIAL;
2✔
101
            this.finalNode = (S) FINAL;
2✔
102

103
            nodes.add(initialNode);
2✔
104
            nodes.add(finalNode);
2✔
105

106
            for (S s : dfa) {
2✔
107
                if (dfa.isAccepting(s)) {
2✔
108
                    nodes.add(s);
2✔
109
                }
110
            }
2✔
111

112
            this.nodes = Collections.unmodifiableList(nodes);
2✔
113
        }
2✔
114

115
        @Override
116
        public Collection<PMPGEdge<I, S>> getOutgoingEdges(S node) {
117
            if (node == initialNode) {
2✔
118
                return Collections.singletonList(new PMPGEdge<>(procedure, dfaInit, ProceduralType.INTERNAL));
2✔
119
            } else if (node == finalNode) {
2✔
120
                return Collections.emptyList();
2✔
121
            } else {
122
                final List<PMPGEdge<I, S>> result = new ArrayList<>(alphabet.size());
2✔
123

124
                for (I i : alphabet) {
2✔
125
                    S succ = dfa.getSuccessor(node, i);
2✔
126
                    if (succ != null && dfa.isAccepting(succ)) {
2✔
127
                        final ProceduralType type;
128

129
                        if (alphabet.isCallSymbol(i)) {
2✔
130
                            type = ProceduralType.PROCESS;
2✔
131
                        } else {
132
                            type = ProceduralType.INTERNAL;
2✔
133
                            if (alphabet.isReturnSymbol(i)) {
2✔
134
                                succ = this.finalNode;
2✔
135
                            }
136
                        }
137

138
                        result.add(new PMPGEdge<>(i, succ, type));
2✔
139
                    }
140
                }
2✔
141

142
                return result;
2✔
143
            }
144
        }
145

146
        @Override
147
        public S getTarget(PMPGEdge<I, S> edge) {
148
            return edge.succ;
2✔
149
        }
150

151
        @Override
152
        public Collection<S> getNodes() {
153
            return this.nodes;
2✔
154
        }
155

156
        @Override
157
        public Set<Void> getNodeProperty(S node) {
158
            return Collections.emptySet();
2✔
159
        }
160

161
        @Override
162
        public ProceduralModalEdgeProperty getEdgeProperty(PMPGEdge<I, S> edge) {
163
            return edge;
2✔
164
        }
165

166
        @Override
167
        public I getEdgeLabel(PMPGEdge<I, S> edge) {
168
            return edge.input;
2✔
169
        }
170

171
        @Override
172
        public S getFinalNode() {
173
            return this.finalNode;
2✔
174
        }
175

176
        @Override
177
        public S getInitialNode() {
178
            return this.initialNode;
2✔
179
        }
180
    }
181
}
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