use of edu.mit.csail.sdg.translator.A4Options.SatSolver in project org.alloytools.alloy by AlloyTools.
the class SimpleCLI method main.
public static void main(String[] args) throws Exception {
final boolean sat4j = "yes".equals(System.getProperty("sat4j"));
final boolean minisat = "yes".equals(System.getProperty("minisat"));
SatSolver solver = A4Options.SatSolver.make("mem", "mem", "/zweb/sat/mem");
final SimpleReporter rep = new SimpleReporter();
final StringBuilder sb = rep.sb;
for (String filename : args) {
try {
// Parse+Typecheck
rep.sb.append("\n\nMain file = " + filename + "\n");
if (db)
db("Parsing+Typechecking...");
Module world = CompUtil.parseEverything_fromFile(rep, null, filename);
if (db)
db(" ok\n");
List<Command> cmds = world.getAllCommands();
for (ErrorWarning msg : rep.warnings) rep.sb.append("Relevance Warning:\n" + (msg.toString().trim()) + "\n\n");
rep.warnings.clear();
// Do a detailed dump if we will not be executing the commands
if (args.length != 1) {
for (Module m : world.getAllReachableModules()) {
for (Sig x : m.getAllSigs()) {
sb.append("\nSig ").append(x.label).append(" at position ").append(x.pos).append("\n");
for (Decl d : x.getFieldDecls()) for (ExprHasName f : d.names) {
sb.append("\nField ").append(f.label).append(" with type ").append(f.type()).append("\n");
d.expr.toString(sb, 2);
}
rep.flush();
}
for (Func x : m.getAllFunc()) {
sb.append("\nFun/pred ").append(x.label).append(" at position ").append(x.pos).append("\n");
for (Decl d : x.decls) for (ExprHasName v : d.names) {
v.toString(sb, 2);
d.expr.toString(sb, 4);
}
x.returnDecl.toString(sb, 2);
x.getBody().toString(sb, 4);
rep.flush();
}
for (Pair<String, Expr> x : m.getAllFacts()) {
sb.append("\nFact ").append(x.a).append("\n");
x.b.toString(sb, 4);
rep.flush();
}
for (Pair<String, Expr> x : m.getAllAssertions()) {
sb.append("\nAssertion ").append(x.a).append("\n");
x.b.toString(sb, 4);
rep.flush();
}
if (m == world)
for (Command x : m.getAllCommands()) {
sb.append("\nCommand ").append(x.label).append("\n");
x.formula.toString(sb, 4);
rep.flush();
}
}
continue;
}
// Validate the metamodel generation code
StringWriter metasb = new StringWriter();
PrintWriter meta = new PrintWriter(metasb);
Util.encodeXMLs(meta, "\n<alloy builddate=\"", Version.buildDate(), "\">\n\n");
A4SolutionWriter.writeMetamodel(world.getAllReachableSigs(), filename, meta);
Util.encodeXMLs(meta, "\n</alloy>");
meta.flush();
metasb.flush();
String metaxml = metasb.toString();
A4SolutionReader.read(new ArrayList<Sig>(), new XMLNode(new StringReader(metaxml)));
StaticInstanceReader.parseInstance(new StringReader(metaxml));
// Okay, now solve the commands
A4Options options = new A4Options();
options.originalFilename = filename;
options.solverDirectory = "/zweb/zweb/tmp/alloy4/x86-freebsd";
options.solver = sat4j ? A4Options.SatSolver.SAT4J : (minisat ? A4Options.SatSolver.MiniSatJNI : solver);
for (int i = 0; i < cmds.size(); i++) {
Command c = cmds.get(i);
if (db) {
String cc = c.toString();
if (cc.length() > 60)
cc = cc.substring(0, 55);
db("Executing " + cc + "...\n");
}
rep.sb.append("Executing \"" + c + "\"\n");
options.skolemDepth = 0;
A4Solution s = TranslateAlloyToKodkod.execute_commandFromBook(rep, world.getAllReachableSigs(), c, options);
if (s.satisfiable()) {
validate(s);
if (s.isIncremental()) {
s = s.next();
if (s.satisfiable())
validate(s);
}
}
options.skolemDepth = 2;
s = TranslateAlloyToKodkod.execute_commandFromBook(rep, world.getAllReachableSigs(), c, options);
if (s.satisfiable()) {
validate(s);
if (s.isIncremental()) {
s = s.next();
if (s.satisfiable())
validate(s);
}
}
}
} catch (Throwable ex) {
rep.sb.append("\n\nException: " + ex);
}
if (db) {
if (args.length != 1)
db(" ERROR!\n");
else
db("\n\n");
}
}
rep.close();
}
use of edu.mit.csail.sdg.translator.A4Options.SatSolver in project org.alloytools.alloy by AlloyTools.
the class PreferencesDialog method testSolvers.
protected Iterable<SatSolver> testSolvers() {
List<SatSolver> satChoices = SatSolver.values().makeCopy();
satChoices.remove(SatSolver.BerkMinPIPE);
String fs = System.getProperty("file.separator");
String test2 = Subprocess.exec(20000, new String[] { binary + fs + "spear", "--model", "--dimacs", binary + fs + "tmp.cnf" });
if (!isSat(test2))
satChoices.remove(SatSolver.SpearPIPE);
if (!loadLibrary("minisat")) {
log.logBold("Warning: JNI-based SAT solver does not work on this platform.\n");
log.log("This is okay, since you can still use SAT4J as the solver.\n" + "For more information, please visit http://alloy.mit.edu/alloy4/\n");
log.logDivider();
log.flush();
satChoices.remove(SatSolver.MiniSatJNI);
}
if (!loadLibrary("minisatprover"))
satChoices.remove(SatSolver.MiniSatProverJNI);
if (!loadLibrary("lingeling"))
satChoices.remove(SatSolver.LingelingJNI);
if (!loadLibrary("glucose"))
satChoices.remove(SatSolver.GlucoseJNI);
if (!loadLibrary("cryptominisat"))
satChoices.remove(SatSolver.CryptoMiniSatJNI);
SatSolver now = Solver.get();
if (!satChoices.contains(now)) {
now = SatSolver.LingelingJNI;
if (!satChoices.contains(now))
now = SatSolver.SAT4J;
Solver.set(now);
}
if (now == SatSolver.SAT4J && satChoices.size() > 3 && satChoices.contains(SatSolver.CNF) && satChoices.contains(SatSolver.KK)) {
log.logBold("Warning: Alloy4 defaults to SAT4J since it is pure Java and very reliable.\n");
log.log("For faster performance, go to Options menu and try another solver like MiniSat.\n");
log.log("If these native solvers fail on your computer, remember to change back to SAT4J.\n");
log.logDivider();
log.flush();
}
return satChoices;
}
Aggregations