Package edu.mit.csail.sdg.alloy4

Examples of edu.mit.csail.sdg.alloy4.ErrorAPI


    /** If this solution is solved and satisfiable, evaluates the given expression and returns an A4TupleSet, a java Integer, or a java Boolean. */
    public Object eval(Expr expr) throws Err {
        try {
           if (expr instanceof Sig) return eval((Sig)expr);
           if (expr instanceof Field) return eval((Field)expr);
           if (!solved) throw new ErrorAPI("This solution is not yet solved, so eval() is not allowed.");
           if (eval==null) throw new ErrorAPI("This solution is unsatisfiable, so eval() is not allowed.");
           if (expr.ambiguous && !expr.errors.isEmpty()) expr = expr.resolve(expr.type(), null);
           if (!expr.errors.isEmpty()) throw expr.errors.pick();
           Object result = TranslateAlloyToKodkod.alloy2kodkod(this, expr);
           if (result instanceof IntExpression) return eval.evaluate((IntExpression)result);
           if (result instanceof Formula) return eval.evaluate((Formula)result);
View Full Code Here


        }
    }

    /** Returns the Kodkod instance represented by this solution; throws an exception if the problem is not yet solved or if it is unsatisfiable. */
    public Instance debugExtractKInstance() throws Err {
        if (!solved) throw new ErrorAPI("This solution is not yet solved, so instance() is not allowed.");
        if (eval==null) throw new ErrorAPI("This solution is unsatisfiable, so instance() is not allowed.");
        return eval.instance().unmodifiableView();
    }
View Full Code Here

    /** Create a fresh atom for the given sig, then return the newly created atom.
     * @throws ErrorAPI if attempting to add an atom to an abstract sig with children, or a builtin sig, or a subset sig.
     */
    public SimAtom makeAtom(Sig sig) throws Err {
        if (sig.builtin) throw new ErrorAPI("Cannot add an atom to a builtin sig.");
        if (!(sig instanceof PrimSig)) throw new ErrorAPI("Cannot add an atom to a subset sig.");
        PrimSig s = (PrimSig)sig;
        if (s.isAbstract!=null && !s.children().isEmpty()) throw new ErrorAPI("Cannot add an atom to an abstract parent sig.");
        String label = sig.label + "$";
        if (label.startsWith("this/")) label=label.substring(5);
        for(int i=0; ;i++) {
          SimAtom atom = SimAtom.make(label + i);
          if (hasAtom(atom)) continue;
View Full Code Here

     * <p> The resulting instance may or may not satisfy all facts, and should be checked for consistency.
     */
    public void init(Sig sig, SimTupleset value) throws Err {
        if (value==null) { sfs.remove(sig); return; }
        if (value.arity()>1) throw new ErrorType("Evaluator encountered an error: sig "+sig.label+" arity must not be " + value.arity());
        if (sig.builtin) throw new ErrorAPI("Evaluator cannot prebind the builtin sig \"" + sig.label + "\"");
        sfs.put(sig, value);
        cacheUNIV = null;
        cacheSTRING = null;
        cacheForConstants.clear();
    }
View Full Code Here

    /** If this solution is UNSAT, return itself; else return the next solution (which could be SAT or UNSAT).
     * @throws ErrorAPI if the solver was not an incremental solver
     */
    public A4Solution next() throws Err {
        if (!solved) throw new ErrorAPI("This solution is not yet solved, so next() is not allowed.");
        if (eval==null) return this;
        if (nextCache==null) nextCache=new A4Solution(this);
        return nextCache;
    }
View Full Code Here

        out.print("\n</instance>\n");
    }

    /** If this solution is a satisfiable solution, this method will write it out in XML format. */
    static void writeInstance(A4Reporter rep, A4Solution sol, PrintWriter out, Iterable<Func> extraSkolems, Map<String,String> sources) throws Err {
        if (!sol.satisfiable()) throw new ErrorAPI("This solution is unsatisfiable.");
        try {
            Util.encodeXMLs(out, "<alloy builddate=\"", Version.buildDate(), "\">\n\n");
            new A4SolutionWriter(rep, sol, sol.getAllReachableSigs(), sol.getBitwidth(), sol.getMaxSeq(), sol.getOriginalCommand(), sol.getOriginalFilename(), out, extraSkolems);
            if (sources!=null) for(Map.Entry<String,String> e: sources.entrySet()) {
                Util.encodeXMLs(out, "\n<source filename=\"", e.getKey(), "\" content=\"", e.getValue(), "\"/>\n");
View Full Code Here

            for(int i=0; i<this.options.length; i++) this.options[i] = options[i];
            if (add) { synchronized(SatSolver.class) { values.add(this); } }
        }
        /** Constructs a new SatSolver value that uses a command-line solver; throws ErrorAPI if the ID is already in use. */
        public static SatSolver make(String id, String toString, String external, String[] options) throws ErrorAPI {
            if (id==null || toString==null || external==null) throw new ErrorAPI("NullPointerException in SatSolver.make()");
            SatSolver ans = new SatSolver(id, toString, external, options, false);
            synchronized(SatSolver.class) {
               for(SatSolver x: values)
                  if (x.id.equals(id))
                     throw new ErrorAPI("The SatSolver id \""+id+"\" is already in use.");
               values.add(ans);
            }
            return ans;
        }
View Full Code Here

    /** Returns the number of tuples in this tuple set. */
    public int size() { return tuples.size(); }

    /** Construct a new tupleset as the product of this and that; this and that must be come from the same solution. */
    public A4TupleSet product(A4TupleSet that) throws ErrorAPI {
        if (sol != that.sol) throw new ErrorAPI("A4TupleSet.product() requires 2 tuplesets from the same A4Solution.");
        return new A4TupleSet(tuples.product(that.tuples), sol);
    }
View Full Code Here

    /** Construct a new tupleset as the union of this and that; this and that must be come from the same solution.
     * Note: if that==null, then the method returns this A4TupleSet as-is. */
    public A4TupleSet plus(A4TupleSet that) throws ErrorAPI {
        if (that==null) return this;
        if (sol != that.sol) throw new ErrorAPI("A4TupleSet.plus() requires 2 tuplesets from the same A4Solution.");
        if (arity() != that.arity()) throw new ErrorAPI("A4TupleSet.plus() requires 2 tuplesets with the same arity.");
        if (this==that || tuples.size()==0) return that; else if (that.tuples.size()==0) return this; // special short cut
        TupleSet ts = tuples.clone();
        ts.addAll(that.tuples);
        if (tuples.size()==ts.size()) return this;
        if (that.tuples.size()==ts.size()) return that;
View Full Code Here

    /** Construct a new tupleset as the subtraction of this and that; this and that must be come from the same solution.
     * Note: if that==null, then the method returns this A4TupleSet as-is. */
    public A4TupleSet minus(A4TupleSet that) throws ErrorAPI {
        if (that==null) return this;
        if (sol != that.sol) throw new ErrorAPI("A4TupleSet.minus() requires 2 tuplesets from the same A4Solution.");
        if (arity() != that.arity()) throw new ErrorAPI("A4TupleSet.minus() requires 2 tuplesets with the same arity.");
        if (tuples.size()==0 || that.tuples.size()==0) return this; // special short cut
        TupleSet ts = tuples.clone();
        ts.removeAll(that.tuples);
        if (tuples.size()!=ts.size()) return new A4TupleSet(ts, sol); else return this;
    }
View Full Code Here

TOP

Related Classes of edu.mit.csail.sdg.alloy4.ErrorAPI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.