(new File(ErlangFolder, tracesFile)).delete();
(new File(ErlangFolder, covermapFile)).delete();
createInitTraces();
loadCoverageMaps();
ErlangTraces = new PrefixTraceTree(ErlangFolder + File.separator + tracesFile);
//System.out.println("Traces Tree:\n" + ErlangTraces.toString());
// Strip wildcard traces from the file...
wildCardStrip(ErlangFolder + File.separator + tracesFile);
QSMTool tool = new QSMTool();
tool.loadConfig(ErlangFolder + File.separator + tracesFile);
QSMTool.setSimpleConfiguration(tool.learnerInitConfiguration.config, true, 0);
ErlangOracleVisualiser viz = new ErlangOracleVisualiser();
// This is the one line thats actually changed...
ErlangOracleLearner innerLearner = new ErlangOracleLearner(viz, tool.learnerInitConfiguration);
innerLearner.addObserver(viz);
LearnerGraph graph = innerLearner.learnMachine(tool.sPlus, tool.sMinus);
boolean complete = false;
int repeats = 0;
while ((graph != null) && (!complete) && (repeats < 1)) {
repeats++;
Map<CmpVertex, Map<String, CmpVertex>> transitionMatrix = graph.getTransitionMatrix();
// Find (one of) the deepest node(s)
CmpVertex deepest = null;
CmpVertex root = null;
int maxDepth = 0;
for (CmpVertex v : transitionMatrix.keySet()) {
System.out.println(v);
System.out.println("\t" + v.getDepth());
if (v.getDepth() > maxDepth) {
deepest = v;
maxDepth = v.getDepth();
} else if (v.getDepth() == 0) {
root = v;
}
}
System.out.println("Deepest (" + maxDepth + ") == " + deepest);
// Get the path to this node
Collection<String> path = getPathTo(deepest, root, transitionMatrix, new ArrayList<CmpVertex>());
System.out.println("Path: " + path);
// Get the alphabet
Collection<String> alpha = new ArrayList<String>(moduleAlphabet);
// Remove the elements that are examined for this node
for (String s : transitionMatrix.get(deepest).keySet()) {
System.out.println("\tTried: " + s);
alpha.remove(s);
}
System.out.println("Untried: " + alpha);
if (alpha.size() > 0) {
// Try all the others...
for (String s : alpha) {
ArrayList<String> trypath = new ArrayList<String>(path);
trypath.add(s);
System.out.println("Trying " + trypath);
// Run this trace in Erlang and add the result to the traces file
Iterator<String> it = trypath.iterator();
//System.out.println("Question for " + erlangModule + ":" + erlangWrapperModule + " is:");
String erlList = "[";
while (it.hasNext()) {
if (!erlList.equals("[")) {
erlList += ",";
}
erlList += it.next();
}
erlList += "]";
String erlArgs = "tracer2:first_failure(" + ErlangQSMOracle.erlangWrapperModule + "," + ErlangQSMOracle.erlangModule + "," + erlList + ",\"" + ErlangQSMOracle.tracesFile + "\"," + ErlangOracleVisualiser.toErlangList(ErlangQSMOracle.erlangModules) + ")";
System.out.println("Evaluating " + erlArgs + " in folder " + ErlangQSMOracle.ErlangFolder);
innerLearner.erlangProcess.getOutputStream().write(erlArgs.getBytes());
innerLearner.erlangProcess.getOutputStream().write('.');
innerLearner.erlangProcess.getOutputStream().write('\n');
innerLearner.erlangProcess.getOutputStream().flush();
}
System.out.println("##############################################################################");
// FIXME stupid file sync issue...
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
;
}
ErlangQSMOracle.loadCoverageMaps();
ErlangQSMOracle.ErlangTraces = new PrefixTraceTree(ErlangQSMOracle.ErlangFolder + "/" + ErlangQSMOracle.tracesFile);
// Strip wildcard traces from the file...
wildCardStrip(ErlangFolder + File.separator + tracesFile);
// For some reason this breaks if I re-use it...
// I'm sure kirill will have a nice way to cary on from where we left off...
innerLearner.killErlang();