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