From ac914c719d401c44cb2633127952b022bf563ff3 Mon Sep 17 00:00:00 2001 From: René den Hertog Date: Thu, 26 Oct 2017 17:34:51 +0200 Subject: 'Bounded Retransmission Protocol' Blob --- .../Source/basiclearner/ExampleSUL.java | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/ExampleSUL.java (limited to 'assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/ExampleSUL.java') diff --git a/assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/ExampleSUL.java b/assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/ExampleSUL.java new file mode 100644 index 0000000..8cfdbac --- /dev/null +++ b/assignments/assignment2/Bounded Retransmission Protocol Tester/Source/basiclearner/ExampleSUL.java @@ -0,0 +1,90 @@ +package basiclearner; + +import de.learnlib.api.SUL; +import de.learnlib.api.SULException; + +/** + * Example of a three-state system, hard-coded. + * + * @author Ramon Janssen + */ +public class ExampleSUL implements SUL { + private enum State{s0,s1,s2}; + private State currentState; + private static boolean VERBOSE = false; + + @Override + public void pre() { + // add any code here that should be run at the beginning of every 'session', + // i.e. put the system in its initial state + if (VERBOSE) { + System.out.println("Starting SUL"); + } + currentState = State.s0; + } + + @Override + public void post() { + // add any code here that should be run at the end of every 'session' + if (VERBOSE) { + System.out.println("Shutting down SUL"); + } + } + + @Override + public String step(String input) throws SULException { + State previousState = this.currentState; + String output = makeTransition(input); + State nextState = this.currentState; + if (VERBOSE) { + System.out.println(previousState + " --" + input + "/" + output + "-> " + nextState); + } + return output; + } + + /** + * The behaviour of the SUL. It takes one input, and returns an output. It now + * contains a hardcoded state-machine (so the result is easy to check). To learn + * an external program/system, connect this method to the SUL (e.g. via sockets + * or stdin/stdout) and make it perform an actual input, and retrieve an actual + * output. + * @param input + * @return + */ + public String makeTransition(String input) { + switch (currentState) { + case s0: + switch(input) { + case "a": + currentState = State.s1; + return "x"; + case "b": + currentState = State.s2; + return "y"; + case "c": + return "z"; + } + case s1: + switch(input) { + case "a": + return "z"; + case "b": + currentState = State.s2; + return "y"; + case "c": + return "z"; + } + case s2: + switch(input) { + case "a": + return "z"; + case "b": + currentState = State.s0; + return "y"; + case "c": + return "z"; + } + } + throw new SULException(new IllegalArgumentException("Argument '" + input + "' was not handled")); + } +} -- cgit v1.2.3