Learning a Simple Mealy Machine with Current Version Of LearnLib (0.13.1)

103 views
Skip to first unread message

Shahbaz at 1 Ali

unread,
Aug 4, 2018, 5:12:11 AM8/4/18
to LearnLib Q&A
Hello to Everyone!

I want to learn a very simple (two-state) mealy machine (as described in attached file). It takes one coin and go to next state and on pressing a button it dispense tea and again come to its initial state.

There is one already example regarding Coffee vending machine (cav15 by Malte) and its implementation is in some old version like LearnLib (0.11). I analyzed its Mealy builder class  and tried myself to create first a "TeaMachine" (usig method like AutomatonBuilders.forMealy(machine) ) and then its learning class but i could not successful. Even in the same project of (cav15), i tried (in order to avoid incompatibilities between different versions of LearnLibs) but could not successful. If someone has same like running code project then please share or guide me. 

Thanks
simple Mealy Machine.jpg

Shahbaz at 1 Ali

unread,
Aug 4, 2018, 6:53:25 AM8/4/18
to LearnLib Q&A
Sorry, i forgot to mention in picture on entry i.e., TEA. The output alphabet is {OK, NOK, Tea}

Shahbaz at 1 Ali

unread,
Aug 4, 2018, 9:19:23 AM8/4/18
to LearnLib Q&A
I have tried to learn this model. I am getting the following error:

"Implicit super constructor DefaultLearningExample.DefaultMealyLearningExample<ExampleCoffeeMachine.Input,String>() is undefined 
 for default constructor. Must define an explicit constructor".  I find its reason on the following link and try to solve it.



II have write this explicit constructor at end of the file but it is giving error. 

Please view the uploaded 

Shahbaz at 1 Ali

unread,
Aug 4, 2018, 9:24:16 AM8/4/18
to LearnLib Q&A
Please view the uploaded code and tell me where i am wrong. Am i rightly extending the class?  
TeaMachineSUL.java

Shahbaz at 1 Ali

unread,
Aug 4, 2018, 10:38:46 PM8/4/18
to LearnLib Q&A
Actually, i want to make my own SUL class like "ExampleCoffeeMachine". In my code i am facing one error.......

Shahbaz at 1 Ali

unread,
Aug 5, 2018, 4:20:22 AM8/5/18
to LearnLib Q&A
Finally i have worked out the solution and now it looks that it was very easy. i have learned the model of my customized "TeaMachineModel". This time i prepared my own TeaMachineSUL by extending the class of ExampleCoffeeMachine class and it work fine. I have uploaded its code here as "TeaMachineSUL.java" and create its instance in another Learner class.

Previously, i was making TeaMachineSUL by extending the class of  "DefaultMealyLearningExample<Input,String>". In that code i am facing an error at the end. I am uploading its updated code here as a file "TeaMachineSUL1.java". Please,  tell me how can i remove the error. And the error is:

""The constructor 
 DefaultLearningExample.DefaultMealyLearningExample<ExampleCoffeeMachine.Input,String>(CompactMealy<TeaMachineSUL1.Input,
 String>) is undefined""
TeaMachineSUL.java
TeaMachineSUL1.java

Markus Frohme

unread,
Aug 5, 2018, 5:47:15 AM8/5/18
to Shahbaz at 1 Ali, LearnLib Q&A
Regarding your TeaMachineSUL.java: Why would you want to extend ExampleCoffeeMachine? Normally you inherit from other classes if you want to reuse some functionality. In your case, you have a new input alphabet and a new SUL, so nothing to reuse from the original coffee machine (+ you only define static methods, that can't override other static methods).

Regarding your TeaMachineSUL1.java: It worked fine when I imported it in IntelliJ. It may be a problem with Eclipse, which uses its own compiler that sometimes has problems with heavy use of generics. Other than that, you extend DefaultMealyLearningExample from the de.learnlib.testsupport group, which (as the name suggest) is primarily used for testing -- so you need to work your way around to use it as a normal class (set the maven depedency scope to <scope>compile</scope>).

Overall, I suggest you just simply write a standalone TeaMachineSUL class which provides the information you need (alphabet, SUL) without inheriting from any special class.
> --
> You received this message because you are subscribed to the Google Groups "LearnLib Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to learnlib-qa...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

> package com.baz.LearningMealyMachine;
>
> import de.learnlib.examples.mealy.ExampleCoffeeMachine;
> import net.automatalib.automata.transout.MutableMealyMachine;
> import net.automatalib.automata.transout.impl.compact.CompactMealy;
> import net.automatalib.util.automata.builders.AutomatonBuilders;
> import net.automatalib.words.Alphabet;
> import net.automatalib.words.impl.Alphabets;
>
> public class TeaMachineSUL extends ExampleCoffeeMachine{
>
> public static enum Input {
> COIN,
> BUTTON
> }
>
> public final static String out_ok = "OK";
> public final static String out_nok = "NOK";
> public final static String out_tea = "Tea!";
>
> public static Alphabet<Input> createInput() {
> return Alphabets.fromEnum(Input.class);
> }
>
> public static <S,T,A extends MutableMealyMachine<S,? super Input,T,? super String>>
> A construcTeaMachineSUL(A machine) {
>
> machine = AutomatonBuilders.forMealy(machine).withInitial("0").from("0").on(Input.BUTTON)
> .withOutput(out_nok).loop().from("0").on(Input.COIN).withOutput(out_ok).to("1")
> .from("1").on(Input.COIN).withOutput(out_nok).loop().from("1").on(Input.BUTTON).withOutput(out_tea)
> .to("0").create();
>
> return machine;
> }
>
> public static CompactMealy<Input,String> construcTeaMachineSUL() {
> return construcTeaMachineSUL(new CompactMealy<Input,String>(createInput()));
> }
>
>
> // public static TeaMachineSUL createExample() {
> // return new TeaMachineSUL();
> // }
>
>
>
> }
>
>

> package com.baz.LearningMealyMachine;
>
> import de.learnlib.examples.DefaultLearningExample.DefaultMealyLearningExample;
> import de.learnlib.examples.mealy.ExampleCoffeeMachine;
> import de.learnlib.examples.mealy.ExampleCoffeeMachine.Input;
> import net.automatalib.automata.transout.MutableMealyMachine;
> import net.automatalib.automata.transout.impl.compact.CompactMealy;
> import net.automatalib.util.automata.builders.AutomatonBuilders;
> import net.automatalib.words.Alphabet;
> import net.automatalib.words.impl.Alphabets;
>
> public class TeaMachineSUL1 extends DefaultMealyLearningExample<Input,String> {
>
>
> public static enum Input {
> COIN,
> BUTTON
> }
>
> public final static String out_ok = "OK";
> public final static String out_nok = "NOK";
> public final static String out_tea = "Tea!";
>
>
> public static Alphabet<Input> createInputAlphabet() {
> return Alphabets.fromEnum(Input.class);
> }
>
>
> /**
> * Construct and return a machine representation of this example
> *
> * @return a Mealy machine representing the Tea machine example
> */
> public static <S,T,A extends MutableMealyMachine<S,? super Input,T,? super String>>
> A constructMachine(A machine) {
>
> machine = AutomatonBuilders.forMealy(machine).withInitial("0").from("0").on(Input.BUTTON)
> .withOutput(out_nok).loop().from("0").on(Input.COIN).withOutput(out_ok).to("1")
> .from("1").on(Input.COIN).withOutput(out_nok).loop().from("1").on(Input.BUTTON).withOutput(out_tea)
> .to("0").create();
>
>
> return machine;
>
> }
>
> public static CompactMealy<Input,String> constructMachine() {
> return constructMachine(new CompactMealy<Input,String>(createInputAlphabet()));
> }
>
> public static TeaMachineSUL1 createExample() {
> return new TeaMachineSUL1();
> }
>
>
> public TeaMachineSUL1() {
> super(constructMachine());
> }
>
> }

Shahbaz at 1 Ali

unread,
Aug 5, 2018, 10:33:16 AM8/5/18
to LearnLib Q&A
Hello sir, thank you for your feedback!

1) First, you are right. I should not inherit the TeaMachineSul class from ExampleMealyMachine class.
2) Secondly, as per you suggestion i have written a simple "TeaMachineSUL.java" class without any inheritance (as i attached in current post, please check it....you are talking like this kind of class???). Next, how i interface it with Learner. How to proceed further please. i tried to correlate it with example-2 (learning of JAVA Stack class) but some confused. Are we needed driver class (deriving like  SimplePOJO.....). How i make membership oracle from this model??...Please guide me by writing a few lines of code for it.......


On Saturday, August 4, 2018 at 5:12:11 PM UTC+8, Shahbaz at 1 Ali wrote:
TeaMachineSUL.java

Shahbaz at 1 Ali

unread,
Aug 6, 2018, 3:30:29 AM8/6/18
to LearnLib Q&A
For example, i tried to prepare Learner class for it....its first two lines of code as:

          Alphabet<TeaMachineSUL.Input> sigma = Alphabets.fromEnum(TeaMachineSUL.Input.class);   //ok

        // Setup the membership oracle to answer queries from the learner
        final MealyMembershipOracle<TeaMachineSUL.Input, TeaMachineSUL.Output> mqOracle = new SULOracle<>(new TeaMachineSUL()); //Error

Error is "Cannot infer type arguments for SULOracle<>".

Please, guide me by writing a few line of code for it.....


On Saturday, August 4, 2018 at 5:12:11 PM UTC+8, Shahbaz at 1 Ali wrote:

Markus Frohme

unread,
Aug 6, 2018, 1:13:13 PM8/6/18
to Shahbaz at 1 Ali, LearnLib Q&A
The SULOracle requires a SUL as its delegate. So in order for `new SULOracle<>(new TeaMachineSUL())` to work, your TeaMachineSUL would have to implement the SUL interface.

But you can also manually construct a TestDriver (see below) that invokes the SUL methods via Java reflection, like in Example 2. While the reflection approach performs a little bit worse, you can save yourself writing the SUL glue-code.



SimplePOJOTestDriver driver = new SimplePOJOTestDriver(TeaMachineSUL.class.getConstructor());

Method traverseMethod = TeaMachineSUL.class.getMethod("traverseSUL", TeaMachineSUL.Input.class);

MethodInput btn = driver.addInput("Button", traverseMethod, Input.BTN);
MethodInput coin = driver.addInput("Coin", traverseMethod, Input.COIN_I);

SUL<MethodInput, AbstractMethodOutput> sul = driver;

sul.pre();
System.out.println(sul.step(btn));
System.out.println(sul.step(btn));
System.out.println(sul.step(coin));
System.out.println(sul.step(btn));
sul.post();

Shahbaz at 1 Ali

unread,
Aug 7, 2018, 10:05:53 AM8/7/18
to LearnLib Q&A

Shahbaz at 1 Ali bazg...@gmail.com

Attachments9:59 PM (4 minutes ago)
to Markus
Hello Sir, Now i have implement SUL interface in my class i.e., TeaMachineFinal.java and using it in Learner class i.e, TeaMachineSULLearner.java. Both classes are being upload here.  I am again facing the same error as:    "Cannot infer type arguments for SULOracle<>"  on line 

// Setup the membership oracle to answer queries from the learner
       MealyMembershipOracle<TeaMachineFinal.Input, TeaMachineFinal.Output> mqOracle = new SULOracle<>(new TeaMachineFinal()); //error

i am following the below link:

Plz guide me where i am wrong now. i have implemented my SUL in the form of java class. And now want to create membership , equivalence oracle and start running the experiment.

On Saturday, August 4, 2018 at 5:12:11 PM UTC+8, Shahbaz at 1 Ali wrote:
TeaMachineSULLearner.java
TeaMachineFinal.java
Reply all
Reply to author
Forward
0 new messages