Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mtf90 committed Jan 16, 2024
1 parent 6f3ac82 commit 72218c8
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public AbstractExplicitAAARLearner(LearnerConstructor<L, CI, D> learnerConstruct
super(learnerConstructor, oracle);

this.explicitInitialAbstraction = explicitInitialAbstraction;
this.trees =
new HashMap<>(HashUtil.capacity(explicitInitialAbstraction.getInitialAbstracts().size()));
this.trees = new HashMap<>(HashUtil.capacity(explicitInitialAbstraction.getInitialAbstracts().size()));

for (AI a : explicitInitialAbstraction.getInitialAbstracts()) {
final CI rep = explicitInitialAbstraction.getRepresentative(a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Spliterators;
import java.util.stream.StreamSupport;

import de.learnlib.AccessSequenceTransformer;
import de.learnlib.algorithm.procedural.spa.ATRManager;
import net.automatalib.alphabet.ProceduralInputAlphabet;
import net.automatalib.automaton.fsa.DFA;
import net.automatalib.common.util.HashUtil;
import net.automatalib.common.util.collection.IteratorUtil;
import net.automatalib.util.automaton.cover.Covers;
import net.automatalib.word.Word;
import net.automatalib.word.WordBuilder;
Expand Down Expand Up @@ -125,13 +124,12 @@ public void scanProcedures(Map<I, ? extends DFA<?, I>> procedures,
private <S> @Nullable Word<I> getShortestHypothesisTS(DFA<S, I> hyp,
AccessSequenceTransformer<I> asTransformer,
Collection<I> inputs) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(Covers.stateCoverIterator(hyp, inputs), 0),
false)
.filter(hyp::accepts)
.map(asTransformer::transformAccessSequence)
.map(as -> this.alphabet.expand(as, terminatingSequences::get))
.min(Comparator.comparingInt(Word::size))
.orElse(null);
return IteratorUtil.stream(Covers.stateCoverIterator(hyp, inputs))
.filter(hyp::accepts)
.map(asTransformer::transformAccessSequence)
.map(as -> this.alphabet.expand(as, terminatingSequences::get))
.min(Comparator.comparingInt(Word::size))
.orElse(null);
}

private void optimizeSequences(Map<I, Word<I>> sequences) {
Expand Down
4 changes: 4 additions & 0 deletions algorithms/active/ttt-vpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ limitations under the License.
<groupId>net.automatalib</groupId>
<artifactId>automata-api</artifactId>
</dependency>
<dependency>
<groupId>net.automatalib</groupId>
<artifactId>automata-commons-util</artifactId>
</dependency>

<dependency>
<groupId>org.checkerframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import net.automatalib.automaton.vpa.SEVPA;
import net.automatalib.automaton.vpa.StackContents;
import net.automatalib.automaton.vpa.State;
import net.automatalib.common.util.collection.CollectionUtil;
import net.automatalib.word.Word;
import org.checkerframework.checker.nullness.qual.Nullable;

Expand Down Expand Up @@ -83,7 +84,7 @@ protected State<HypLoc<I>> getDefinitiveSuccessor(State<HypLoc<I>> baseState, Wo
if (trans.isTree()) {
succs.add(trans.getTreeTarget());
} else {
trans.getNonTreeTarget().subtreeLocations().forEach(succs::add);
CollectionUtil.add(succs, trans.getNonTreeTarget().subtreeLocsIterator());
}
}
}
Expand All @@ -95,7 +96,7 @@ protected State<HypLoc<I>> getDefinitiveSuccessor(State<HypLoc<I>> baseState, Wo
if (trans.isTree()) {
succs.add(trans.getTreeTarget());
} else {
trans.getNonTreeTarget().subtreeLocations().forEach(succs::add);
CollectionUtil.add(succs, trans.getNonTreeTarget().subtreeLocsIterator());
}
}
curr = new NonDetState<>(succs, curr.getStack());
Expand Down
1 change: 1 addition & 0 deletions algorithms/active/ttt-vpa/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
requires org.checkerframework.checker.qual;

requires static de.learnlib.tooling.annotation;
requires net.automatalib.common.util;

exports de.learnlib.algorithm.ttt.vpa;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import net.automatalib.alphabet.SupportsGrowingAlphabet;
import net.automatalib.common.smartcollection.ElementReference;
import net.automatalib.common.smartcollection.UnorderedCollection;
import net.automatalib.common.util.collection.CollectionsUtil;
import net.automatalib.common.util.collection.CollectionUtil;
import net.automatalib.word.Word;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -344,7 +344,7 @@ protected Set<TTTState<I, D>> getNondetSuccessors(Collection<? extends TTTState<
result.add(trans.getTreeTarget());
} else {
AbstractBaseDTNode<I, D> tgtNode = trans.getNonTreeTarget();
CollectionsUtil.add(result, tgtNode.subtreeStatesIterator());
CollectionUtil.add(result, tgtNode.subtreeStatesIterator());
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import net.automatalib.common.smartcollection.IntSeq;
import net.automatalib.common.util.IOUtil;
import net.automatalib.common.util.Pair;
import net.automatalib.common.util.collection.CollectionsUtil;
import net.automatalib.common.util.collection.CollectionUtil;
import net.automatalib.common.util.collection.IterableUtil;
import net.automatalib.serialization.dot.GraphDOT;
import net.automatalib.util.automaton.Automata;
import net.automatalib.util.automaton.conformance.WMethodTestsIterator;
Expand Down Expand Up @@ -102,11 +103,11 @@ public void testVisualization() throws IOException {

final WordBuilder<Integer> wb = new WordBuilder<>();
for (Pair<IntSeq, IntSeq> p : getExampleSamples()) {
CollectionsUtil.add(wb, p.getFirst());
CollectionUtil.add(wb, p.getFirst().iterator());
final Word<Integer> input = wb.toWord();
wb.clear();

CollectionsUtil.add(wb, p.getSecond());
CollectionUtil.add(wb, p.getSecond().iterator());
final Word<Integer> output = wb.toWord();
wb.clear();

Expand Down Expand Up @@ -134,7 +135,7 @@ public void testEquivalence(int size) {
final CompactSST<Character, String> sst = new CompactSST<>(INPUTS);

final List<Word<String>> words = new ArrayList<>();
for (List<String> t : CollectionsUtil.allTuples(OUTPUTS, 0, 3)) {
for (List<String> t : IterableUtil.allTuples(OUTPUTS, 0, 3)) {
words.add(Word.fromList(t));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ private DiscriminationTreeIterators() {
*/
public static <N extends AbstractDTNode<?, ?, ?, N>, D> Iterator<D> transformingLeafIterator(N root,
Function<? super N, D> transformer) {
return IteratorUtil.map(leafIterator(root), transformer::apply);
return IteratorUtil.map(leafIterator(root), transformer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import net.automatalib.alphabet.Alphabet;
import net.automatalib.alphabet.impl.Alphabets;
import net.automatalib.automaton.transducer.impl.CompactMealy;
import net.automatalib.common.util.collection.CollectionsUtil;
import net.automatalib.common.util.collection.IterableUtil;
import net.automatalib.util.automaton.random.RandomAutomata;
import net.automatalib.word.Word;

Expand Down Expand Up @@ -60,7 +60,7 @@ public ParallelismExample1() {

// generate 1 million (10^6) input words
this.queries = new ArrayList<>((int) Math.pow(inputs.size(), QUERIES_EXP));
for (List<Integer> input : CollectionsUtil.allTuples(inputs, QUERIES_EXP)) {
for (List<Integer> input : IterableUtil.allTuples(inputs, QUERIES_EXP)) {
queries.add(new DefaultQuery<>(Word.fromList(input)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import de.learnlib.oracle.ParallelOracle;
import de.learnlib.query.DefaultQuery;
import net.automatalib.alphabet.Alphabet;
import net.automatalib.common.util.collection.CollectionsUtil;
import net.automatalib.common.util.collection.IterableUtil;
import net.automatalib.word.Word;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void testConcurrentMembershipQueries() {

final List<CountingQuery<I, D>> queries = new ArrayList<>(numQueries);

for (List<I> word : CollectionsUtil.allTuples(alphabet, 0, MAXIMUM_LENGTH_OF_QUERIES)) {
for (List<I> word : IterableUtil.allTuples(alphabet, 0, MAXIMUM_LENGTH_OF_QUERIES)) {
queries.add(new CountingQuery<>(Word.fromList(word)));
}

Expand Down Expand Up @@ -111,9 +111,9 @@ public void testConcurrentEquivalenceQueries() {
final List<DefaultQuery<I, D>> queries =
new ArrayList<>((int) Math.pow(alphabet.size(), MAXIMUM_LENGTH_OF_QUERIES));

for (List<I> word : CollectionsUtil.allTuples(alphabet,
MAXIMUM_LENGTH_OF_QUERIES + 1,
MAXIMUM_LENGTH_OF_QUERIES + 1)) {
for (List<I> word : IterableUtil.allTuples(alphabet,
MAXIMUM_LENGTH_OF_QUERIES + 1,
MAXIMUM_LENGTH_OF_QUERIES + 1)) {
queries.add(new DefaultQuery<>(Word.fromList(word)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.automatalib.alphabet.Alphabet;
import net.automatalib.alphabet.impl.Alphabets;
import net.automatalib.automaton.transducer.impl.CompactMealy;
import net.automatalib.common.util.collection.CollectionsUtil;
import net.automatalib.common.util.collection.CollectionUtil;
import net.automatalib.common.util.random.RandomUtil;
import net.automatalib.util.automaton.random.RandomAutomata;
import net.automatalib.word.Word;
Expand Down Expand Up @@ -60,7 +60,7 @@ public static <I, D> Collection<Query<I, D>> createNoopQueries(int numQueries,
Collection<I> inputs) {

final Random r = new Random(42);
final List<? extends I> inputsAsList = CollectionsUtil.randomAccessList(inputs);
final List<? extends I> inputsAsList = CollectionUtil.randomAccessList(inputs);

List<Query<I, D>> result = new ArrayList<>(numQueries);
for (int i = 0; i < numQueries; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import net.automatalib.automaton.fsa.DFA;
import net.automatalib.automaton.transducer.MealyMachine;
import net.automatalib.automaton.transducer.MooreMachine;
import net.automatalib.common.util.collection.CollectionsUtil;
import net.automatalib.common.util.collection.IterableUtil;
import net.automatalib.word.Word;

Expand Down Expand Up @@ -128,6 +127,6 @@ public CompleteExplorationEQOracle(MembershipOracle<I, D> sulOracle, int minDept

@Override
protected Stream<Word<I>> generateTestWords(A hypothesis, Collection<? extends I> inputs) {
return IterableUtil.stream(CollectionsUtil.allTuples(inputs, minDepth, maxDepth)).map(Word::fromList);
return IterableUtil.stream(IterableUtil.allTuples(inputs, minDepth, maxDepth)).map(Word::fromList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import net.automatalib.automaton.fsa.DFA;
import net.automatalib.automaton.transducer.MealyMachine;
import net.automatalib.automaton.transducer.MooreMachine;
import net.automatalib.common.util.collection.CollectionsUtil;
import net.automatalib.common.util.collection.CollectionUtil;
import net.automatalib.word.Word;
import net.automatalib.word.WordBuilder;

Expand Down Expand Up @@ -105,7 +105,7 @@ public RandomWordsEQOracle(MembershipOracle<I, D> mqOracle,
@Override
protected Stream<Word<I>> generateTestWords(A hypothesis, Collection<? extends I> inputs) {

final List<? extends I> symbolList = CollectionsUtil.randomAccessList(inputs);
final List<? extends I> symbolList = CollectionUtil.randomAccessList(inputs);

return Stream.generate(() -> generateTestWord(symbolList, symbolList.size())).limit(maxTests);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public WMethodEQOracle(MembershipOracle<I, D> sulOracle, int lookahead, int expe
protected Stream<Word<I>> generateTestWords(A hypothesis, Collection<? extends I> inputs) {
return IteratorUtil.stream(new WMethodTestsIterator<>(hypothesis,
inputs,
Math.max(lookahead,
expectedSize - hypothesis.size())));
Math.max(lookahead, expectedSize - hypothesis.size())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public WpMethodEQOracle(MembershipOracle<I, D> sulOracle, int lookahead, int exp
protected Stream<Word<I>> generateTestWords(A hypothesis, Collection<? extends I> inputs) {
return IteratorUtil.stream(new WpMethodTestsIterator<>(hypothesis,
inputs,
Math.max(lookahead,
expectedSize - hypothesis.size())));
Math.max(lookahead, expectedSize - hypothesis.size())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import de.learnlib.query.DefaultQuery;
import de.learnlib.sul.SUL;
import net.automatalib.automaton.transducer.MealyMachine;
import net.automatalib.common.util.collection.CollectionsUtil;
import net.automatalib.common.util.collection.CollectionUtil;
import net.automatalib.word.Word;
import net.automatalib.word.WordBuilder;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -107,7 +107,7 @@ public RandomWalkEQOracle(SUL<I, O> sul, double restartProbability, long maxStep
return null;
}

List<? extends I> choices = CollectionsUtil.randomAccessList(inputs);
List<? extends I> choices = CollectionUtil.randomAccessList(inputs);
int bound = choices.size();
S cur = hypothesis.getInitialState();
WordBuilder<I> wbIn = new WordBuilder<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ protected Stream<Word<I>> generateTestWords(SBA<?, I> hypothesis, Collection<? e
return IteratorUtil.stream(new SBAWMethodTestsIterator<>(hypothesis,
alphabet,
Math.max(lookahead,
expectedSize - hypothesis.size())));
expectedSize - hypothesis.size())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ protected Stream<Word<I>> generateTestWords(SPA<?, I> hypothesis, Collection<? e
return IteratorUtil.stream(new SPATestsIterator<>(hypothesis,
alphabet,
(dfa, alph) -> new WMethodTestsIterator<>(dfa,
alph,
Math.max(lookahead,
expectedSize -
dfa.size()))));
alph,
Math.max(lookahead,
expectedSize -
dfa.size()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ protected Stream<Word<I>> generateTestWords(SPA<?, I> hypothesis, Collection<? e
return IteratorUtil.stream(new SPATestsIterator<>(hypothesis,
alphabet,
(dfa, alph) -> new WpMethodTestsIterator<>(dfa,
alph,
Math.max(
lookahead,
expectedSize -
dfa.size()))));
alph,
Math.max(lookahead,
expectedSize -
dfa.size()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ protected Stream<Word<I>> generateTestWords(SPMM<?, I, ?, O> hypothesis, Collect
return IteratorUtil.stream(new SPMMWMethodTestsIterator<>(hypothesis,
alphabet,
Math.max(lookahead,
expectedSize - hypothesis.size())));
expectedSize - hypothesis.size())));
}
}
Loading

0 comments on commit 72218c8

Please sign in to comment.