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

LearnLib / automatalib / 13138848026

04 Feb 2025 02:53PM UTC coverage: 92.108% (+2.2%) from 89.877%
13138848026

push

github

mtf90
[maven-release-plugin] prepare release automatalib-0.12.0

16609 of 18032 relevant lines covered (92.11%)

1.7 hits per line

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

90.0
/util/src/main/java/net/automatalib/util/minimizer/MinimizationResult.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of AutomataLib <https://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.minimizer;
17

18
import java.util.Collection;
19

20
import net.automatalib.common.util.mapping.Mapping;
21

22
/**
23
 * The result structure of a minimization process. The result of a minimization process is a partition on the original
24
 * set of states. This is represented by a collection of {@link Block}s containing states that are equivalent and thus
25
 * can be merged.
26
 * <p>
27
 * Since all states in a block are equivalent (and thus especially have the same set of outgoing edge labels), a
28
 * minimized automaton can be created from this partition by instantiating a state for each block. The edges between
29
 * those states are created in the following way: For each state/block, an original state is chosen arbitrarily from
30
 * this block. The edges are created according to the edges of this state, only that they point to the states
31
 * representing the blocks the respective target states belong to (using {@link #getBlockForState(Object)}).
32
 * <p>
33
 * The blocks in the result partition are guaranteed to have contiguous IDs (see {@link Block#getId()}), starting at 0.
34
 * This allows an efficient construction of the resulting automaton.
35
 *
36
 * @param <S>
37
 *         state type
38
 * @param <L>
39
 *         transition label type
40
 */
41
public final class MinimizationResult<S, L> {
42

43
    // the state storage, used for retrieving the State records
44
    // for an original state
45
    private final Mapping<S, State<S, L>> stateStorage;
46
    // the blocks in the final partition
47
    private final Collection<Block<S, L>> blocks;
48

49
    /**
50
     * Constructor.
51
     *
52
     * @param stateStorage
53
     *         the state storage,
54
     * @param blocks
55
     *         the final partition.
56
     */
57
    MinimizationResult(Mapping<S, State<S, L>> stateStorage, Collection<Block<S, L>> blocks) {
2✔
58
        this.stateStorage = stateStorage;
2✔
59
        this.blocks = blocks;
2✔
60
    }
2✔
61

62
    /**
63
     * Retrieves all (original) states in a block.
64
     *
65
     * @param block
66
     *         the block.
67
     * @param <S>
68
     *         state type
69
     * @param <L>
70
     *         transition label type
71
     *
72
     * @return a collection containing all original states in this block.
73
     */
74
    public static <S, L> Collection<S> getStatesInBlock(Block<S, L> block) {
75
        return new OriginalStateCollection<>(block.getStates());
×
76
    }
77

78
    /**
79
     * Retrieves the number of blocks in the final partition.
80
     *
81
     * @return the number of blocks.
82
     */
83
    public int getNumBlocks() {
84
        return blocks.size();
2✔
85
    }
86

87
    /**
88
     * Retrieves all blocks in the final partition.
89
     *
90
     * @return the final partition.
91
     */
92
    public Collection<Block<S, L>> getBlocks() {
93
        return blocks;
2✔
94
    }
95

96
    /**
97
     * Chooses a representative (i.e., an arbitrary element of the set of states) from a block.
98
     *
99
     * @param block
100
     *         the block.
101
     *
102
     * @return an arbitrary element of the state set of the given block.
103
     */
104
    public S getRepresentative(Block<S, L> block) {
105
        return block.getStates().choose().getOriginalState();
2✔
106
    }
107

108
    /**
109
     * Retrieves the block to which a given original state belongs.
110
     *
111
     * @param origState
112
     *         the original state.
113
     *
114
     * @return the corresponding block.
115
     */
116
    public Block<S, L> getBlockForState(S origState) {
117
        State<S, L> state = stateStorage.get(origState);
2✔
118
        return state.getBlock();
2✔
119
    }
120
}
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