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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations