use of edu.mit.csail.sdg.ast.Command 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.ast.Command in project org.alloytools.alloy by AlloyTools.
the class SimpleGUI method doRefreshRun.
// ===============================================================================================================//
/**
* This method refreshes the "run" menu.
*/
private Runner doRefreshRun() {
if (wrap)
return wrapMe();
KeyStroke ac = KeyStroke.getKeyStroke(VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
try {
wrap = true;
runmenu.removeAll();
menuItem(runmenu, "Execute Latest Command", 'E', 'E', doExecuteLatest());
runmenu.add(new JSeparator());
menuItem(runmenu, "Show Latest Instance", 'L', 'L', doShowLatest(), latestInstance.length() > 0);
menuItem(runmenu, "Show Metamodel", 'M', 'M', doShowMetaModel());
if (Version.experimental)
menuItem(runmenu, "Show Parse Tree", 'P', doShowParseTree());
menuItem(runmenu, "Open Evaluator", 'V', doLoadEvaluator());
} finally {
wrap = false;
}
List<Command> cp = commands;
if (cp == null) {
try {
String source = text.get().getText();
cp = CompUtil.parseOneModule_fromString(source);
} catch (Err e) {
commands = null;
runmenu.getItem(0).setEnabled(false);
runmenu.getItem(3).setEnabled(false);
text.shade(new Pos(text.get().getFilename(), e.pos.x, e.pos.y, e.pos.x2, e.pos.y2));
if (AlloyCore.isDebug() && VerbosityPref.get() == Verbosity.FULLDEBUG)
log.logRed("Fatal Exception!" + e.dump() + "\n\n");
else
log.logRed(e.toString() + "\n\n");
return null;
} catch (Throwable e) {
commands = null;
runmenu.getItem(0).setEnabled(false);
runmenu.getItem(3).setEnabled(false);
log.logRed("Cannot parse the model.\n" + e.toString() + "\n\n");
return null;
}
commands = cp;
}
text.clearShade();
// To clear any residual error message
log.clearError();
if (cp == null) {
runmenu.getItem(0).setEnabled(false);
runmenu.getItem(3).setEnabled(false);
return null;
}
if (cp.size() == 0) {
runmenu.getItem(0).setEnabled(false);
return null;
}
if (latestCommand >= cp.size())
latestCommand = cp.size() - 1;
runmenu.remove(0);
try {
wrap = true;
for (int i = 0; i < cp.size(); i++) {
JMenuItem y = new JMenuItem(cp.get(i).toString(), null);
y.addActionListener(doRun(i));
if (i == latestCommand) {
y.setMnemonic(VK_E);
y.setAccelerator(ac);
}
runmenu.add(y, i);
}
if (cp.size() >= 2) {
JMenuItem y = new JMenuItem("Execute All", null);
y.setMnemonic(VK_A);
y.addActionListener(doRun(-1));
runmenu.add(y, 0);
runmenu.add(new JSeparator(), 1);
}
} finally {
wrap = false;
}
return null;
}
use of edu.mit.csail.sdg.ast.Command 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;
}
}
use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class AlloyTest method main.
public static void main(String[] args) throws Exception {
A4Reporter rep = new A4Reporter();
Module world = CompUtil.parseEverything_fromFile(rep, null, "/home/aleks/mvc.als");
A4Options options = new A4Options();
options.solver = A4Options.SatSolver.SAT4J;
options.skolemDepth = 1;
for (Command command : world.getAllCommands()) {
A4Solution ans = null;
try {
ans = TranslateAlloyToKodkod.execute_commandFromBook(rep, world.getAllReachableSigs(), command, options);
System.out.println(ans);
} catch (Err ex) {
Logger.getLogger(AlloyTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class DemoFileSystem method runFor3.
void runFor3(Expr expr) throws Err {
A4Options opt = new A4Options();
Command cmd = new Command(false, 3, 3, 3, expr.and(fact));
A4Solution sol = TranslateAlloyToKodkod.execute_command(NOP, sigs, cmd, opt);
System.out.println(sol.toString().trim());
if (sol.satisfiable()) {
System.out.println("In particular, File = " + sol.eval(file));
System.out.println("In particular, Dir = " + sol.eval(dir));
System.out.println("In particular, contains = " + sol.eval(contains));
System.out.println("In particular, parent = " + sol.eval(parent));
}
System.out.println();
}
Aggregations