Search in sources :

Example 6 with DirectedSparseMultigraph

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

the class FqlppDisplay method buildFromFn.

@SuppressWarnings("unchecked")
private static Graph<Pair<String, Color>, Integer> buildFromFn(Fn f, Color src, Color dst) {
    Graph<Pair<String, Color>, Integer> g2 = new DirectedSparseMultigraph<>();
    for (Object n : f.source) {
        g2.addVertex(new Pair<>(Util.nice(n.toString()), src));
    }
    for (Object n : f.target) {
        g2.addVertex(new Pair<>(Util.nice(n.toString()), dst));
    }
    int i = 0;
    for (Object n : f.source) {
        Pair<String, Color> p1 = new Pair<>(Util.nice(n.toString()), src);
        Pair<String, Color> p2 = new Pair<>(Util.nice(f.apply(n).toString()), dst);
        g2.addEdge(i++, p1, p2);
    }
    return g2;
}
Also used : DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Color(java.awt.Color) Paint(java.awt.Paint) Pair(catdata.Pair)

Example 7 with DirectedSparseMultigraph

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

the class FqlppDisplay method build2Elements.

@SuppressWarnings("unchecked")
private static Graph build2Elements(Signature<Object, Object> sig, Transform<Object, Object, Set, Fn> trans) {
    Functor<Object, Object, Set, Fn> I = trans.source;
    Functor<Object, Object, Set, Fn> J = trans.target;
    Graph<Object, Object> ret = new DirectedSparseMultigraph<>();
    for (Node n : sig.nodes) {
        for (Object o : I.applyO(n)) {
            ret.addVertex(new Triple<>(o, n.name, "src"));
        }
    }
    for (Edge e : sig.edges) {
        for (Object o : I.applyO(e.source)) {
            Object fo = I.applyA(sig.path(e)).apply(o);
            Triple s = new Triple<>(o, e.source.name, "src");
            Triple t = new Triple<>(fo, e.target.name, "dst");
            ret.addEdge(new Quad<>(e.name, s, t, "src"), s, t);
        }
    }
    for (Node n : sig.nodes) {
        for (Object o : J.applyO(n)) {
            ret.addVertex(new Triple<>(o, n.name, "dst"));
        }
    }
    for (Edge e : sig.edges) {
        for (Object o : J.applyO(e.source)) {
            Object fo = J.applyA(sig.path(e)).apply(o);
            Triple s = new Triple<>(o, e.source.name, "dst");
            Triple t = new Triple<>(fo, e.target.name, "dst");
            ret.addEdge(new Quad<>(e.name, s, t, "dst"), s, t);
        }
    }
    int i = 0;
    for (Node n : sig.nodes) {
        for (Object o : I.applyO(n)) {
            Object fo = trans.apply(n).apply(o);
            Triple s = new Triple<>(o, n.name, "src");
            Triple t = new Triple<>(fo, n.name, "dst");
            ret.addEdge(new Quad<>("", s, t, i++), s, t);
        }
    }
    return ret;
}
Also used : Triple(catdata.Triple) Set(java.util.Set) FinSet(catdata.fqlpp.cat.FinSet) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Node(catdata.fqlpp.cat.Signature.Node) Fn(catdata.fqlpp.cat.FinSet.Fn) Edge(catdata.fqlpp.cat.Signature.Edge) Paint(java.awt.Paint)

Example 8 with DirectedSparseMultigraph

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

the class FqlppDisplay method buildMapping.

@SuppressWarnings("unchecked")
private static Graph buildMapping(Signature<String, String> src, Signature<String, String> dst, Functor F) {
    Graph<Object, Object> ret = new DirectedSparseMultigraph<>();
    for (Node n : src.nodes) {
        ret.addVertex(new Pair<>(n.name, "src"));
    }
    for (Edge e : src.edges) {
        Pair s = new Pair<>(e.source.name, "src");
        Pair t = new Pair<>(e.target.name, "src");
        ret.addEdge(new Quad<>(e.name, s, t, "src"), s, t);
    }
    for (Node n : dst.nodes) {
        ret.addVertex(new Pair<>(n.name, "dst"));
    }
    for (Edge e : dst.edges) {
        Pair s = new Pair<>(e.source.name, "dst");
        Pair t = new Pair<>(e.target.name, "dst");
        ret.addEdge(new Quad<>(e.name, s, t, "dst"), s, t);
    }
    int i = 0;
    for (Node n : src.nodes) {
        Node fo = (Node) F.applyO(n);
        Pair s = new Pair<>(n.name, "src");
        Pair t = new Pair<>(fo.name, "dst");
        ret.addEdge(new Quad<>("", s, t, i++), s, t);
    }
    return ret;
}
Also used : DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Node(catdata.fqlpp.cat.Signature.Node) Edge(catdata.fqlpp.cat.Signature.Edge) Paint(java.awt.Paint) Pair(catdata.Pair)

Example 9 with DirectedSparseMultigraph

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

the class XMapping method buildFromSig.

private Graph<Chc<C, D>, Object> buildFromSig() {
    String pre = "_38u5n";
    int i = 0;
    Graph<Chc<C, D>, Object> G = new DirectedSparseMultigraph<>();
    for (C n : src.ids) {
        G.addVertex(Chc.inLeft(n));
        G.addEdge(pre + i++, Chc.inLeft(n), Chc.inRight(em.get(n).get(0)));
    }
    for (D n : dst.ids) {
        G.addVertex(Chc.inRight(n));
    }
    for (C e : src.terms()) {
        if (src.allIds().contains(e)) {
            continue;
        }
        if (e.toString().startsWith("!")) {
            continue;
        }
        Pair<C, C> t = src.type(e);
        if (src.global.ids.contains(t.first) || src.global.ids.contains(t.second)) {
            continue;
        }
        G.addEdge(Chc.inLeft(e), Chc.inLeft(t.first), Chc.inLeft(t.second));
    }
    for (D e : dst.terms()) {
        if (dst.allIds().contains(e)) {
            continue;
        }
        if (e.toString().startsWith("!")) {
            continue;
        }
        Pair<D, D> t = dst.type(e);
        if (dst.global.ids.contains(t.first) || dst.global.ids.contains(t.second)) {
            continue;
        }
        G.addEdge(Chc.inRight(e), Chc.inRight(t.first), Chc.inRight(t.second));
    }
    return G;
}
Also used : DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Paint(java.awt.Paint) Chc(catdata.Chc)

Example 10 with DirectedSparseMultigraph

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

the class FQLProgram method build.

private Graph<String, Object> build() {
    // Graph<V, E> where V is the type of the vertices
    Graph<String, Object> g2 = new DirectedSparseMultigraph<>();
    Ref<Integer> guid = new Ref<>(0);
    for (String k : insts.keySet()) {
        InstExp i = insts.get(k);
        i.type(this).toConst(this);
        g2.addVertex(k);
        i.accept(new Unit(), new InstExpVisitor<Unit, Unit>() {

            @Override
            public Unit visit(Unit env, Zero e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, One e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, Two e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, Plus e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.a, k);
                g2.addEdge(new Pair<>(pp(guid), e), e.b, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Times e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.a, k);
                g2.addEdge(new Pair<>(pp(guid), e), e.b, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Exp e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.a, k);
                g2.addEdge(new Pair<>(pp(guid), e), e.b, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Const e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, Delta e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Sigma e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Pi e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, FullSigma e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Relationalize e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, External e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, Eval e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.e, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, FullEval e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.e, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Kernel e) {
                TransExp t = transforms.get(e.trans);
                Pair<String, String> p = t.type(FQLProgram.this);
                g2.addEdge(new Pair<>(pp(guid), e), p.first, k);
                g2.addEdge(new Pair<>(pp(guid), e), p.second, k);
                return null;
            }

            private Integer pp(Ref<Integer> ref) {
                int ret = ref.x;
                ref.x = ret + 1;
                return ref.x;
            }

            @Override
            public Unit visit(Unit env, Step e) {
                // (Step) this should add an edge
                return null;
            }
        });
    }
    return g2;
}
Also used : FullEval(catdata.fql.decl.InstExp.FullEval) One(catdata.fql.decl.InstExp.One) FullSigma(catdata.fql.decl.InstExp.FullSigma) Sigma(catdata.fql.decl.InstExp.Sigma) Step(catdata.fql.decl.InstExp.Step) Unit(catdata.Unit) Pi(catdata.fql.decl.InstExp.Pi) Plus(catdata.fql.decl.InstExp.Plus) FullEval(catdata.fql.decl.InstExp.FullEval) Eval(catdata.fql.decl.InstExp.Eval) Kernel(catdata.fql.decl.InstExp.Kernel) Pair(catdata.Pair) Relationalize(catdata.fql.decl.InstExp.Relationalize) Zero(catdata.fql.decl.InstExp.Zero) Const(catdata.fql.decl.InstExp.Const) Two(catdata.fql.decl.InstExp.Two) Ref(catdata.Ref) Delta(catdata.fql.decl.InstExp.Delta) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.decl.InstExp.FullSigma) Exp(catdata.fql.decl.InstExp.Exp)

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