• 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

60.61
/util/src/main/java/net/automatalib/util/automaton/random/RandomAutomatonGenerator.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.automaton.random;
17

18
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.List;
21
import java.util.Random;
22

23
import net.automatalib.automaton.MutableAutomaton;
24
import net.automatalib.common.util.collection.CollectionUtil;
25
import net.automatalib.common.util.random.RandomUtil;
26
import org.checkerframework.checker.nullness.qual.Nullable;
27

28
public class RandomAutomatonGenerator<S, I, T, SP, TP, A extends MutableAutomaton<S, I, T, SP, TP>> {
29

30
    protected final Random random;
31
    protected final List<? extends I> inputs;
32
    protected final List<? extends SP> spList;
33
    protected final List<? extends TP> tpList;
34
    protected final ArrayList<S> states;
35
    protected final A automaton;
36

37
    public RandomAutomatonGenerator(Random random,
38
                                    Collection<? extends I> inputs,
39
                                    Collection<? extends SP> stateProps,
40
                                    Collection<? extends TP> transProps,
41
                                    A automaton) {
2✔
42
        this.random = random;
2✔
43

44
        this.spList = CollectionUtil.randomAccessList(stateProps);
2✔
45
        this.tpList = CollectionUtil.randomAccessList(transProps);
2✔
46

47
        this.inputs = CollectionUtil.randomAccessList(inputs);
2✔
48
        this.states = new ArrayList<>();
2✔
49
        this.automaton = automaton;
2✔
50
    }
2✔
51

52
    public A getAutomaton() {
53
        return automaton;
×
54
    }
55

56
    protected @Nullable TP randomTransProperty() {
57
        return RandomUtil.choose(random, tpList);
2✔
58
    }
59

60
    protected @Nullable S randomState() {
61
        return RandomUtil.choose(random, states);
2✔
62
    }
63

64
    protected @Nullable S randomDistinctState(int stateIdx) {
65
        if (states.size() == 1) {
×
66
            return null;
×
67
        }
68

69
        int idx = random.nextInt(states.size() - 1);
×
70

71
        if (idx >= stateIdx) {
×
72
            idx++;
×
73
        }
74

75
        return states.get(idx);
×
76
    }
77

78
    protected @Nullable I randomInput() {
79
        return RandomUtil.choose(random, inputs);
×
80
    }
81

82
    public void addStates(int numStates) {
83
        states.ensureCapacity(states.size() + numStates);
2✔
84

85
        for (int i = 0; i < numStates; i++) {
2✔
86
            S state = automaton.addState(randomStateProperty());
2✔
87
            states.add(state);
2✔
88
        }
89
    }
2✔
90

91
    protected @Nullable SP randomStateProperty() {
92
        return RandomUtil.choose(random, spList);
2✔
93
    }
94

95
    public void chooseInitial() {
96
        S init = RandomUtil.choose(random, states);
2✔
97
        if (init != null) {
2✔
98
            automaton.setInitial(init, true);
2✔
99
        }
100
    }
2✔
101

102
    public void chooseInitials(int num) {
103
        List<S> inits = RandomUtil.sampleUnique(random, states, num);
×
104

105
        for (S init : inits) {
×
106
            automaton.setInitial(init, true);
×
107
        }
×
108
    }
×
109

110
}
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