cmd options for learner and learned model for minimal input alphabet added as sample.
authorcharlie <charlie@gerhardus.com>
Sun, 24 Jan 2016 21:12:36 +0000 (22:12 +0100)
committercharlie <charlie@gerhardus.com>
Sun, 24 Jan 2016 21:12:36 +0000 (22:12 +0100)
a4/tcp/adapter/listener.py
a4/tcp/learnedModel.small.LStar.rand.dot [new file with mode: 0644]
a4/tcp/run.sh
a4/tcp/tester/learner/Main.java

index 17d6f21..d64503b 100644 (file)
@@ -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 (file)
index 0000000..e169a68
--- /dev/null
@@ -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;
+}
index d3d70ef..645b4f8 100755 (executable)
@@ -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
index 0ac2018..4d25e54 100644 (file)
@@ -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<Integer, Float> for int-input and float-output
-       private static final Alphabet<String> inputAlphabet =
-               new SimpleAlphabet<String>(ImmutableSet.of(
-                                       "SYN", "ACK",
-                                       "DAT", "RST", "FIN"));  
+       private static Alphabet<String> 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<String>(ImmutableSet.of(
+                                       "SYN", "ACK",
+                                       "DAT", "RST", "FIN"));
+                       break;
+                       case 1:
+                               inputAlphabet = new SimpleAlphabet<String>(ImmutableSet.of(
+                                       "SYN", "ACK",
+                                       "RST"));
+                       break;
+                       default:
+                               inputAlphabet = new SimpleAlphabet<String>(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<String,String> (or SUL<S,T> 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<?,String,?,String> model, Alphabet<String> 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");