Search in sources :

Example 16 with Command

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;
    }
}
Also used : Command(edu.mit.csail.sdg.ast.Command) A4Options(edu.mit.csail.sdg.translator.A4Options) Module(edu.mit.csail.sdg.ast.Module) CompModule(edu.mit.csail.sdg.parser.CompModule) A4Solution(edu.mit.csail.sdg.translator.A4Solution) Test(org.junit.Test)

Example 17 with Command

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;
}
Also used : Err(edu.mit.csail.sdg.alloy4.Err) Command(edu.mit.csail.sdg.ast.Command) Pos(edu.mit.csail.sdg.alloy4.Pos) KeyStroke(javax.swing.KeyStroke) JMenuItem(javax.swing.JMenuItem) JSeparator(javax.swing.JSeparator)

Example 18 with Command

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;
    }
}
Also used : Command(edu.mit.csail.sdg.ast.Command) A4Options(edu.mit.csail.sdg.translator.A4Options) Module(edu.mit.csail.sdg.ast.Module) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 19 with Command

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);
        }
    }
}
Also used : Err(edu.mit.csail.sdg.alloy4.Err) Command(edu.mit.csail.sdg.ast.Command) A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) A4Options(edu.mit.csail.sdg.translator.A4Options) Module(edu.mit.csail.sdg.ast.Module) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 20 with Command

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();
}
Also used : Command(edu.mit.csail.sdg.ast.Command) A4Options(edu.mit.csail.sdg.translator.A4Options) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Aggregations

Command (edu.mit.csail.sdg.ast.Command)21 A4Solution (edu.mit.csail.sdg.translator.A4Solution)12 A4Options (edu.mit.csail.sdg.translator.A4Options)10 Module (edu.mit.csail.sdg.ast.Module)6 Sig (edu.mit.csail.sdg.ast.Sig)6 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)5 Expr (edu.mit.csail.sdg.ast.Expr)5 Func (edu.mit.csail.sdg.ast.Func)4 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)3 Pos (edu.mit.csail.sdg.alloy4.Pos)3 Decl (edu.mit.csail.sdg.ast.Decl)3 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)3 CompModule (edu.mit.csail.sdg.parser.CompModule)3 ArrayList (java.util.ArrayList)3 Err (edu.mit.csail.sdg.alloy4.Err)2 ErrorWarning (edu.mit.csail.sdg.alloy4.ErrorWarning)2 XMLNode (edu.mit.csail.sdg.alloy4.XMLNode)2 CommandScope (edu.mit.csail.sdg.ast.CommandScope)2 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)2 Test (org.junit.Test)2