use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class AlloyModelsTest method minimalAlloyDoc.
@Test
public void minimalAlloyDoc() throws Exception {
CompModule world = CompUtil.parseEverything_fromString(A4Reporter.NOP, "sig Foo {} \n" + "run { 1 < #Int } for 10 int\n");
A4Options options = new A4Options();
options.unrolls = 10;
for (Command command : world.getAllCommands()) {
A4Solution ans = TranslateAlloyToKodkod.execute_command(A4Reporter.NOP, world.getAllReachableSigs(), command, options);
while (ans.satisfiable()) {
String hc = "Answer: " + ans.toString().hashCode();
System.out.println(hc);
ans = ans.next();
}
return;
}
}
use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class CompModule method getSubnodes.
/**
* {@inheritDoc}
*/
@Override
public List<? extends Browsable> getSubnodes() {
ArrayList<Browsable> ans = new ArrayList<Browsable>();
ArrayList<Browsable> x;
if (opens.size() > 0) {
x = new ArrayList<Browsable>(opens.size());
for (Open e : opens.values()) if (!x.contains(e.realModule))
x.add(e.realModule);
ans.add(make("<b>" + x.size() + (x.size() > 1 ? " opens</b>" : " open</b>"), x));
}
if (sigs.size() > 0) {
x = new ArrayList<Browsable>(sigs.values());
ans.add(make("<b>" + x.size() + (x.size() > 1 ? " sigs</b>" : " sig</b>"), x));
}
if (funcs.size() > 0) {
ArrayList<Browsable> x2 = new ArrayList<Browsable>(funcs.size());
x = new ArrayList<Browsable>(funcs.size());
for (ArrayList<Func> e : funcs.values()) for (Func f : e) if (f.isPred)
x.add(f);
else
x2.add(f);
if (x.size() > 0)
ans.add(make("<b>" + x.size() + (x.size() > 1 ? " preds</b>" : " pred</b>"), x));
if (x2.size() > 0)
ans.add(make("<b>" + x2.size() + (x2.size() > 1 ? " funs</b>" : " fun</b>"), x2));
}
if (commands.size() > 0) {
ArrayList<Browsable> x2 = new ArrayList<Browsable>(commands.size());
x = new ArrayList<Browsable>(commands.size());
for (Command e : commands) if (e.check)
x.add(e);
else
x2.add(e);
if (x.size() > 0)
ans.add(make("<b>" + x.size() + (x.size() > 1 ? " checks</b>" : " check</b>"), x));
if (x2.size() > 0)
ans.add(make("<b>" + x2.size() + (x2.size() > 1 ? " runs</b>" : " run</b>"), x2));
}
if (facts.size() > 0) {
x = new ArrayList<Browsable>(facts.size());
for (Pair<String, Expr> e : facts) x.add(make(e.b.span(), e.b.span(), "<b>fact " + e.a + "</b>", e.b));
ans.add(make("<b>" + x.size() + (x.size() > 1 ? " facts</b>" : " fact</b>"), x));
}
if (asserts.size() > 0) {
x = new ArrayList<Browsable>(asserts.size());
for (Map.Entry<String, Expr> e : asserts.entrySet()) {
Pos sp = e.getValue().span();
x.add(make(sp, sp, "<b>assert</b> " + e.getKey(), e.getValue()));
}
ans.add(make("<b>" + x.size() + (x.size() > 1 ? " asserts</b>" : " assert</b>"), x));
}
return ans;
}
use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class CompModule method resolveCommands.
/**
* Each command now points to a typechecked Expr.
*/
private void resolveCommands(Expr globalFacts) throws Err {
ConstList<Sig> exactSigs = ConstList.make(world.exactSigs);
for (int i = 0; i < commands.size(); i++) {
Command cmd = commands.get(i);
cmd = resolveCommand(cmd, exactSigs, globalFacts);
commands.set(i, cmd);
}
}
use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class CompModule method addDefaultCommand.
public void addDefaultCommand() {
if (commands.isEmpty()) {
addFunc(Pos.UNKNOWN, Pos.UNKNOWN, "$$Default", null, new ArrayList<Decl>(), null, ExprConstant.TRUE);
commands.add(new Command(Pos.UNKNOWN, ExprConstant.TRUE, "Default", false, 4, 4, 4, 0, null, null, ExprVar.make(null, "$$Default"), null));
}
}
use of edu.mit.csail.sdg.ast.Command 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.");
}
}
Aggregations