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();
}
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);
}
}
}
}
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);
}
}
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.");
}
}
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.");
}
Aggregations