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

Add Tabakov-Vardi random automata generator #69

Merged
merged 9 commits into from
Jan 24, 2024

Conversation

jn1z
Copy link
Contributor

@jn1z jn1z commented Jan 22, 2024

Add Tabakov-Vardi random automata generator. This method has been used in several papers as an attempt to generate representative NFAs.

Also fix some minor Javadoc typos.

Copy link
Member

@mtf90 mtf90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. I only have some small remarks that should be fairly easy to address. The rest looks good to me.

Also, feel free to add a note/mention in the CHANGELOG.md :).

Comment on lines 30 to 32
* Generate random NFA using Tabakov and Vardi's approach, described in the paper
* <a href="https://doi.org/10.1007/11591191_28">Experimental Evaluation of Classical Automata Constructions</a>
* by Deian Tabakov and Moshe Y. Vardi.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you maybe add this description to the class level so that the description is directly available at the overview page (like here)? You can then use a more generic description for the method (like the second generateNFAmethod). However, be careful with dots as the javadoc tool typically interprets them as the end of the description. So "Moshe Y. Vardi." probably needs to be encoded as Moshe Y&nbsp;Vardi.. You can check the result with mvn site.

Comment on lines 47 to 48
public static CompactNFA<Integer> generateNFA(
Random r, int size, float td, float ad, Alphabet<Integer> alphabet) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you maybe generalize this to Alphabet<I>? You can use Alphabet#getSymbol/Alphabet#getSymbolIndex if you need to map between symbols and their respective indices. Maybe it could also be useful to add a third method that allows you to specify a MutableNFA object to write to so that you don't force CompactNFAs (like in RandomAutomata#randomDeterministic).

Copy link
Contributor Author

@jn1z jn1z Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, easy to generalize to Alphabet<I> !

I'm not sure I understand the distinction with a MutableNFA change, or how to implement it (I tend to get lost in abstraction layers). So if you're okay with it, I'll leave that part like it is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can push the changes myself afterwards.

float ad = 0.5f; // exactly 2 accepting states
Alphabet<Integer> alphabet = Alphabets.integers(0, 1);
CompactNFA<Integer> compactNFA = TabakovVardiRandomAutomata.generateNFA(r, size, td, ad, alphabet);
Assert.assertEquals(size, compactNFA.size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameters of the assertEquals methods are ordered as (actual, expected). So it would be cleaner to flip the arguments for more meaningful error messages (also in the second test case).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Apparently I've gotten that wrong for years.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI -- surprisingly, TestNG and JUnit use different parameter orders.
https://stackoverflow.com/questions/26102865/assertequals-what-is-actual-and-what-is-expected

sb.append(compactNFA.getTransitions(s, 0));
}
// 5 transitions for 0
Assert.assertEquals("[0, 3][][1, 2][3]", sb.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of String-based comparisons. Could you please compare the original Set<Integer>s instead? TestNG has assertEquals methods for sets and you can use Java 11 in the tests, so the Set.of methods are available.

@mtf90 mtf90 merged commit 81bdc13 into LearnLib:develop Jan 24, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants