Search in sources :

Example 6 with SafeList

use of edu.mit.csail.sdg.alloy4.SafeList 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

Sig (edu.mit.csail.sdg.ast.Sig)5 SafeList (edu.mit.csail.sdg.alloy4.SafeList)3 Field (edu.mit.csail.sdg.ast.Sig.Field)3 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)3 A4Solution (edu.mit.csail.sdg.translator.A4Solution)3 ConstList (edu.mit.csail.sdg.alloy4.ConstList)2 Err (edu.mit.csail.sdg.alloy4.Err)2 XMLNode (edu.mit.csail.sdg.alloy4.XMLNode)2 ExprVar (edu.mit.csail.sdg.ast.ExprVar)2 StringReader (java.io.StringReader)2 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)1 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)1 ErrorAPI (edu.mit.csail.sdg.alloy4.ErrorAPI)1 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)1 Command (edu.mit.csail.sdg.ast.Command)1 Expr (edu.mit.csail.sdg.ast.Expr)1 Func (edu.mit.csail.sdg.ast.Func)1 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)1 CompModule (edu.mit.csail.sdg.parser.CompModule)1 A4Options (edu.mit.csail.sdg.translator.A4Options)1