Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of confluent states in DAG builders #80

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed

* Fixed a bug in `SBAs#toCFMPS` which would allow the returned view to reach a final node on a non-return symbol.
* Fixed (another) inconsistency bug in `Incremental*DAGBuilder`s.


## [0.11.0](https://github.com/LearnLib/automatalib/releases/tag/automatalib-0.11.0) - 2023-11-06
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public void insert(Word<? extends I> word, boolean accepting) {
if (last != init) {
last = unhide(last, suffTransIdx, suffixState);

// the suffixState may be part of our current path and become confluent due to un-hiding
if (suffixState.isConfluence()) {
// update the reference with whatever state comes first
if (conf != null) {
// in case of a cyclic structure, the suffix may make predecessors of 'conf' confluent due to un-hiding
// update the reference with whatever confluent state comes first
final Iterator<Transition> iter = path.descendingIterator();
while (iter.hasNext()) {
final State s = iter.next().state;
if (s == conf || s == suffixState) {
if (s.isConfluence()) {
conf = s;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ public void insert(Word<? extends I> word, boolean accepting) {
last = unhide(last, suffTransIdx, suffixState);
}

// the suffixState may be part of our current path and become confluent due to un-hiding
if (suffixState.isConfluence()) {
// update the reference with whatever state comes first
if (conf != null) {
// in case of a cyclic structure, the suffix may make predecessors of 'conf' confluent due to un-hiding
// update the reference with whatever confluent state comes first
final Iterator<Transition> iter = path.descendingIterator();
while (iter.hasNext()) {
final State s = iter.next().state;
if (s == conf || s == suffixState) {
if (s.isConfluence()) {
conf = s;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ public void insert(Word<? extends I> word, Word<? extends O> outputWord) {
if (last != init) {
last = unhide(last, suffTransIdx, suffixState, suffTransOut);

// the suffixState may be part of our current path and become confluent due to un-hiding
if (suffixState.isConfluence()) {
// update the reference with whatever state comes first
if (conf != null) {
// in case of a cyclic structure, the suffix may make predecessors of 'conf' confluent due to un-hiding
// update the reference with whatever confluent state comes first
final Iterator<Transition<O>> iter = path.descendingIterator();
while (iter.hasNext()) {
final State<O> s = iter.next().state;
if (s == conf || s == suffixState) {
if (s.isConfluence()) {
conf = s;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ public void insert(Word<? extends I> word, Word<? extends O> outputWord) {
if (last != init) {
last = unhide(last, suffTransIdx, suffixState);

// the suffixState may be part of our current path and become confluent due to un-hiding
if (suffixState.isConfluence()) {
// update the reference with whatever state comes first
if (conf != null) {
// in case of a cyclic structure, the suffix may make predecessors of 'conf' confluent due to un-hiding
// update the reference with whatever confluent state comes first
final Iterator<Transition<O>> iter = path.descendingIterator();
while (iter.hasNext()) {
final State<O> s = iter.next().state;
if (s == conf || s == suffixState) {
if (s.isConfluence()) {
conf = s;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import net.automatalib.alphabet.Alphabet;
import net.automatalib.alphabet.impl.Alphabets;
import net.automatalib.common.util.Pair;
import net.automatalib.incremental.IntegrationUtil;
import net.automatalib.incremental.IntegrationUtil.ParsedTraces;
Expand All @@ -40,6 +41,32 @@ protected String getDOTResource() {
return "/dfa/dag.dot";
}

/**
* (DFA-adjusted) test-case based on <a href="https://github.com/LearnLib/automatalib/issues/79">AutomataLib
* issue #79</a>.
*/
@Test
public void testAutomataLib79() {
final Alphabet<Character> alphabet = Alphabets.characters('0', '3');

final Word<Character> in1 = Word.fromString("12");
final Word<Character> in2 = Word.fromString("302");
final Word<Character> in3 = Word.fromString("3023102");
final Word<Character> in4 = Word.fromString("30231023102");

final IncrementalDFADAGBuilder<Character> builder = new IncrementalDFADAGBuilder<>(alphabet);

builder.insert(in1, true);
builder.insert(in2, true);
builder.insert(in3, true);
builder.insert(in4, false); // threw a ConflictException previously

Assert.assertEquals(builder.lookup(in1), Acceptance.TRUE);
Assert.assertEquals(builder.lookup(in2), Acceptance.TRUE);
Assert.assertEquals(builder.lookup(in3), Acceptance.TRUE);
Assert.assertEquals(builder.lookup(in4), Acceptance.FALSE);
}

/**
* This tests case validates a set of traces from an external system which exposed an issue in confluence
* propagation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import net.automatalib.alphabet.Alphabet;
import net.automatalib.alphabet.impl.Alphabets;
import net.automatalib.common.util.Pair;
import net.automatalib.incremental.IntegrationUtil;
import net.automatalib.incremental.IntegrationUtil.ParsedTraces;
Expand All @@ -40,6 +41,32 @@ protected String getDOTResource() {
return "/dfa/pc_dag.dot";
}

/**
* (DFA-adjusted) test-case based on <a href="https://github.com/LearnLib/automatalib/issues/79">AutomataLib
* issue #79</a>.
*/
@Test
public void testAutomataLib79() {
final Alphabet<Character> alphabet = Alphabets.characters('0', '3');

final Word<Character> in1 = Word.fromString("12");
final Word<Character> in2 = Word.fromString("302");
final Word<Character> in3 = Word.fromString("3023102");
final Word<Character> in4 = Word.fromString("30231023102");

final IncrementalPCDFADAGBuilder<Character> builder = new IncrementalPCDFADAGBuilder<>(alphabet);

builder.insert(in1, true);
builder.insert(in2, true);
builder.insert(in3, true);
builder.insert(in4, false); // threw a ConflictException previously

Assert.assertEquals(builder.lookup(in1), Acceptance.TRUE);
Assert.assertEquals(builder.lookup(in2), Acceptance.TRUE);
Assert.assertEquals(builder.lookup(in3), Acceptance.TRUE);
Assert.assertEquals(builder.lookup(in4), Acceptance.FALSE);
}

/**
* This tests case validates a set of traces from an external system which exposed an issue in confluence
* propagation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import net.automatalib.alphabet.Alphabet;
import net.automatalib.alphabet.impl.Alphabets;
import net.automatalib.common.util.Pair;
import net.automatalib.incremental.IntegrationUtil;
import net.automatalib.incremental.IntegrationUtil.ParsedTraces;
Expand All @@ -40,6 +41,36 @@ protected String getDOTResource() {
return "/mealy/dag.dot";
}

/**
* Test case based on <a href="https://github.com/LearnLib/automatalib/issues/79">AutomataLib issue #79</a>.
*/
@Test
public void testAutomataLib79() {
final Alphabet<Character> alphabet = Alphabets.characters('0', '3');

final Word<Character> in1 = Word.fromString("12");
final Word<Character> in2 = Word.fromString("302");
final Word<Character> in3 = Word.fromString("3023102");
final Word<Character> in4 = Word.fromString("30231023");

final Word<Character> out1 = Word.fromString("21");
final Word<Character> out2 = Word.fromString("101");
final Word<Character> out3 = Word.fromString("1013201");
final Word<Character> out4 = Word.fromString("10132010");

final IncrementalMealyDAGBuilder<Character, Character> builder = new IncrementalMealyDAGBuilder<>(alphabet);

builder.insert(in1, out1);
builder.insert(in2, out2);
builder.insert(in3, out3);
builder.insert(in4, out4); // threw a ConflictException previously

Assert.assertEquals(builder.lookup(in1), out1);
Assert.assertEquals(builder.lookup(in2), out2);
Assert.assertEquals(builder.lookup(in3), out3);
Assert.assertEquals(builder.lookup(in4), out4);
}

/**
* This tests case validates a set of traces from an external system which exposed an issue in confluence
* propagation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import net.automatalib.alphabet.Alphabet;
import net.automatalib.alphabet.impl.Alphabets;
import net.automatalib.common.util.Pair;
import net.automatalib.incremental.IntegrationUtil;
import net.automatalib.incremental.IntegrationUtil.ParsedTraces;
Expand All @@ -41,6 +42,37 @@ protected String getDOTResource() {
return "/moore/dag.dot";
}

/**
* (Moore-adjusted) test-case based on <a href="https://github.com/LearnLib/automatalib/issues/79">AutomataLib
* issue #79</a>.
*/
@Test
public void testAutomataLib79() {
final Alphabet<Character> alphabet = Alphabets.characters('0', '3');

final Word<Character> in1 = Word.fromString("12");
final Word<Character> in2 = Word.fromString("302");
final Word<Character> in3 = Word.fromString("3023102");
final Word<Character> in4 = Word.fromString("30231023");

final Word<Character> out1 = Word.fromString("001");
final Word<Character> out2 = Word.fromString("0101");
final Word<Character> out3 = Word.fromString("01013101");
final Word<Character> out4 = Word.fromString("010131010");

final IncrementalMooreDAGBuilder<Character, Character> builder = new IncrementalMooreDAGBuilder<>(alphabet);

builder.insert(in1, out1);
builder.insert(in2, out2);
builder.insert(in3, out3);
builder.insert(in4, out4); // threw a ConflictException previously

Assert.assertEquals(builder.lookup(in1), out1);
Assert.assertEquals(builder.lookup(in2), out2);
Assert.assertEquals(builder.lookup(in3), out3);
Assert.assertEquals(builder.lookup(in4), out4);
}

/**
* This test is a slightly modified version of {@link IncrementalMealyDAGBuilderTest#testIntegration()}.
*/
Expand Down