Skip to content

Commit 507bb0c

Browse files
committed
Added copyright headers, used new visualization framework in examples
1 parent 5023953 commit 507bb0c

9 files changed

Lines changed: 82 additions & 34 deletions

File tree

algorithms/features/src/main/java/de/learnlib/algorithms/features/observationtable/ObservationTable.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ public static interface Row<I,D> extends Iterable<D> {
129129
public D getCellContent(@Nonnegative int index) throws IndexOutOfBoundsException;
130130
}
131131

132-
133132
/**
134133
* Representation of an inconsistency in the observation table.
135134
* <p>

algorithms/ttt/src/main/java/de/learnlib/algorithms/ttt/base/BaseTTTLearner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ private Splitter<I,D> findSplitter(DTNode<I,D> blockRoot) {
528528
* @return a counterexample uncovering an inconsistency, or {@code null}
529529
* if the hypothesis is consistent with the discrimination tree
530530
*/
531+
// TODO can be removed
531532
private DefaultQuery<I, D> checkHypothesisConsistency() {
532533
for(DTNode<I,D> leaf : dtree.getRoot().subtreeLeaves()) {
533534
TTTState<I,D> state = leaf.state;

core/src/main/java/de/learnlib/nfa/NFALearner.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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+
*/
117
package de.learnlib.nfa;
218

319
import net.automatalib.automata.fsa.NFA;

core/src/main/java/de/learnlib/nfa/NFALearnerWrapper.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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+
*/
117
package de.learnlib.nfa;
218

319
import javax.annotation.Nonnull;

core/src/main/java/de/learnlib/statistics/SimpleProfiler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
package de.learnlib.statistics;
1919

20-
import java.util.HashMap;
2120
import java.util.Map;
2221
import java.util.Map.Entry;
22+
import java.util.concurrent.ConcurrentHashMap;
2323

2424
import javax.annotation.Nonnull;
2525
import javax.annotation.ParametersAreNonnullByDefault;
@@ -34,8 +34,8 @@ public class SimpleProfiler {
3434

3535
private static boolean PROFILE = true;
3636

37-
private static final Map<String,Counter> cumulated = new HashMap<>();
38-
private static final Map<String,Long> pending = new HashMap<>();
37+
private static final Map<String,Counter> cumulated = new ConcurrentHashMap<>();
38+
private static final Map<String,Long> pending = new ConcurrentHashMap<>();
3939

4040
private static LearnLogger logger = LearnLogger.getLogger(SimpleProfiler.class.getName());
4141

examples/src/main/java/de/learnlib/examples/example1/Example.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717
package de.learnlib.examples.example1;
1818

1919
import java.io.IOException;
20-
import java.io.Writer;
2120

21+
import net.automatalib.automata.fsa.DFA;
22+
import net.automatalib.automata.fsa.impl.compact.CompactDFA;
23+
import net.automatalib.util.automata.builders.AutomatonBuilders;
24+
import net.automatalib.util.graphs.dot.GraphDOT;
25+
import net.automatalib.visualization.Visualization;
26+
import net.automatalib.words.Alphabet;
27+
import net.automatalib.words.impl.Alphabets;
2228
import de.learnlib.algorithms.features.observationtable.OTUtils;
2329
import de.learnlib.algorithms.features.observationtable.writer.ObservationTableASCIIWriter;
2430
import de.learnlib.algorithms.lstargeneric.dfa.ExtensibleLStarDFA;
@@ -30,13 +36,6 @@
3036
import de.learnlib.oracles.SimulatorOracle.DFASimulatorOracle;
3137
import de.learnlib.statistics.SimpleProfiler;
3238

33-
import net.automatalib.automata.fsa.DFA;
34-
import net.automatalib.automata.fsa.impl.compact.CompactDFA;
35-
import net.automatalib.commons.dotutil.DOT;
36-
import net.automatalib.util.graphs.dot.GraphDOT;
37-
import net.automatalib.words.Alphabet;
38-
import net.automatalib.words.impl.Alphabets;
39-
4039
/**
4140
* This example shows the usage of a learning algorithm and an equivalence test
4241
* as part of an experiment in order to learn a simulated SUL (system under
@@ -55,22 +54,23 @@ private static CompactDFA<Character> constructSUL() {
5554
// input alphabet contains characters 'a'..'b'
5655
Alphabet<Character> sigma = Alphabets.characters('a', 'b');
5756

58-
// create states
59-
CompactDFA<Character> dfa = new CompactDFA<>(sigma);
60-
int q0 = dfa.addInitialState(true);
61-
int q1 = dfa.addState(false);
62-
int q2 = dfa.addState(false);
63-
int q3 = dfa.addState(false);
64-
65-
// create transitions
66-
dfa.addTransition(q0, 'a', q1);
67-
dfa.addTransition(q0, 'b', q2);
68-
dfa.addTransition(q1, 'a', q0);
69-
dfa.addTransition(q1, 'b', q3);
70-
dfa.addTransition(q2, 'a', q3);
71-
dfa.addTransition(q2, 'b', q0);
72-
dfa.addTransition(q3, 'a', q2);
73-
dfa.addTransition(q3, 'b', q1);
57+
// create automaton
58+
CompactDFA<Character> dfa = AutomatonBuilders.newDFA(sigma)
59+
.from("q0")
60+
.on('a').to("q1")
61+
.on('b').to("q2")
62+
.from("q1")
63+
.on('a').to("q0")
64+
.on('b').to("q3")
65+
.from("q2")
66+
.on('a').to("q3")
67+
.on('b').to("q0")
68+
.from("q3")
69+
.on('a').to("q2")
70+
.on('b').to("q1")
71+
.withInitial("q0")
72+
.withAccepting("q0")
73+
.create();
7474

7575
return dfa;
7676
}
@@ -142,9 +142,7 @@ public static void main(String[] args) throws IOException {
142142
System.out.println("Model: ");
143143
GraphDOT.write(result, inputs, System.out); // may throw IOException!
144144

145-
Writer w = DOT.createDotWriter(true);
146-
GraphDOT.write(result, inputs, w);
147-
w.close();
145+
Visualization.visualizeAutomaton(result, inputs, true);
148146

149147
System.out.println("-------------------------------------------------------");
150148

test-support/learner-it-support/src/main/java/de/learnlib/testsupport/it/learner/LearnerVariant.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ public LearnerVariant(String name, LearningAlgorithm<? extends M,I,D> learner, i
2929
this.learner = learner;
3030
this.maxRounds = maxRounds;
3131
}
32+
33+
public String getLearnerName() {
34+
String learnerName = learner.toString();
35+
int atPos = learnerName.lastIndexOf('@');
36+
if (atPos != -1) {
37+
int simpleNameStart = learnerName.lastIndexOf('.', atPos - 1) + 1;
38+
learnerName = learnerName.substring(simpleNameStart, atPos);
39+
}
40+
41+
return learnerName;
42+
}
3243

3344
public String getName() {
3445
return name;

test-support/learner-it-support/src/main/java/de/learnlib/testsupport/it/learner/LearnerVariantListImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import net.automatalib.automata.fsa.DFA;
2323
import net.automatalib.automata.transout.MealyMachine;
2424
import net.automatalib.words.Word;
25-
2625
import de.learnlib.api.LearningAlgorithm;
2726
import de.learnlib.mealy.MealyUtil;
2827

test-support/learner-it-support/src/main/java/de/learnlib/testsupport/it/learner/SingleLearnerVariantITSubCase.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ public SingleLearnerVariantITSubCase(LearnerVariant<? extends M,I,D> variant, Le
4444

4545
@Override
4646
public String getTestName() {
47-
return variant.getLearner().getClass().getSimpleName() + "[" + variant.getName() + "]/" + example.getClass().getSimpleName();
47+
return variant.getLearnerName() + "[" + variant.getName() + "]/" + example.getClass().getSimpleName();
4848
}
4949

5050
@Test
5151
public void testLearning() {
52-
System.out.println("Running learner integration test " + getTestName());
52+
System.out.print("Running learner integration test " + getTestName() + " ... ");
53+
System.out.flush();
54+
5355
LearningAlgorithm<? extends M,I,D> learner
5456
= variant.getLearner();
5557

@@ -63,6 +65,8 @@ public void testLearning() {
6365
EquivalenceOracle<? super M, I, D> eqOracle
6466
= new SimulatorEQOracle<I,D>(example.getReferenceAutomaton());
6567

68+
long start = System.nanoTime();
69+
6670
learner.startLearning();
6771

6872
int roundCounter = 0;
@@ -81,6 +85,10 @@ public void testLearning() {
8185
Assert.assertNull(
8286
Automata.findSeparatingWord(example.getReferenceAutomaton(), learner.getHypothesisModel(), alphabet),
8387
"Final hypothesis does not match reference automaton");
88+
89+
long duration = (System.nanoTime() - start)/1000000L;
90+
System.out.printf("ok [%d.%03ds]", duration/1000L, duration%1000L);
91+
System.out.println();
8492
}
8593

8694

0 commit comments

Comments
 (0)