Search in sources :

Example 11 with A4Solution

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

the class InternalTest method test1.

public void test1() throws Exception {
    XMLNode xml = new XMLNode(new StringReader("<alloy builddate='unknown'>" + "<instance bitwidth='2' maxseq='1' command='Run Deadlock' filename='dijkstra.als'>" + "<sig label='univ' ID='0' builtin='yes'> <atom label='-2'/> <atom label='-1'/> <atom label='0'/> <atom label='1'/> <atom label='State$0'/> <atom label='State$1'/> <atom label='State$2'/> </sig>" + "<sig label='Int' ID='1' parentID='0' builtin='yes'> <atom label='-2'/> <atom label='-1'/> <atom label='0'/> <atom label='1'/> </sig>" + "<sig label='seq/Int' ID='2' parentID='1' builtin='yes'> <atom label='0'/> </sig>" + "<sig label='State' ID='5' parentID='0'> <atom label='State$0'/> <atom label='State$1'/> <atom label='State$2'/> </sig>" + "<field label='len' parentID='5' ID='17'>" + "   <tuple> <atom label='State$1'/> <atom label='-2'/> </tuple>" + "   <tuple> <atom label='State$1'/> <atom label='-1'/> </tuple>" + "   <types> <type ID='5'/> <type ID='1'/> </types>" + "</field>" + "<skolem label='$Deadlock_s' ID='16'>" + "   <tuple> <atom label='State$0'/> </tuple>" + "   <types> <type ID='5'/> </types>" + "</skolem>" + "</instance>" + "</alloy>"));
    Sig state = new Sig.PrimSig("State");
    A4Solution sol = A4SolutionReader.read(Arrays.asList(state), xml);
    SafeList<ExprVar> skolems = new SafeList<ExprVar>(sol.getAllSkolems());
    check(skolems.size() == 1);
    check(skolems.get(0).label, "$Deadlock_s");
    check(skolems.get(0).type(), state.type());
    // 
    Sig state2 = new Sig.PrimSig("State");
    Field field2 = state2.addField("len", Sig.SIGINT);
    sol = A4SolutionReader.read(Arrays.asList(state2), xml);
    SafeList<ExprVar> skolems2 = new SafeList<ExprVar>(sol.getAllSkolems());
    check(skolems2.size() == 1);
    check(skolems2.get(0).label, "$Deadlock_s");
    check(skolems2.get(0).type(), state2.type());
    check("" + sol.eval(field2.cardinality()), "-2");
}
Also used : Sig(edu.mit.csail.sdg.ast.Sig) ExprVar(edu.mit.csail.sdg.ast.ExprVar) Field(edu.mit.csail.sdg.ast.Sig.Field) XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) SafeList(edu.mit.csail.sdg.alloy4.SafeList) StringReader(java.io.StringReader) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 12 with A4Solution

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

the class InternalTest method test2.

public void test2() throws Exception {
    test1();
    XMLNode xml = new XMLNode(new StringReader("<alloy builddate='unknown'>" + "<instance bitwidth='2' maxseq='1' command='Run Deadlock' filename='dijkstra.als'>" + "<sig label='univ' ID='0' builtin='yes'> <atom label='-2'/> <atom label='-1'/> <atom label='0'/> <atom label='1'/> <atom label='State$0'/> <atom label='State$1'/> <atom label='State$2'/> </sig>" + "<sig label='Int' ID='1' parentID='0' builtin='yes'> <atom label='-2'/> <atom label='-1'/> <atom label='0'/> <atom label='1'/> </sig>" + "<sig label='seq/Int' ID='2' parentID='1' builtin='yes'> <atom label='0'/> </sig>" + "<sig label='Act' ID='5' parentID='0'> <atom label='Act$0'/> <atom label='Act$1'/> <atom label='Act$2'/> </sig>" + "<skolem label='$x' ID='16'>" + "   <tuple> <atom label='0'/> <atom label='Act$1'/> </tuple>" + "   <types> <type ID='2'/> <type ID='5'/> </types>" + "</skolem>" + "</instance>" + "</alloy>"));
    Sig activity = new Sig.PrimSig("Act");
    A4Solution sol = A4SolutionReader.read(Arrays.asList(activity), xml);
    SafeList<ExprVar> skolems = new SafeList<ExprVar>(sol.getAllSkolems());
    check(skolems.size() == 1);
    check(skolems.get(0).label, "$x");
    check(skolems.get(0).type(), Sig.SEQIDX.type().product(activity.type()));
}
Also used : Sig(edu.mit.csail.sdg.ast.Sig) ExprVar(edu.mit.csail.sdg.ast.ExprVar) XMLNode(edu.mit.csail.sdg.alloy4.XMLNode) SafeList(edu.mit.csail.sdg.alloy4.SafeList) StringReader(java.io.StringReader) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 13 with A4Solution

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

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

Example 15 with A4Solution

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

the class ExampleCompilingFromSource method compileModuleAndRun.

public static void compileModuleAndRun(String model) throws Err {
    A4Reporter rep = new A4Reporter();
    // parse model from string
    CompModule world = CompUtil.parseEverything_fromString(rep, model);
    ConstList<Command> commands = world.getAllCommands();
    if (commands.size() != 1)
        throw new ErrorAPI("Must specify exactly one command; number of commands found: " + commands.size());
    Command cmd = commands.get(0);
    A4Options opt = new A4Options();
    opt.solver = A4Options.SatSolver.SAT4J;
    // solve
    A4Solution sol = TranslateAlloyToKodkod.execute_command(rep, world.getAllSigs(), cmd, opt);
    // print solution
    System.out.println(sol);
    for (Sig sig : world.getAllReachableSigs()) {
        System.out.println("traversing sig: " + sig);
        SafeList<Field> fields = sig.getFields();
        for (Field field : fields) {
            System.out.println("  traversing field: " + field);
            A4TupleSet ts = (sol.eval(field));
            for (A4Tuple t : ts) {
                System.out.print("    [");
                for (int i = 0; i < t.arity(); i++) System.out.print(t.atom(i) + " ");
                System.out.println("]");
            }
        }
    }
}
Also used : ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) A4TupleSet(edu.mit.csail.sdg.translator.A4TupleSet) Sig(edu.mit.csail.sdg.ast.Sig) Field(edu.mit.csail.sdg.ast.Sig.Field) A4Tuple(edu.mit.csail.sdg.translator.A4Tuple) CompModule(edu.mit.csail.sdg.parser.CompModule) Command(edu.mit.csail.sdg.ast.Command) A4Options(edu.mit.csail.sdg.translator.A4Options) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Aggregations

A4Solution (edu.mit.csail.sdg.translator.A4Solution)15 Command (edu.mit.csail.sdg.ast.Command)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)4 XMLNode (edu.mit.csail.sdg.alloy4.XMLNode)4 Expr (edu.mit.csail.sdg.ast.Expr)3 ExprVar (edu.mit.csail.sdg.ast.ExprVar)3 CompModule (edu.mit.csail.sdg.parser.CompModule)3 StringReader (java.io.StringReader)3 ErrorWarning (edu.mit.csail.sdg.alloy4.ErrorWarning)2 SafeList (edu.mit.csail.sdg.alloy4.SafeList)2 Decl (edu.mit.csail.sdg.ast.Decl)2 ExprHasName (edu.mit.csail.sdg.ast.ExprHasName)2 Func (edu.mit.csail.sdg.ast.Func)2 Field (edu.mit.csail.sdg.ast.Sig.Field)2 A4Tuple (edu.mit.csail.sdg.translator.A4Tuple)2 Test (org.junit.Test)2 Err (edu.mit.csail.sdg.alloy4.Err)1