use of edu.mit.csail.sdg.alloy4.Pair 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.alloy4.Pair in project org.alloytools.alloy by AlloyTools.
the class A4Solution method highLevelCore.
/**
* If this solution is unsatisfiable and its unsat core is available, then
* return the core; else return an empty set.
*/
public Pair<Set<Pos>, Set<Pos>> highLevelCore() {
if (hCoreCache != null)
return hCoreCache;
Set<Pos> ans1 = new LinkedHashSet<Pos>(), ans2 = new LinkedHashSet<Pos>();
if (hCore != null)
for (Node f : hCore) {
Object x = k2pos(f);
if (x instanceof Pos) {
// System.out.println("F: "+f+" at "+x+"\n");
// System.out.flush();
ans1.add((Pos) x);
} else if (x instanceof Expr) {
Expr expr = (Expr) x;
Pos p = ((Expr) x).span();
ans1.add(p);
// System.out.flush();
for (Func func : expr.findAllFunctions()) ans2.add(func.getBody().span());
}
}
return hCoreCache = new Pair<Set<Pos>, Set<Pos>>(Collections.unmodifiableSet(ans1), Collections.unmodifiableSet(ans2));
}
use of edu.mit.csail.sdg.alloy4.Pair in project org.alloytools.alloy by AlloyTools.
the class Graph method draw.
// ============================================================================================================================//
/**
* Assuming layout has been performed, this draws the graph with the given
* magnification scale.
*/
void draw(Artist gr, double scale, Object highlight, boolean showLegends) {
if (nodes.size() == 0)
// The rest of this procedure assumes there is at least one
return;
// node
Object group = null;
GraphNode highFirstNode = null, highLastNode = null;
GraphEdge highFirstEdge = null, highLastEdge = null;
if (highlight instanceof GraphEdge) {
highFirstEdge = (GraphEdge) highlight;
highLastEdge = highFirstEdge;
group = highFirstEdge.group;
while (highFirstEdge.a().shape() == null) highFirstEdge = highFirstEdge.a().ins.get(0);
while (highLastEdge.b().shape() == null) highLastEdge = highLastEdge.b().outs.get(0);
highFirstNode = highFirstEdge.a();
highLastNode = highLastEdge.b();
} else if (!(highlight instanceof GraphNode) && highlight != null) {
group = highlight;
}
// Since drawing an edge will automatically draw all segments if they're
// connected via dummy nodes,
// we must make sure we only draw out edges from non-dummy-nodes
int maxAscent = Artist.getMaxAscent();
for (GraphNode n : nodes) if (n.shape() != null) {
for (GraphEdge e : n.outs) if (e.group != group)
e.draw(gr, scale, highFirstEdge, group);
for (GraphEdge e : n.selfs) if (e.group != group)
e.draw(gr, scale, highFirstEdge, group);
}
if (group != null) {
for (GraphNode n : nodes) if (n.shape() != null) {
for (GraphEdge e : n.outs) if (e.group == group && e != highFirstEdge)
e.draw(gr, scale, highFirstEdge, group);
for (GraphEdge e : n.selfs) if (e.group == group && e != highFirstEdge)
e.draw(gr, scale, highFirstEdge, group);
}
if (highFirstEdge != null)
highFirstEdge.draw(gr, scale, highFirstEdge, group);
}
for (GraphNode n : nodes) if (highFirstNode != n && highLastNode != n)
n.draw(gr, scale, n == highlight);
if (highFirstNode != null)
highFirstNode.draw(gr, scale, true);
if (highLastNode != null && highLastNode != highFirstNode)
highLastNode.draw(gr, scale, true);
if (highFirstEdge != null)
highFirstEdge.drawLabel(gr, highFirstEdge.color(), new Color(255, 255, 255, 160));
// show legends?
if (!showLegends || legends.size() == 0)
return;
boolean groupFound = false;
int y = 0, maxWidth = 0;
for (Map.Entry<Comparable<?>, Pair<String, Color>> e : legends.entrySet()) {
if (e.getValue().b == null)
continue;
if (group != null && e.getKey() == group)
groupFound = true;
int w = (int) getBounds(true, e.getValue().a).getWidth();
if (maxWidth < w)
maxWidth = w;
y = y + ad;
}
if (y == 0)
// This means no legends need to be drawn
return;
gr.setColor(Color.GRAY);
gr.draw(new RoundRectangle2D.Double(5, 5, maxWidth + 10, y + 10, 5, 5), false);
y = 10;
for (Map.Entry<Comparable<?>, Pair<String, Color>> e : legends.entrySet()) {
Color color = e.getValue().b;
if (color == null)
continue;
gr.setFont((groupFound && e.getKey() == group) || !groupFound);
gr.setColor((!groupFound || e.getKey() == group) ? color : Color.GRAY);
gr.drawString(e.getValue().a, 8, y + maxAscent);
y = y + ad;
}
}
Aggregations