From: charlie Date: Sun, 24 Jan 2016 21:12:36 +0000 (+0100) Subject: cmd options for learner and learned model for minimal input alphabet added as sample. X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=0f78791495b0f4f172b02cd14bea0bedcd37f3f2;p=tt2015.git cmd options for learner and learned model for minimal input alphabet added as sample. --- diff --git a/a4/tcp/adapter/listener.py b/a4/tcp/adapter/listener.py index 17d6f21..d64503b 100644 --- a/a4/tcp/adapter/listener.py +++ b/a4/tcp/adapter/listener.py @@ -34,7 +34,7 @@ if __name__ == "__main__": print 'received: {}'.format(data) if data == 'RES': print 'resetting the SUT...' - sender.sendReset() + #sender.sendReset() sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=0) data = '' continue diff --git a/a4/tcp/learnedModel.small.LStar.rand.dot b/a4/tcp/learnedModel.small.LStar.rand.dot new file mode 100644 index 0000000..e169a68 --- /dev/null +++ b/a4/tcp/learnedModel.small.LStar.rand.dot @@ -0,0 +1,15 @@ +digraph g { +__start0 [label="" shape="none"]; + + s0 [shape="circle" label="0"]; + s1 [shape="circle" label="1"]; + s2 [shape="circle" label="2"]; + s0 -> s1 [label="SYN / SYN-ACK"]; + s0 -> s0 [label="ACK / TO"]; + s1 -> s1 [label="SYN / SYN-ACK"]; + s1 -> s2 [label="ACK / TO"]; + s2 -> s2 [label="SYN / TO"]; + s2 -> s2 [label="ACK / TO"]; + +__start0 -> s0; +} diff --git a/a4/tcp/run.sh b/a4/tcp/run.sh index d3d70ef..645b4f8 100755 --- a/a4/tcp/run.sh +++ b/a4/tcp/run.sh @@ -1,2 +1,3 @@ #!/bin/bash -x -java -cp ":lib/automata-parent.jar:lib/learnlib-parent.jar" learner.Main +#java -cp ":lib/automata-parent.jar:lib/learnlib-parent.jar" learner.Main small +java -cp ":lib/automata-parent.jar:lib/learnlib-parent.jar" learner.Main partial LStar rand diff --git a/a4/tcp/tester/learner/Main.java b/a4/tcp/tester/learner/Main.java index 0ac2018..4d25e54 100644 --- a/a4/tcp/tester/learner/Main.java +++ b/a4/tcp/tester/learner/Main.java @@ -54,10 +54,7 @@ public class Main { //*****************// // Defines the input alphabet, adapt for your socket (you can even use other types than string, if you // change the generic-values, e.g. make your SUL of type SUL for int-input and float-output - private static final Alphabet inputAlphabet = - new SimpleAlphabet(ImmutableSet.of( - "SYN", "ACK", - "DAT", "RST", "FIN")); + private static Alphabet inputAlphabet; // There are two SULs predefined, an example (see ExampleSul.java) and a socket SUL which connects to the SUL over socket private static final SULType sulType = SULType.Socket; public enum SULType { Example, Socket } @@ -74,11 +71,11 @@ public class Main { private static final String OUTPUT_FILENAME = "learnedModel"; // the learning and testing algorithms. LStar is the basic algorithm, TTT performs much faster // but is a bit more inaccurate and produces more intermediate hypotheses, so test well) - private static final LearningMethod learningAlgorithm = LearningMethod.LStar; + private static LearningMethod learningAlgorithm = LearningMethod.LStar; public enum LearningMethod { LStar, RivestSchapire, TTT, KearnsVazirani } // Random walk is the simplest, but performs badly on large models: the chance of hitting a // erroneous long trace is very small - private static final TestingMethod testMethod = TestingMethod.RandomWalk; + private static TestingMethod testMethod = TestingMethod.RandomWalk; public enum TestingMethod { RandomWalk, WMethod, WpMethod } // for random walk, the chance to do a reset after an input and the number of // inputs to test before accepting a hypothesis @@ -89,9 +86,80 @@ public class Main { private static final boolean runControlledExperiment = true; // For controlled experiments only: store every hypotheses as a file. Useful for 'debugging' // if the learner does not terminate (hint: the TTT-algorithm produces many hypotheses). - private static final boolean saveAllHypotheses = false; + private static final boolean saveAllHypotheses = true; + + private static String stateCountStr; + private static String methodStr; + private static String testStr; public static void main(String [] args) throws IOException { + if (args.length != 3) { + System.out.println("error: missing commandline arguments!"); + return; + } + + /* this option reduces the number of inputs used by the learning + * + * this should result in a smaller model because these inputs + * are only valid in certain states. + */ + stateCountStr = args[0]; + int stateCount = 0; + if (args[0].equals("partial")) { + stateCount = 1; + } else if (args[0].equals("full")) { + stateCount = 2; + } + + /* learning method + * + * can be LStar, TTT, RS or KV + */ + methodStr = args[1]; + if (methodStr.equals("LStar")) { + learningAlgorithm = LearningMethod.LStar; + } else if (methodStr.equals("TTT")) { + learningAlgorithm = LearningMethod.TTT; + } else if (methodStr.equals("RS")) { + learningAlgorithm = LearningMethod.RivestSchapire; + } else if (methodStr.equals("KV")) { + learningAlgorithm = LearningMethod.KearnsVazirani; + } + + /* testing method + * + * can be: rand, wm, wpm + */ + testStr = args[2]; + if (testStr.equals("rand")) { + testMethod = TestingMethod.RandomWalk; + } else if (testStr.equals("wm")) { + testMethod = TestingMethod.WMethod; + } else if (testStr.equals("wpm")) { + testMethod = TestingMethod.WpMethod; + } + + System.out.println("settings:"); + System.out.println("stateCount = "+stateCount); + System.out.println("learningMethod = "+methodStr); + System.out.println("testMethod = "+testStr); + + switch (stateCount) { + case 2: + inputAlphabet = new SimpleAlphabet(ImmutableSet.of( + "SYN", "ACK", + "DAT", "RST", "FIN")); + break; + case 1: + inputAlphabet = new SimpleAlphabet(ImmutableSet.of( + "SYN", "ACK", + "RST")); + break; + default: + inputAlphabet = new SimpleAlphabet(ImmutableSet.of( + "SYN", "ACK")); + } + // Load the actual SUL-class, depending on which SUL-type is set at the top of this file // You can also program an own SUL-class if you extend SUL (or SUL in // general, with S and T the input and output types - you'll have to change some of the @@ -258,9 +326,9 @@ public class Main { * @throws IOException */ public static void produceOutput(String fileName, MealyMachine model, Alphabet alphabet, boolean verboseError) throws FileNotFoundException, IOException { - GraphDOT.write(model, alphabet, new PrintWriter(OUTPUT_FILENAME + ".dot")); + GraphDOT.write(model, alphabet, new PrintWriter(fileName + "." + stateCountStr + "." + methodStr + "." + testStr + ".dot")); try { - DOT.runDOT(new File(OUTPUT_FILENAME + ".dot"), "pdf", new File(OUTPUT_FILENAME + ".pdf")); + DOT.runDOT(new File(fileName + "." + stateCountStr + "." + methodStr + "." + testStr + ".dot"), "pdf", new File(fileName + "." + stateCountStr + "." + methodStr + "." + testStr + ".pdf")); } catch (Exception e) { if (verboseError) { System.err.println("Warning: Install graphviz to convert dot-files to PDF");