Search in sources :

Example 1 with DirectedSparseMultigraph

use of edu.uci.ics.jung.graph.DirectedSparseMultigraph in project fql by CategoricalData.

the class XCtx method elemGraph.

private Graph<Triple<C, C, List<C>>, Pair<Integer, C>> elemGraph() {
    Graph<Triple<C, C, List<C>>, Pair<Integer, C>> g = new DirectedSparseMultigraph<>();
    @SuppressWarnings("unchecked") C ccc = (C) "_1";
    for (Triple<C, C, List<C>> arr : cat().arrowsFrom(ccc)) {
        if (global.ids.contains(arr.second)) {
            continue;
        }
        if (arr.second.equals("_1")) {
            continue;
        }
        g.addVertex(arr);
    }
    int i = 0;
    for (Triple<C, C, List<C>> arr : cat().arrowsFrom(ccc)) {
        if (global.ids.contains(arr.second)) {
            continue;
        }
        if (cat().isId(arr)) {
            continue;
        }
        if (arr.second.equals("_1")) {
            continue;
        }
        for (C c : schema.terms()) {
            Pair<C, C> t = schema.type(c);
            if (!t.first.equals(arr.second)) {
                continue;
            }
            if (global.ids.contains(t.second)) {
                continue;
            }
            if (t.second.equals("_1")) {
                continue;
            }
            if (schema.ids.contains(c)) {
                continue;
            }
            List<C> l = new LinkedList<>(arr.third);
            l.add(c);
            Triple<C, C, List<C>> tofind = new Triple<>(arr.first, t.second, l);
            Triple<C, C, List<C>> found = find_fast(tofind);
            g.addEdge(new Pair<>(i++, c), arr, found);
        }
    }
    return g;
}
Also used : Paint(java.awt.Paint) LinkedList(java.util.LinkedList) Triple(catdata.Triple) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) LinkedList(java.util.LinkedList) List(java.util.List) Pair(catdata.Pair)

Example 2 with DirectedSparseMultigraph

use of edu.uci.ics.jung.graph.DirectedSparseMultigraph in project fql by CategoricalData.

the class AqlViewer method viewGraph.

/*
	public static Optional<JComponent> viewPragma(Pragma p) {
		if (p instanceof ToCsvPragmaTransform) {
			return Optional.empty();
		} else if (p instanceof ToCsvPragmaInstance) {
			return Optional.of(viewPragmaToCsvInstance((ToCsvPragmaInstance)p));
		}
		throw new RuntimeException("Anomaly: please report");
	} 
	
	private static JComponent viewPragmaToCsvInstance(ToCsvPragmaInstance p) {
		return new JPanel();
	} */
private static <N, E> JComponent viewGraph(DMG<N, E> g) {
    Graph<N, E> sgv = new DirectedSparseMultigraph<>();
    for (N n : g.nodes) {
        sgv.addVertex(n);
    }
    for (E e : g.edges.keySet()) {
        sgv.addEdge(e, g.edges.get(e).first, g.edges.get(e).second);
    }
    if (sgv.getVertexCount() == 0) {
        return new JPanel();
    }
    Layout<N, E> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<N, E> vv = new VisualizationViewer<>(layout);
    Function<N, Paint> vertexPaint = x -> Color.black;
    DefaultModalGraphMouse<N, E> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<E, String> et = Object::toString;
    Function<N, String> vt = Object::toString;
    vv.getRenderContext().setEdgeLabelTransformer(et);
    vv.getRenderContext().setVertexLabelTransformer(vt);
    GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
    JPanel ret = new JPanel(new GridLayout(1, 1));
    ret.add(zzz);
    ret.setBorder(BorderFactory.createEtchedBorder());
    vv.getRenderContext().setLabelOffset(16);
    vv.setBackground(Color.white);
    return ret;
}
Also used : Color(java.awt.Color) TypeSide(catdata.aql.TypeSide) Sym(catdata.aql.exp.TyExpRaw.Sym) Comment(catdata.aql.Comment) Constraints(catdata.aql.Constraints) AqlOption(catdata.aql.AqlOptions.AqlOption) Instance(catdata.aql.Instance) Map(java.util.Map) Exp(catdata.aql.exp.Exp) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) DP(catdata.aql.DP) Term(catdata.aql.Term) BorderLayout(java.awt.BorderLayout) Pair(catdata.Pair) Semantics(catdata.aql.Semantics) Function(com.google.common.base.Function) Transform(catdata.aql.Transform) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) ColimitSchema(catdata.aql.ColimitSchema) Query(catdata.aql.Query) DMG(catdata.graph.DMG) Component(java.awt.Component) Collectors(java.util.stream.Collectors) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) Paint(java.awt.Paint) Sk(catdata.aql.exp.InstExpRaw.Sk) Triple(catdata.Triple) Algebra(catdata.aql.Algebra) CombinatorParser(catdata.aql.exp.CombinatorParser) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) Ty(catdata.aql.exp.TyExpRaw.Ty) Pragma(catdata.aql.Pragma) Ctx(catdata.Ctx) JSplitPane(javax.swing.JSplitPane) RawTerm(catdata.aql.RawTerm) En(catdata.aql.exp.SchExpRaw.En) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Chc(catdata.Chc) AqlParser(catdata.aql.exp.AqlParser) Gen(catdata.aql.exp.InstExpRaw.Gen) GridLayout(java.awt.GridLayout) LinkedHashMap(java.util.LinkedHashMap) Mapping(catdata.aql.Mapping) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) AqlJs(catdata.aql.AqlJs) Collage(catdata.aql.Collage) LinkedList(java.util.LinkedList) JComponent(javax.swing.JComponent) Morphism(catdata.aql.Morphism) Fk(catdata.aql.exp.SchExpRaw.Fk) Layout(edu.uci.ics.jung.algorithms.layout.Layout) JButton(javax.swing.JButton) CodeTextPanel(catdata.ide.CodeTextPanel) SemanticsVisitor(catdata.aql.SemanticsVisitor) Util(catdata.Util) Unit(catdata.Unit) Att(catdata.aql.exp.SchExpRaw.Att) Split(catdata.ide.Split) AqlEnv(catdata.aql.exp.AqlEnv) Schema(catdata.aql.Schema) Var(catdata.aql.Var) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JPanel(javax.swing.JPanel) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 3 with DirectedSparseMultigraph

use of edu.uci.ics.jung.graph.DirectedSparseMultigraph in project dwoss by gg-net.

the class Grapher method showFull.

/**
 * Show the full StateMachine with a special formater.
 * <p/>
 * @param <T>          type of state machine
 * @param stateMachine the statemachine to show
 * @param formater     an optional formater
 */
public static <T> void showFull(final StateMachine<T> stateMachine, final StateFormater<T> formater) {
    DirectedGraph<State<T>, String> g = new DirectedSparseMultigraph<>();
    int i = 0;
    for (Link<T> link : stateMachine.getLinks()) {
        // TODO: A Graph needs for each transition a unique id. A StateMachine not. So we build it here.
        g.addEdge("[" + (i++) + "] " + link.getTransition().toString(), link.getSource(), link.getDestination());
    }
    FRLayout<State<T>, String> layout = new FRLayout<>(g);
    // layout.setRepulsionMultiplier(2);
    // layout.setMaxIterations(20);
    // sets the initial size of the space
    layout.setSize(new Dimension(1100, 950));
    VisualizationViewer<State<T>, String> vv = new VisualizationViewer<>(layout);
    // Sets the viewing area size
    vv.setPreferredSize(new Dimension(1280, 1024));
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
    // final VisualizationModel<String,Number> visualizationModel =
    // new DefaultVisualizationModel<String,Number>(layout, preferredSize);
    // this class will provide both label drawing and vertex shapes
    VertexLabelAsShapeRenderer<State<T>, String> vlasr = new VertexLabelAsShapeRenderer<>(vv.getRenderContext());
    // // customize the render context
    if (formater != null) {
        vv.getRenderContext().setVertexLabelTransformer((state) -> {
            return formater.toHtml(state);
        });
        vv.setVertexToolTipTransformer((state) -> {
            return formater.toToolTipHtml(state);
        });
    }
    vv.getRenderContext().setVertexShapeTransformer(vlasr);
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.RED));
    vv.getRenderContext().setEdgeDrawPaintTransformer((input) -> {
        return Color.DARK_GRAY;
    });
    vv.getRenderContext().setEdgeStrokeTransformer((input) -> {
        return new BasicStroke(2.5f);
    });
    // customize the renderer
    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<State<T>, String>(Color.LIGHT_GRAY, Color.WHITE, true));
    vv.getRenderer().setVertexLabelRenderer(vlasr);
    DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    vv.addKeyListener(gm.getModeKeyListener());
    JFrame frame = new JFrame("Simple Graph View");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(vv, BorderLayout.CENTER);
    frame.getContentPane().add(gm.getModeComboBox(), BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
}
Also used : DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) JFrame(javax.swing.JFrame) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 4 with DirectedSparseMultigraph

use of edu.uci.ics.jung.graph.DirectedSparseMultigraph in project fql by CategoricalData.

the class Transform method build.

private Pair<Graph<Quad<Node, Object, String, Boolean>, Pair<Path, Integer>>, HashMap<Quad<Node, Object, String, Boolean>, Map<Attribute<Node>, Object>>> build(String src_n, String dst_n) throws FQLException {
    FinCat<Node, Path> c = src.thesig.toCategory2().first;
    HashMap<Quad<Node, Object, String, Boolean>, Map<Attribute<Node>, Object>> map = new HashMap<>();
    Graph<Quad<Node, Object, String, Boolean>, Pair<Path, Integer>> g2 = new DirectedSparseMultigraph<>();
    for (Node n : c.objects) {
        for (Pair<Object, Object> o : src.data.get(n.string)) {
            Quad<Node, Object, String, Boolean> xx = new Quad<>(n, o.first, src_n, true);
            g2.addVertex(xx);
            List<Attribute<Node>> attrs = src.thesig.attrsFor(n);
            Map<Attribute<Node>, Object> m = new HashMap<>();
            for (Attribute<Node> attr : attrs) {
                Object a = lookup(src.data.get(attr.name), o.first);
                m.put(attr, a);
            }
            map.put(xx, m);
        }
    }
    int j = 0;
    for (Quad<Node, Object, String, Boolean> x : g2.getVertices()) {
        for (Quad<Node, Object, String, Boolean> y : g2.getVertices()) {
            if (!x.third.equals(y.third)) {
                continue;
            }
            Set<Arr<Node, Path>> h = c.hom(x.first, y.first);
            for (Arr<Node, Path> arr : h) {
                if (c.isId(arr)) {
                    continue;
                }
                if (!DefunctGlobalOptions.debug.fql.ALL_GR_PATHS && arr.arr.path.size() != 1) {
                    continue;
                }
                if (doLookup(src, arr.arr, x.second, y.second)) {
                    g2.addEdge(new Pair<>(arr.arr, j++), x, y);
                }
            }
        }
    }
    for (Node n : c.objects) {
        for (Pair<Object, Object> o : dst.data.get(n.string)) {
            Quad<Node, Object, String, Boolean> xx = new Quad<>(n, o.first, dst_n, false);
            g2.addVertex(xx);
            List<Attribute<Node>> attrs = dst.thesig.attrsFor(n);
            Map<Attribute<Node>, Object> m = new HashMap<>();
            for (Attribute<Node> attr : attrs) {
                Object a = lookup(dst.data.get(attr.name), o.first);
                m.put(attr, a);
            }
            map.put(xx, m);
        }
    }
    for (Quad<Node, Object, String, Boolean> x : g2.getVertices()) {
        for (Quad<Node, Object, String, Boolean> y : g2.getVertices()) {
            Set<Arr<Node, Path>> h = c.hom(x.first, y.first);
            for (Arr<Node, Path> arr : h) {
                if (c.isId(arr)) {
                    continue;
                }
                if (!DefunctGlobalOptions.debug.fql.ALL_GR_PATHS && arr.arr.path.size() != 1) {
                    continue;
                }
                if (doLookup(dst, arr.arr, x.second, y.second)) {
                    g2.addEdge(new Pair<>(arr.arr, j++), x, y);
                }
            }
        }
    }
    for (String k : data.keySet()) {
        Set<Pair<Object, Object>> v = data.get(k);
        for (Pair<Object, Object> i : v) {
            Node n = src.thesig.getNode(k);
            g2.addEdge(new Pair<>(null, j++), new Quad<>(n, i.first, src_n, true), new Quad<>(n, i.second, dst_n, false));
        }
    }
    return new Pair<>(g2, map);
}
Also used : Arr(catdata.fql.cat.Arr) Quad(catdata.Quad) HashMap(java.util.HashMap) Pair(catdata.Pair) Paint(java.awt.Paint) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with DirectedSparseMultigraph

use of edu.uci.ics.jung.graph.DirectedSparseMultigraph in project fql by CategoricalData.

the class CategoryOfElements method build.

private static Pair<Graph<Pair<Node, Object>, Pair<Path, Integer>>, HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>>> build(Instance i) throws FQLException {
    FinCat<Node, Path> c = i.thesig.toCategory2().first;
    HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>> map = new HashMap<>();
    Graph<Pair<Node, Object>, Pair<Path, Integer>> g2 = new DirectedSparseMultigraph<>();
    for (Node n : c.objects) {
        for (Pair<Object, Object> o : i.data.get(n.string)) {
            Pair<Node, Object> xx = new Pair<>(n, o.first);
            g2.addVertex(xx);
            List<Attribute<Node>> attrs = i.thesig.attrsFor(n);
            Map<Attribute<Node>, Object> m = new HashMap<>();
            for (Attribute<Node> attr : attrs) {
                Object a = lookup(i.data.get(attr.name), o.first);
                m.put(attr, a);
            }
            map.put(xx, m);
        }
    }
    int j = 0;
    for (Pair<Node, Object> x : g2.getVertices()) {
        for (Pair<Node, Object> y : g2.getVertices()) {
            Set<Arr<Node, Path>> h = c.hom(x.first, y.first);
            for (Arr<Node, Path> arr : h) {
                if (c.isId(arr)) {
                    continue;
                }
                if (!DefunctGlobalOptions.debug.fql.ALL_GR_PATHS && arr.arr.path.size() != 1) {
                    continue;
                }
                if (doLookup(i, arr.arr, x.second, y.second)) {
                    g2.addEdge(new Pair<>(arr.arr, j++), x, y);
                }
            }
        }
    }
    return new Pair<>(g2, map);
}
Also used : Path(catdata.fql.decl.Path) Arr(catdata.fql.cat.Arr) HashMap(java.util.HashMap) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) Paint(java.awt.Paint) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) HashMap(java.util.HashMap) Map(java.util.Map) Pair(catdata.Pair)

Aggregations

DirectedSparseMultigraph (edu.uci.ics.jung.graph.DirectedSparseMultigraph)11 Paint (java.awt.Paint)9 Pair (catdata.Pair)8 Triple (catdata.Triple)4 Chc (catdata.Chc)3 Unit (catdata.Unit)3 Map (java.util.Map)3 Ctx (catdata.Ctx)2 Util (catdata.Util)2 Algebra (catdata.aql.Algebra)2 AqlJs (catdata.aql.AqlJs)2 AqlOption (catdata.aql.AqlOptions.AqlOption)2 ColimitSchema (catdata.aql.ColimitSchema)2 Collage (catdata.aql.Collage)2 Comment (catdata.aql.Comment)2 Constraints (catdata.aql.Constraints)2 DP (catdata.aql.DP)2 Instance (catdata.aql.Instance)2 Mapping (catdata.aql.Mapping)2 Morphism (catdata.aql.Morphism)2