public SimpleTask1() { }
public void cb(WorkerCallback out, Object... objs) throws IOException { out.callback(objs); }
public void run(WorkerCallback out) throws Exception {
cb(out, "S2", "Starting the solver...\n\n");
final SimpleReporter rep = new SimpleReporter(out, options.recordKodkod);
final Module world = CompUtil.parseEverything_fromFile(rep, map, options.originalFilename, resolutionMode);
final List<Sig> sigs = world.getAllReachableSigs();
final ConstList<Command> cmds = world.getAllCommands();
cb(out, "warnings", bundleWarningNonFatal);
if (rep.warn>0 && !bundleWarningNonFatal) return;
List<String> result = new ArrayList<String>(cmds.size());
if (bundleIndex==-2) {
final String outf=tempdir+File.separatorChar+"m.xml";
cb(out, "S2", "Generating the metamodel...\n");
PrintWriter of = new PrintWriter(outf, "UTF-8");
Util.encodeXMLs(of, "\n<alloy builddate=\"", Version.buildDate(), "\">\n\n");
A4SolutionWriter.writeMetamodel(ConstList.make(sigs), options.originalFilename, of);
Util.encodeXMLs(of, "\n</alloy>");
Util.close(of);
if ("yes".equals(System.getProperty("debug"))) validate(outf);
cb(out, "metamodel", outf);
synchronized(SimpleReporter.class) { latestMetamodelXML=outf; }
} else for(int i=0; i<cmds.size(); i++) if (bundleIndex<0 || i==bundleIndex) {
synchronized(SimpleReporter.class) { latestModule=world; latestKodkodSRC=ConstMap.make(map); }
final String tempXML=tempdir+File.separatorChar+i+".cnf.xml";
final String tempCNF=tempdir+File.separatorChar+i+".cnf";
final Command cmd=cmds.get(i);
rep.tempfile=tempCNF;
cb(out, "bold", "Executing \""+cmd+"\"\n");
A4Solution ai=TranslateAlloyToKodkod.execute_commandFromBook(rep, world.getAllReachableSigs(), cmd, options);
if (ai==null) result.add(null);
else if (ai.satisfiable()) result.add(tempXML);
else if (ai.highLevelCore().a.size()>0) result.add(tempCNF+".core");
else result.add("");
}
(new File(tempdir)).delete(); // In case it was UNSAT, or canceled...
if (result.size()>1) {
rep.cb("bold", "" + result.size() + " commands were executed. The results are:\n");
for(int i=0; i<result.size(); i++) {
Command r=world.getAllCommands().get(i);
if (result.get(i)==null) { rep.cb("", " #"+(i+1)+": Unknown.\n"); continue; }
if (result.get(i).endsWith(".xml")) {
rep.cb("", " #"+(i+1)+": ");
rep.cb("link", r.check?"Counterexample found. ":"Instance found. ", "XML: "+result.get(i));
rep.cb("", r.label+(r.check?" is invalid":" is consistent"));