//*****************//
// 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 }
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
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
* @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");