Search in sources :

Example 11 with ErrorAPI

use of edu.mit.csail.sdg.alloy4.ErrorAPI in project org.alloytools.alloy by AlloyTools.

the class A4TupleSet method intersect.

/**
 * Construct a new tupleset as the intersection of this and that; this and that
 * must be come from the same solution.
 */
public A4TupleSet intersect(A4TupleSet that) throws ErrorAPI {
    if (sol != that.sol)
        throw new ErrorAPI("A4TupleSet.intersect() requires 2 tuplesets from the same A4Solution.");
    if (arity() != that.arity())
        throw new ErrorAPI("A4TupleSet.intersect() requires 2 tuplesets with the same arity.");
    if (this.tuples.size() == 0)
        // special short cut
        return this;
    if (that.tuples.size() == 0)
        // special short cut
        return that;
    TupleSet ts = tuples.clone();
    ts.retainAll(that.tuples);
    if (tuples.size() != ts.size())
        return new A4TupleSet(ts, sol);
    else
        return this;
}
Also used : TupleSet(kodkod.instance.TupleSet) ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI)

Example 12 with ErrorAPI

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

ErrorAPI (edu.mit.csail.sdg.alloy4.ErrorAPI)9 TupleSet (kodkod.instance.TupleSet)4 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)2 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)2 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)2 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)2 Command (edu.mit.csail.sdg.ast.Command)2 A4Options (edu.mit.csail.sdg.translator.A4Options)2 A4Solution (edu.mit.csail.sdg.translator.A4Solution)2 Err (edu.mit.csail.sdg.alloy4.Err)1 ErrorWarning (edu.mit.csail.sdg.alloy4.ErrorWarning)1 VizGUI (edu.mit.csail.sdg.alloy4viz.VizGUI)1 Module (edu.mit.csail.sdg.ast.Module)1 Sig (edu.mit.csail.sdg.ast.Sig)1 Field (edu.mit.csail.sdg.ast.Sig.Field)1 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)1 CompModule (edu.mit.csail.sdg.parser.CompModule)1 A4Tuple (edu.mit.csail.sdg.translator.A4Tuple)1 A4TupleSet (edu.mit.csail.sdg.translator.A4TupleSet)1