use of edu.mit.csail.sdg.translator.A4Solution 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.A4Solution in project org.alloytools.alloy by AlloyTools.
the class VizTree method convertValueToText.
/**
* {@inheritDoc}
*/
@Override
public String convertValueToText(Object val, boolean selected, boolean expanded, boolean leaf, int row, boolean focus) {
String c = ">";
if (onWindows)
c = selected ? " style=\"color:#ffffff;\">" : " style=\"color:#000000;\">";
if (val instanceof A4Solution)
return "<html> <b" + c + encode(title == null ? "" : title) + "</b></html>";
if (val instanceof Sig) {
String label = ((Sig) val).label;
if (label.startsWith("this/"))
label = label.substring(5);
return "<html> <b" + c + "sig " + encode(label) + "</b></html>";
}
if (val instanceof ExprVar)
return "<html> <b" + c + "set " + encode(((ExprVar) val).label) + "</b></html>";
if (val instanceof String)
return "<html> <span" + c + encode((String) val) + "</span></html>";
if (val instanceof Pair)
return "<html> <b" + c + "field " + encode(((ExprHasName) (((Pair<?, ?>) val).b)).label) + "</b></html>";
if (val instanceof A4Tuple) {
StringBuilder sb = new StringBuilder("<html> <span" + c);
A4Tuple tp = (A4Tuple) val;
for (int i = 1; i < tp.arity(); i++) {
if (i > 1)
sb.append(" -> ");
sb.append(encode(tp.atom(i)));
}
sb.append("</span></html>");
return sb.toString();
}
return "";
}
use of edu.mit.csail.sdg.translator.A4Solution in project org.alloytools.alloy by AlloyTools.
the class AlloyModelsTest method minimalAlloyDoc.
@Test
public void minimalAlloyDoc() throws Exception {
CompModule world = CompUtil.parseEverything_fromString(A4Reporter.NOP, "sig Foo {} \n" + "run { 1 < #Int } for 10 int\n");
A4Options options = new A4Options();
options.unrolls = 10;
for (Command command : world.getAllCommands()) {
A4Solution ans = TranslateAlloyToKodkod.execute_command(A4Reporter.NOP, world.getAllReachableSigs(), command, options);
while (ans.satisfiable()) {
String hc = "Answer: " + ans.toString().hashCode();
System.out.println(hc);
ans = ans.next();
}
return;
}
}
use of edu.mit.csail.sdg.translator.A4Solution in project org.alloytools.alloy by AlloyTools.
the class AlloyModelsTest method testRecursion.
@Test
public void testRecursion() throws Exception {
String filename = "src/test/resources/test-recursion.als";
Module world = CompUtil.parseEverything_fromFile(A4Reporter.NOP, null, filename);
A4Options options = new A4Options();
options.unrolls = 10;
for (Command command : world.getAllCommands()) {
A4Solution ans = TranslateAlloyToKodkod.execute_command(A4Reporter.NOP, world.getAllReachableSigs(), command, options);
while (ans.satisfiable()) {
String hc = "Answer: " + ans.toString().hashCode();
System.out.println(hc);
ans = ans.next();
}
return;
}
}
use of edu.mit.csail.sdg.translator.A4Solution in project org.alloytools.alloy by AlloyTools.
the class InternalTest method main2.
/**
* Displays the amount of memory taken per solution enumeration.
*/
public static void main2(String[] args) throws Exception {
String filename = "models/examples/algorithms/dijkstra.als";
Module world = CompUtil.parseEverything_fromFile(A4Reporter.NOP, null, filename);
A4Options options = new A4Options();
for (Command command : world.getAllCommands()) {
A4Solution ans = TranslateAlloyToKodkod.execute_command(A4Reporter.NOP, world.getAllReachableSigs(), command, options);
while (ans.satisfiable()) {
String hc = "Answer: " + ans.toString().hashCode();
System.gc();
System.gc();
System.gc();
Thread.sleep(500);
System.gc();
System.gc();
System.gc();
Thread.sleep(500);
long t = Runtime.getRuntime().totalMemory(), f = Runtime.getRuntime().freeMemory(), m = Runtime.getRuntime().maxMemory();
System.out.println(hc + " total=" + t + " free=" + f + " max=" + m);
System.out.flush();
ans = ans.next();
}
return;
}
}
Aggregations