Search in sources :

Example 6 with Pair

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;
}
Also used : Browsable(edu.mit.csail.sdg.ast.Browsable) Func(edu.mit.csail.sdg.ast.Func) ArrayList(java.util.ArrayList) Expr(edu.mit.csail.sdg.ast.Expr) Command(edu.mit.csail.sdg.ast.Command) Pos(edu.mit.csail.sdg.alloy4.Pos) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with Pair

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));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) TupleSet(kodkod.instance.TupleSet) Expr(edu.mit.csail.sdg.ast.Expr) Pos(edu.mit.csail.sdg.alloy4.Pos) Func(edu.mit.csail.sdg.ast.Func) Node(kodkod.ast.Node)

Example 8 with Pair

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;
    }
}
Also used : Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Pair(edu.mit.csail.sdg.alloy4.Pair)

Aggregations

Expr (edu.mit.csail.sdg.ast.Expr)5 Pair (edu.mit.csail.sdg.alloy4.Pair)4 Pos (edu.mit.csail.sdg.alloy4.Pos)4 Sig (edu.mit.csail.sdg.ast.Sig)4 ExprHasName (edu.mit.csail.sdg.ast.ExprHasName)3 Func (edu.mit.csail.sdg.ast.Func)3 Map (java.util.Map)3 Command (edu.mit.csail.sdg.ast.Command)2 Decl (edu.mit.csail.sdg.ast.Decl)2 Module (edu.mit.csail.sdg.ast.Module)2 Field (edu.mit.csail.sdg.ast.Sig.Field)2 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)2 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)2 A4Solution (edu.mit.csail.sdg.translator.A4Solution)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Set (java.util.Set)2 Err (edu.mit.csail.sdg.alloy4.Err)1 ErrorWarning (edu.mit.csail.sdg.alloy4.ErrorWarning)1 XMLNode (edu.mit.csail.sdg.alloy4.XMLNode)1