Search in sources :

Example 1 with MapNodeGraph

use of jcog.data.graph.MapNodeGraph in project narchy by automenta.

the class NodeGraphTest method testObjectGraph.

@Test
public void testObjectGraph() {
    MapNodeGraph<Object, Object> h = new MapNodeGraph<>();
    h.addEdge(h.addNode("y"), "yx", h.addNode("x"));
    ObjectGraph o = new ObjectGraph(3, h) {

        @Override
        protected boolean access(Object root, FasterList<Pair<Class, ObjectGraph.Accessor>> path, Object target) {
            System.out.println(root + " -> " + target + "\n\t" + path);
            return true;
        }

        @Override
        public boolean includeValue(Object value) {
            return true;
        }

        @Override
        public boolean includeClass(Class<?> c) {
            return !c.isPrimitive();
        }

        @Override
        public boolean includeField(Field f) {
            return true;
        }
    };
    o.print();
}
Also used : Field(java.lang.reflect.Field) FasterList(jcog.list.FasterList) ObjectGraph(jcog.data.graph.ObjectGraph) MapNodeGraph(jcog.data.graph.MapNodeGraph) Test(org.junit.jupiter.api.Test)

Example 2 with MapNodeGraph

use of jcog.data.graph.MapNodeGraph in project narchy by automenta.

the class NodeGraphTest method g1.

static NodeGraph g1() {
    MapNodeGraph n = new MapNodeGraph();
    n.addNode("a");
    n.addNode("b");
    n.addNode("c");
    n.addNode("d");
    n.addNode("e");
    edge(n, "a", "b");
    edge(n, "b", "c");
    edge(n, "c", "d");
    edge(n, "a", "e");
    return n;
}
Also used : MapNodeGraph(jcog.data.graph.MapNodeGraph)

Example 3 with MapNodeGraph

use of jcog.data.graph.MapNodeGraph in project narchy by automenta.

the class SimpleGraphTest method main.

public static void main(String[] args) {
    MutableGraph g = GraphBuilder.directed().build();
    g.putEdge(("a"), ("b"));
    g.putEdge(("b"), ("c"));
    g.putEdge(("b"), ("d"));
    MapNodeGraph h = new MapNodeGraph();
    h.addNode(("x"));
    h.addNode(("y"));
    h.addNode(("z"));
    h.addNode(("w"));
    h.addEdge(("x"), ("xy"), ("y"));
    h.addEdge(("x"), ("xz"), ("z"));
    h.addEdge(("y"), ("yz"), ("z"));
    h.addEdge(("w"), ("wy"), ("y"));
    SimpleGraph sg = new SimpleGraph();
    // sg.commit(g);
    sg.commit(h);
    sg.show(800, 600, false);
}
Also used : SimpleGraph(spacegraph.space3d.widget.SimpleGraph) MapNodeGraph(jcog.data.graph.MapNodeGraph) MutableGraph(com.google.common.graph.MutableGraph)

Example 4 with MapNodeGraph

use of jcog.data.graph.MapNodeGraph in project narchy by automenta.

the class TasksView method layoutTimeline.

public void layoutTimeline() {
    final MapNodeGraph<Surface, String> graph = new MapNodeGraph();
    float tScale = 100;
    float tMin = tScale;
    for (Surface cc : children()) {
        // TODO make window content iteration method
        TaskIcon c = (TaskIcon) cc;
        Task t = c.task;
        NodeGraph.MutableNode<Surface, String> tn = graph.addNode(c);
        for (long e : t.stamp()) {
            NodeGraph.Node en = graph.node(evidences.getIfAbsentPutWithKey(e, (ee) -> {
                Surface s = new PushButton("_" + ee);
                // TODO make evidence buttons visibility toggleable
                // children.add(s);
                graph.addNode(s);
                return s;
            }));
            graph.addEdge((NodeGraph.MutableNode) en, "stamp", tn);
        }
        float minH = 30;
        float maxH = 200;
        float h = t.isQuestOrQuestion() ? Util.lerp(t.originality() / 2f, minH, maxH) : Util.lerp(t.originality() * t.conf(), minH, maxH);
        long start, end;
        if (!t.isEternal()) {
            start = t.start();
            end = t.end();
        } else {
            start = t.creation();
            // TODO max time
            end = 10;
        }
        float x1 = start * tScale;
        float x2 = end * tScale;
        if (x2 - x1 < tMin) {
            float x = (x1 + x2) / 2f;
            x1 = x - tMin / 2;
            x2 = x + tMin / 2;
        }
        float y = (float) (Math.random() * 500);
        c.pos(x1, y, x2, y + h);
    }
    graph.print();
    new Thread(() -> {
        int iterations = 300;
        for (int i = 0; i < iterations; i++) {
            layoutForceDirect(graph);
            layout();
            Util.sleep(5);
        }
    }).start();
}
Also used : NodeGraph(jcog.data.graph.NodeGraph) MutableContainer(spacegraph.space2d.container.MutableContainer) PushButton(spacegraph.space2d.widget.button.PushButton) Surface(spacegraph.space2d.Surface) IOException(java.io.IOException) MapNodeGraph(jcog.data.graph.MapNodeGraph) Util(jcog.Util) spacegraph.util.math.v2(spacegraph.util.math.v2) File(java.io.File) Task(nars.Task) TODO(jcog.TODO) Op(nars.Op) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) SpaceGraph(spacegraph.SpaceGraph) Task(nars.Task) MapNodeGraph(jcog.data.graph.MapNodeGraph) NodeGraph(jcog.data.graph.NodeGraph) MapNodeGraph(jcog.data.graph.MapNodeGraph) Surface(spacegraph.space2d.Surface) PushButton(spacegraph.space2d.widget.button.PushButton)

Aggregations

MapNodeGraph (jcog.data.graph.MapNodeGraph)4 MutableGraph (com.google.common.graph.MutableGraph)1 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 TODO (jcog.TODO)1 Util (jcog.Util)1 NodeGraph (jcog.data.graph.NodeGraph)1 ObjectGraph (jcog.data.graph.ObjectGraph)1 FasterList (jcog.list.FasterList)1 Op (nars.Op)1 Task (nars.Task)1 LongObjectHashMap (org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap)1 Test (org.junit.jupiter.api.Test)1 SpaceGraph (spacegraph.SpaceGraph)1 Surface (spacegraph.space2d.Surface)1 MutableContainer (spacegraph.space2d.container.MutableContainer)1 PushButton (spacegraph.space2d.widget.button.PushButton)1 SimpleGraph (spacegraph.space3d.widget.SimpleGraph)1 spacegraph.util.math.v2 (spacegraph.util.math.v2)1