use of edu.mit.csail.sdg.alloy4.ErrorAPI in project org.alloytools.alloy by AlloyTools.
the class SimInstance method makeAtom.
/**
* 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;
SimTupleset add = SimTupleset.make(SimTuple.make(atom));
if (cacheUNIV != null)
cacheUNIV = cacheUNIV.union(add);
for (; s != null; s = s.parent) if (!s.builtin) {
SimTupleset old = sfs.get(s);
if (old == null || old.empty())
sfs.put(s, add);
else if (!add.in(old))
sfs.put(s, old.union(add));
else
break;
}
return atom;
}
}
use of edu.mit.csail.sdg.alloy4.ErrorAPI in project org.alloytools.alloy by AlloyTools.
the class SimInstance method init.
/**
* Initializes the given sig 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(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();
}
use of edu.mit.csail.sdg.alloy4.ErrorAPI in project org.alloytools.alloy by AlloyTools.
the class A4Solution method shrink.
/**
* Shrink the bounds for the given relation; throws an exception if the new
* bounds is not sameAs/subsetOf the old bounds.
*/
void shrink(Relation relation, TupleSet lowerBound, TupleSet upperBound) throws Err {
if (solved)
throw new ErrorFatal("Cannot shrink a Kodkod relation since solve() has completed.");
TupleSet oldL = bounds.lowerBound(relation);
TupleSet oldU = bounds.upperBound(relation);
if (oldU.containsAll(upperBound) && upperBound.containsAll(lowerBound) && lowerBound.containsAll(oldL)) {
bounds.bound(relation, lowerBound, upperBound);
} else {
throw new ErrorAPI("Inconsistent bounds shrinking on relation: " + relation);
}
}
use of edu.mit.csail.sdg.alloy4.ErrorAPI in project org.alloytools.alloy by AlloyTools.
the class A4SolutionWriter method writeInstance.
/**
* 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");
}
out.print("\n</alloy>\n");
} catch (Throwable ex) {
if (ex instanceof Err)
throw (Err) ex;
else
throw new ErrorFatal("Error writing the solution XML file.", ex);
}
if (out.checkError())
throw new ErrorFatal("Error writing the solution XML file.");
}
use of edu.mit.csail.sdg.alloy4.ErrorAPI in project org.alloytools.alloy by AlloyTools.
the class A4TupleSet method plus.
/**
* 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)
// special short cut
return this;
TupleSet ts = tuples.clone();
ts.addAll(that.tuples);
if (tuples.size() == ts.size())
return this;
if (that.tuples.size() == ts.size())
return that;
return new A4TupleSet(ts, sol);
}
Aggregations