Skip to content

Commit 6b9dcf7

Browse files
committed
Added parallelization of query sorting for cache and of query dispatch for simulator
1 parent 65fcbaf commit 6b9dcf7

4 files changed

Lines changed: 47 additions & 9 deletions

File tree

core/src/main/java/de/learnlib/oracles/MQUtil.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ public static <I,D> void answerQueries(QueryAnswerer<I,D> answerer, Collection<?
6565
}
6666
}
6767

68+
public static <I,D> void answerQueriesParallel(QueryAnswerer<I,D> answerer, Collection<? extends Query<I,D>> queries) {
69+
queries.parallelStream().forEach(q -> {
70+
Word<I> prefix = q.getPrefix();
71+
Word<I> suffix = q.getSuffix();
72+
D answer = answerer.answerQuery(prefix, suffix);
73+
q.answer(answer);
74+
});
75+
}
76+
6877
public static <I,D> boolean isCounterexample(DefaultQuery<I, D> query, SuffixOutput<I, D> hyp) {
6978
D qryOut = query.getOutput();
7079
D hypOut = hyp.computeSuffixOutput(query.getPrefix(), query.getSuffix());
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright (C) 2015 TU Dortmund
2+
* This file is part of LearnLib, http://www.learnlib.de/.
3+
*
4+
* LearnLib is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License version 3.0 as published by the Free Software Foundation.
7+
*
8+
* LearnLib is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* Lesser General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU Lesser General Public
14+
* License along with LearnLib; if not, see
15+
* http://www.gnu.de/documents/lgpl.en.html.
16+
*/
17+
package de.learnlib.oracles;
18+
19+
import java.util.Collection;
20+
21+
import de.learnlib.api.MembershipOracle;
22+
import de.learnlib.api.Query;
23+
import de.learnlib.api.QueryAnswerer;
24+
25+
public interface ParallelSingleQueryOracle<I, D> extends MembershipOracle<I, D>, QueryAnswerer<I, D> {
26+
@Override
27+
default public void processQueries(Collection<? extends Query<I,D>> queries) {
28+
MQUtil.answerQueriesParallel(this, queries);
29+
}
30+
}

filters/cache/src/main/java/de/learnlib/cache/mealy/MealyCacheOracle.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.Collection;
21-
import java.util.Collections;
2221
import java.util.Comparator;
2322
import java.util.Iterator;
2423
import java.util.List;
2524
import java.util.concurrent.locks.Lock;
2625
import java.util.concurrent.locks.ReentrantLock;
2726

28-
import de.learnlib.api.MembershipOracle;
29-
import de.learnlib.api.Query;
30-
import de.learnlib.cache.LearningCacheOracle.MealyLearningCacheOracle;
31-
27+
import net.automatalib.commons.util.array.RichArray;
3228
import net.automatalib.commons.util.comparison.CmpUtil;
3329
import net.automatalib.commons.util.mappings.Mapping;
3430
import net.automatalib.incremental.mealy.IncrementalMealyBuilder;
@@ -37,6 +33,9 @@
3733
import net.automatalib.words.Alphabet;
3834
import net.automatalib.words.Word;
3935
import net.automatalib.words.WordBuilder;
36+
import de.learnlib.api.MembershipOracle;
37+
import de.learnlib.api.Query;
38+
import de.learnlib.cache.LearningCacheOracle.MealyLearningCacheOracle;
4039

4140
/**
4241
* Mealy cache. This cache is implemented as a membership oracle: upon construction, it is
@@ -160,8 +159,8 @@ public void processQueries(Collection<? extends Query<I, Word<O>>> queries) {
160159
return;
161160
}
162161

163-
List<Query<I,Word<O>>> qrys = new ArrayList<>(queries);
164-
Collections.sort(qrys, queryCmp);
162+
RichArray<Query<I,Word<O>>> qrys = new RichArray<>(queries);
163+
qrys.parallelSort(queryCmp);
165164

166165
List<MasterQuery<I,O>> masterQueries = new ArrayList<>();
167166

@@ -188,7 +187,7 @@ public void processQueries(Collection<? extends Query<I, Word<O>>> queries) {
188187
}
189188

190189
master.addSlave(q);
191-
// Update ref to increase the effectivity of the length check in
190+
// Update ref to increase the effectiveness of the length check in
192191
// isPrefixOf
193192
ref = curr;
194193
}

simulator/src/main/java/de/learnlib/oracles/SimulatorOracle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @param <I> input symbol type
3232
* @param <D> (suffix) output domain type
3333
*/
34-
public class SimulatorOracle<I, D> extends AbstractSingleQueryOracle<I, D> {
34+
public class SimulatorOracle<I, D> implements ParallelSingleQueryOracle<I, D> {
3535

3636

3737
public static class DFASimulatorOracle<I> extends SimulatorOracle<I,Boolean>

0 commit comments

Comments
 (0)