Search in sources :

Example 21 with ErrorType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project org.alloytools.alloy by AlloyTools.

the class SimInstance method init.

/**
 * Initializes the given field to be associated with the given unary value;
 * should only be called at the beginning.
 * <p>
 * The resulting instance may or may not satisfy all facts, and should be
 * checked for consistency.
 */
public void init(Field field, SimTupleset value) throws Err {
    if (value == null) {
        sfs.remove(field);
        return;
    }
    if (!value.empty() && value.arity() != field.type().arity())
        throw new ErrorType("Evaluator encountered an error: field " + field.label + " arity must not be " + value.arity());
    if (field.defined)
        throw new ErrorAPI("Evaluator cannot prebind the value of a defined field.");
    sfs.put(field, value);
    cacheUNIV = null;
    cacheSTRING = null;
    cacheForConstants.clear();
}
Also used : ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 22 with ErrorType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project org.alloytools.alloy by AlloyTools.

the class CompModule method rejectNameClash.

// ============================================================================================================================//
private static void rejectNameClash(final List<CompModule> modules) throws Err {
    // The Alloy language forbids two overlapping sigs from having fields
    // with the same name.
    // In other words: if 2 fields have the same name, then their type's
    // first column must not intersect.
    final Map<String, List<Field>> fieldname2fields = new LinkedHashMap<String, List<Field>>();
    for (CompModule m : modules) {
        for (Sig sig : m.sigs.values()) {
            for (Field field : sig.getFields()) {
                List<Field> peers = fieldname2fields.get(field.label);
                if (peers == null) {
                    peers = new ArrayList<Field>();
                    fieldname2fields.put(field.label, peers);
                }
                for (Field field2 : peers) if (field.type().firstColumnOverlaps(field2.type()))
                    throw new ErrorType(field.pos, "Two overlapping signatures cannot have\n" + "two fields with the same name \"" + field.label + "\":\n\n1) one is in sig \"" + field.sig + "\"\n" + field.pos + "\n\n2) the other is in sig \"" + field2.sig + "\"\n" + field2.pos);
                peers.add(field);
            }
        }
    }
}
Also used : PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) Sig(edu.mit.csail.sdg.ast.Sig) SubsetSig(edu.mit.csail.sdg.ast.Sig.SubsetSig) Field(edu.mit.csail.sdg.ast.Sig.Field) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Util.asList(edu.mit.csail.sdg.alloy4.Util.asList) SafeList(edu.mit.csail.sdg.alloy4.SafeList) TempList(edu.mit.csail.sdg.alloy4.ConstList.TempList) List(java.util.List) ExprList(edu.mit.csail.sdg.ast.ExprList) ArrayList(java.util.ArrayList) JoinableList(edu.mit.csail.sdg.alloy4.JoinableList) ConstList(edu.mit.csail.sdg.alloy4.ConstList) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with ErrorType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project org.alloytools.alloy by AlloyTools.

the class TranslateAlloyToKodkod method execute_command.

/**
 * Based on the specified "options", execute one command and return the
 * resulting A4Solution object.
 *
 * @param rep - if nonnull, we'll send compilation diagnostic messages to it
 * @param sigs - the list of sigs; this list must be complete
 * @param cmd - the Command to execute
 * @param opt - the set of options guiding the execution of the command
 * @return null if the user chose "save to FILE" as the SAT solver, and nonnull
 *         if the solver finishes the entire solving and is either satisfiable
 *         or unsatisfiable.
 *         <p>
 *         If the return value X is satisfiable, you can call X.next() to get
 *         the next satisfying solution X2; and you can call X2.next() to get
 *         the next satisfying solution X3... until you get an unsatisfying
 *         solution.
 */
public static A4Solution execute_command(A4Reporter rep, Iterable<Sig> sigs, Command cmd, A4Options opt) throws Err {
    if (rep == null)
        rep = A4Reporter.NOP;
    TranslateAlloyToKodkod tr = null;
    try {
        if (cmd.parent != null || !cmd.getGrowableSigs().isEmpty())
            return execute_greedyCommand(rep, sigs, cmd, opt);
        tr = new TranslateAlloyToKodkod(rep, opt, sigs, cmd);
        tr.makeFacts(cmd.formula);
        return tr.frame.solve(rep, cmd, new Simplifier(), false);
    } catch (UnsatisfiedLinkError ex) {
        throw new ErrorFatal("The required JNI library cannot be found: " + ex.toString().trim(), ex);
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        Pos p = tr != null ? tr.frame.kv2typepos(ex.decl().variable()).b : Pos.UNKNOWN;
        throw new ErrorType(p, "Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        else
            throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
    }
}
Also used : CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) Pos(edu.mit.csail.sdg.alloy4.Pos) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException)

Example 24 with ErrorType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project org.alloytools.alloy by AlloyTools.

the class TranslateAlloyToKodkod method execute_greedyCommand.

private static A4Solution execute_greedyCommand(A4Reporter rep, Iterable<Sig> sigs, Command usercommand, A4Options opt) throws Exception {
    // FIXTHIS: if the next command has a "smaller scope" than the last
    // command, we would get a Kodkod exception...
    // FIXTHIS: if the solver is "toCNF" or "toKodkod" then this method will
    // throw an Exception...
    // FIXTHIS: does solution enumeration still work when we're doing a
    // greedy solve?
    TranslateAlloyToKodkod tr = null;
    try {
        long start = System.currentTimeMillis();
        GreedySimulator sim = new GreedySimulator();
        sim.allSigs = sigs;
        sim.partial = null;
        A4Reporter rep2 = new A4Reporter(rep) {

            private boolean first = true;

            @Override
            public void translate(String solver, int bitwidth, int maxseq, int skolemDepth, int symmetry) {
                if (first)
                    super.translate(solver, bitwidth, maxseq, skolemDepth, symmetry);
                first = false;
            }

            @Override
            public void resultSAT(Object command, long solvingTime, Object solution) {
            }

            @Override
            public void resultUNSAT(Object command, long solvingTime, Object solution) {
            }
        };
        // Form the list of commands
        List<Command> commands = new ArrayList<Command>();
        while (usercommand != null) {
            commands.add(usercommand);
            usercommand = usercommand.parent;
        }
        // For each command...
        A4Solution sol = null;
        for (int i = commands.size() - 1; i >= 0; i--) {
            Command cmd = commands.get(i);
            sim.growableSigs = cmd.getGrowableSigs();
            while (cmd != null) {
                rep.debug(cmd.scope.toString());
                usercommand = cmd;
                tr = new TranslateAlloyToKodkod(rep2, opt, sigs, cmd);
                tr.makeFacts(cmd.formula);
                sim.totalOrderPredicates = tr.totalOrderPredicates;
                sol = tr.frame.solve(rep2, cmd, sim.partial == null || cmd.check ? new Simplifier() : sim, false);
                if (!sol.satisfiable() && !cmd.check) {
                    start = System.currentTimeMillis() - start;
                    if (sim.partial == null) {
                        rep.resultUNSAT(cmd, start, sol);
                        return sol;
                    } else {
                        rep.resultSAT(cmd, start, sim.partial);
                        return sim.partial;
                    }
                }
                if (sol.satisfiable() && cmd.check) {
                    start = System.currentTimeMillis() - start;
                    rep.resultSAT(cmd, start, sol);
                    return sol;
                }
                sim.partial = sol;
                if (sim.growableSigs.isEmpty())
                    break;
                for (Sig s : sim.growableSigs) {
                    CommandScope sc = cmd.getScope(s);
                    if (sc.increment > sc.endingScope - sc.startingScope) {
                        cmd = null;
                        break;
                    }
                    cmd = cmd.change(s, sc.isExact, sc.startingScope + sc.increment, sc.endingScope, sc.increment);
                }
            }
        }
        if (sol.satisfiable())
            rep.resultSAT(usercommand, System.currentTimeMillis() - start, sol);
        else
            rep.resultUNSAT(usercommand, System.currentTimeMillis() - start, sol);
        return sol;
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        Pos p = tr != null ? tr.frame.kv2typepos(ex.decl().variable()).b : Pos.UNKNOWN;
        throw new ErrorType(p, "Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    }
}
Also used : A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) ArrayList(java.util.ArrayList) Sig(edu.mit.csail.sdg.ast.Sig) CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Command(edu.mit.csail.sdg.ast.Command) Pos(edu.mit.csail.sdg.alloy4.Pos) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) CommandScope(edu.mit.csail.sdg.ast.CommandScope)

Example 25 with ErrorType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project org.alloytools.alloy by AlloyTools.

the class TranslateAlloyToKodkod method alloy2kodkod.

/**
 * Translate the Alloy expression into an equivalent Kodkod Expression or
 * IntExpression or Formula object.
 *
 * @param sol - an existing satisfiable A4Solution object
 * @param expr - this is the Alloy expression we want to translate
 */
public static Object alloy2kodkod(A4Solution sol, Expr expr) throws Err {
    if (expr.ambiguous && !expr.errors.isEmpty())
        expr = expr.resolve(expr.type(), null);
    if (!expr.errors.isEmpty())
        throw expr.errors.pick();
    TranslateAlloyToKodkod tr = new TranslateAlloyToKodkod(sol.getBitwidth(), sol.unrolls(), sol.a2k(), sol.s2k());
    Object ans;
    try {
        ans = tr.visitThis(expr);
    } catch (UnsatisfiedLinkError ex) {
        throw new ErrorFatal("The required JNI library cannot be found: " + ex.toString().trim());
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        throw new ErrorType("Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
    }
    if ((ans instanceof IntExpression) || (ans instanceof Formula) || (ans instanceof Expression))
        return ans;
    throw new ErrorFatal("Unknown internal error encountered in the evaluator.");
}
Also used : QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) Expression(kodkod.ast.Expression) BinaryExpression(kodkod.ast.BinaryExpression) IntExpression(kodkod.ast.IntExpression) IntExpression(kodkod.ast.IntExpression) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException)

Aggregations

ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)18 ArrayList (java.util.ArrayList)9 Err (edu.mit.csail.sdg.alloy4.Err)6 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)6 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)6 Pos (edu.mit.csail.sdg.alloy4.Pos)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)5 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)4 CapacityExceededException (kodkod.engine.CapacityExceededException)4 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)4 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)3 Expr (edu.mit.csail.sdg.ast.Expr)3 Sig (edu.mit.csail.sdg.ast.Sig)3 ExecutionException (java.util.concurrent.ExecutionException)3 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)3 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)3 ErrorMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder)3 RpcError (org.opendaylight.yangtools.yang.common.RpcError)3 Env (edu.mit.csail.sdg.alloy4.Env)2