Search in sources :

Example 6 with A4Options

use of edu.mit.csail.sdg.translator.A4Options 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 7 with A4Options

use of edu.mit.csail.sdg.translator.A4Options in project org.alloytools.alloy by AlloyTools.

the class SimpleGUI method doRun.

/**
 * This method executes a particular RUN or CHECK command.
 */
private Runner doRun(Integer commandIndex) {
    if (wrap)
        return wrapMe(commandIndex);
    final int index = commandIndex;
    if (WorkerEngine.isBusy())
        return null;
    if (index == (-2))
        subrunningTask = 1;
    else
        subrunningTask = 0;
    latestAutoInstance = "";
    if (index >= 0)
        latestCommand = index;
    if (index == -1 && commands != null) {
        latestCommand = commands.size() - 1;
        if (latestCommand < 0)
            latestCommand = 0;
    }
    // To update the accelerator to point to the command actually chosen
    doRefreshRun();
    OurUtil.enableAll(runmenu);
    if (commands == null)
        return null;
    if (commands.size() == 0 && index != -2 && index != -3) {
        log.logRed("There are no commands to execute.\n\n");
        return null;
    }
    int i = index;
    if (i >= commands.size())
        i = commands.size() - 1;
    SimpleCallback1 cb = new SimpleCallback1(this, null, log, VerbosityPref.get().ordinal(), latestAlloyVersionName, latestAlloyVersion);
    SimpleTask1 task = new SimpleTask1();
    A4Options opt = new A4Options();
    opt.tempDirectory = alloyHome() + fs + "tmp";
    opt.solverDirectory = alloyHome() + fs + "binary";
    opt.recordKodkod = RecordKodkod.get();
    opt.noOverflow = NoOverflow.get();
    opt.unrolls = Version.experimental ? Unrolls.get() : (-1);
    opt.skolemDepth = SkolemDepth.get();
    opt.coreMinimization = CoreMinimization.get();
    opt.inferPartialInstance = InferPartialInstance.get();
    opt.coreGranularity = CoreGranularity.get();
    opt.originalFilename = Util.canon(text.get().getFilename());
    opt.solver = Solver.get();
    task.bundleIndex = i;
    task.bundleWarningNonFatal = WarningNonfatal.get();
    task.map = text.takeSnapshot();
    task.options = opt.dup();
    task.resolutionMode = (Version.experimental && ImplicitThis.get()) ? 2 : 1;
    task.tempdir = maketemp();
    try {
        runmenu.setEnabled(false);
        runbutton.setVisible(false);
        showbutton.setEnabled(false);
        stopbutton.setVisible(true);
        int newmem = SubMemory.get(), newstack = SubStack.get();
        if (newmem != subMemoryNow || newstack != subStackNow)
            WorkerEngine.stop();
        if (AlloyCore.isDebug() && VerbosityPref.get() == Verbosity.FULLDEBUG)
            WorkerEngine.runLocally(task, cb);
        else
            WorkerEngine.run(task, newmem, newstack, alloyHome() + fs + "binary", "", cb);
        subMemoryNow = newmem;
        subStackNow = newstack;
    } catch (Throwable ex) {
        WorkerEngine.stop();
        log.logBold("Fatal Error: Solver failed due to unknown reason.\n" + "One possible cause is that, in the Options menu, your specified\n" + "memory size is larger than the amount allowed by your OS.\n" + "Also, please make sure \"java\" is in your program path.\n");
        log.logDivider();
        log.flush();
        doStop(2);
    }
    return null;
}
Also used : SimpleCallback1(edu.mit.csail.sdg.alloy4whole.SimpleReporter.SimpleCallback1) A4Options(edu.mit.csail.sdg.translator.A4Options) SimpleTask1(edu.mit.csail.sdg.alloy4whole.SimpleReporter.SimpleTask1)

Example 8 with A4Options

use of edu.mit.csail.sdg.translator.A4Options in project org.alloytools.alloy by AlloyTools.

the class SimpleGUI method doShowParseTree.

/**
 * This method displays the parse tree.
 */
private Runner doShowParseTree() {
    if (wrap)
        return wrapMe();
    doRefreshRun();
    OurUtil.enableAll(runmenu);
    if (commands != null) {
        Module world = null;
        try {
            int resolutionMode = (Version.experimental && ImplicitThis.get()) ? 2 : 1;
            A4Options opt = new A4Options();
            opt.tempDirectory = alloyHome() + fs + "tmp";
            opt.solverDirectory = alloyHome() + fs + "binary";
            opt.originalFilename = Util.canon(text.get().getFilename());
            world = CompUtil.parseEverything_fromFile(A4Reporter.NOP, text.takeSnapshot(), opt.originalFilename, resolutionMode);
        } catch (Err er) {
            text.shade(er.pos);
            log.logRed(er.toString() + "\n\n");
            return null;
        }
        world.showAsTree(this);
    }
    return null;
}
Also used : Err(edu.mit.csail.sdg.alloy4.Err) A4Options(edu.mit.csail.sdg.translator.A4Options) Module(edu.mit.csail.sdg.ast.Module)

Example 9 with A4Options

use of edu.mit.csail.sdg.translator.A4Options 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 10 with A4Options

use of edu.mit.csail.sdg.translator.A4Options 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)

Aggregations

A4Options (edu.mit.csail.sdg.translator.A4Options)12 Command (edu.mit.csail.sdg.ast.Command)10 A4Solution (edu.mit.csail.sdg.translator.A4Solution)10 Module (edu.mit.csail.sdg.ast.Module)7 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)4 Expr (edu.mit.csail.sdg.ast.Expr)3 Sig (edu.mit.csail.sdg.ast.Sig)3 CompModule (edu.mit.csail.sdg.parser.CompModule)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 Decl (edu.mit.csail.sdg.ast.Decl)2 Func (edu.mit.csail.sdg.ast.Func)2 Test (org.junit.Test)2 ErrorAPI (edu.mit.csail.sdg.alloy4.ErrorAPI)1 VizGUI (edu.mit.csail.sdg.alloy4viz.VizGUI)1 SimpleCallback1 (edu.mit.csail.sdg.alloy4whole.SimpleReporter.SimpleCallback1)1 SimpleTask1 (edu.mit.csail.sdg.alloy4whole.SimpleReporter.SimpleTask1)1 ExprHasName (edu.mit.csail.sdg.ast.ExprHasName)1 Field (edu.mit.csail.sdg.ast.Sig.Field)1