Package org.graphstream.graph

Examples of org.graphstream.graph.Edge


   * java.lang.Object)
   */
  public void edgeAttributeChanged(String sourceId, long timeId,
      String edgeId, String attribute, Object oldValue, Object newValue) {
    if (sinkTime.isNewEvent(sourceId, timeId)) {
      Edge edge = g.getEdge(edgeId);
      if (edge != null) {
        passYourWay = true;

        if (oldValue == null)
          oldValue = edge.getAttribute(attribute);

        try {
          edge.changeAttribute(attribute, newValue);
        } finally {
          passYourWay = false;
        }

        sendEdgeAttributeChanged(sourceId, timeId, edgeId, attribute,
View Full Code Here


   * .String, long, java.lang.String, java.lang.String)
   */
  public void edgeAttributeRemoved(String sourceId, long timeId,
      String edgeId, String attribute) {
    if (sinkTime.isNewEvent(sourceId, timeId)) {
      Edge edge = g.getEdge(edgeId);
      if (edge != null) {
        sendEdgeAttributeRemoved(sourceId, timeId, edgeId, attribute);
        passYourWay = true;

        try {
          edge.removeAttribute(attribute);
        } finally {
          passYourWay = false;
        }

      }
View Full Code Here

          events.add(new NodeRemoved(n1.getId()));
        }
      }

      for (int idx = 0; idx < g2.getEdgeCount(); idx++) {
        Edge e2 = g2.getEdge(idx);
        Edge e1 = g1.getEdge(e2.getId());

        if (e1 == null)
          events.add(new EdgeAdded(e2.getId(), e2.getSourceNode()
              .getId(), e2.getTargetNode().getId(), e2
              .isDirected()));

        attributeDiff(ElementType.EDGE, e1, e2);
      }

      for (int idx = 0; idx < g1.getEdgeCount(); idx++) {
        Edge e1 = g1.getEdge(idx);
        Edge e2 = g2.getEdge(e1.getId());

        if (e2 == null) {
          attributeDiff(ElementType.EDGE, e1, e2);
          events.add(new EdgeRemoved(e1.getId(), e1.getSourceNode()
              .getId(), e1.getTargetNode().getId(), e1
View Full Code Here

     *
     * @see org.graphstream.stream.ElementSink#edgeRemoved(java.lang.String,
     * long, java.lang.String)
     */
    public void edgeRemoved(String sourceId, long timeId, String edgeId) {
      Edge edge = g.getEdge(edgeId);

      for (String key : edge.getAttributeKeySet())
        edgeAttributeRemoved(sourceId, timeId, edgeId, key);

      Event e;
      e = new EdgeRemoved(edgeId, edge.getSourceNode().getId(), edge
          .getTargetNode().getId(), edge.isDirected());
      events.add(e);
    }
View Full Code Here

  protected void testDirected(Graph graph) {
    Node A = graph.addNode("A");
    Node B = graph.addNode("B");
    Node C = graph.addNode("C");

    Edge AB = graph.addEdge("AB", "A", "B");
    Edge BC = graph.addEdge("BC", "B", "C", true);
    Edge CA = graph.addEdge("CA", "C", "A", false);

    // A
    // |\
    // | \
    // | \
    // | \
    // B--->C

    assertFalse(AB.isDirected());
    assertTrue(BC.isDirected());
    assertFalse(CA.isDirected());

    assertEquals(2, A.getDegree());
    assertEquals(2, B.getDegree());
    assertEquals(2, C.getDegree());

    assertEquals(2, A.getInDegree());
    assertEquals(2, A.getOutDegree());
    assertEquals(1, B.getInDegree());
    assertEquals(2, B.getOutDegree());
    assertEquals(2, C.getInDegree());
    assertEquals(1, C.getOutDegree());

    assertEquals(AB, A.getEdgeFrom("B"));
    assertEquals(CA, A.getEdgeFrom("C"));
    assertEquals(AB, B.getEdgeFrom("A"));
    assertNull(B.getEdgeFrom("C"));
    assertEquals(CA, C.getEdgeFrom("A"));
    assertEquals(BC, C.getEdgeFrom("B"));

    assertEquals(AB, A.getEdgeToward("B"));
    assertEquals(CA, A.getEdgeToward("C"));
    assertEquals(AB, B.getEdgeToward("A"));
    assertEquals(BC, B.getEdgeToward("C"));
    assertEquals(CA, C.getEdgeToward("A"));
    assertNull(C.getEdgeToward("B"));

    // Now change things a little :
    //
    // A
    // |\
    // | \
    // | \
    // v \
    // B<---C
    //
    // BC changes its direction, and AB becomes directed.

    graph.removeEdge("BC");
    BC = graph.addEdge("BC", "C", "B", true);
    graph.removeEdge("AB");
    AB = graph.addEdge("AB", "A", "B", true);

    assertTrue(AB.isDirected());
    assertTrue(BC.isDirected());
    assertFalse(CA.isDirected());

    assertEquals(2, A.getDegree());
    assertEquals(2, B.getDegree());
    assertEquals(2, C.getDegree());

    assertEquals(1, A.getInDegree());
    assertEquals(2, A.getOutDegree());
    assertEquals(2, B.getInDegree());
    assertEquals(0, B.getOutDegree());
    assertEquals(1, C.getInDegree());
    assertEquals(2, C.getOutDegree());

    assertNull(A.getEdgeFrom("B"));
    assertEquals(CA, A.getEdgeFrom("C"));
    assertEquals(AB, B.getEdgeFrom("A"));
    assertEquals(BC, B.getEdgeFrom("C"));
    assertEquals(CA, C.getEdgeFrom("A"));
    assertNull(C.getEdgeFrom("B"));

    assertEquals(AB, A.getEdgeToward("B"));
    assertEquals(CA, A.getEdgeToward("C"));
    assertNull(B.getEdgeToward("A"));
    assertNull(B.getEdgeToward("C"));
    assertEquals(CA, C.getEdgeToward("A"));
    assertEquals(BC, C.getEdgeToward("B"));
   
    // Directed loop edges
    assertFalse(A.hasEdgeBetween(A));
    assertFalse(A.hasEdgeToward(A));
    assertFalse(A.hasEdgeFrom(A));
    assertNull(A.getEdgeBetween(A));
    assertNull(A.getEdgeToward(A));
    assertNull(A.getEdgeFrom(A));   
    Edge AA = graph.addEdge("AA", "A", "A", true);
    assertEquals(4, graph.getEdgeCount());
    assertEquals(3, A.getDegree());
    assertEquals(2, A.getInDegree());
    assertEquals(3, A.getOutDegree());
    assertTrue(A.hasEdgeBetween(A));
    assertTrue(A.hasEdgeToward(A));
    assertTrue(A.hasEdgeFrom(A));
    assertEquals(AA, A.getEdgeBetween(A));
    assertEquals(AA, A.getEdgeToward(A));
    assertEquals(AA, A.getEdgeFrom(A));   
    assertEquals(A, AA.getSourceNode());
    assertEquals(A, AA.getTargetNode());   
  }
View Full Code Here

  protected void testIterables(Graph graph) {
    Node A = graph.addNode("A");
    Node B = graph.addNode("B");
    Node C = graph.addNode("C");

    Edge AB = graph.addEdge("AB", "A", "B");
    Edge BC = graph.addEdge("BC", "B", "C");
    Edge CA = graph.addEdge("CA", "C", "A");

    // Test graph iterables.

    HashSet<Node> nodes = new HashSet<Node>();
    HashSet<Edge> edges = new HashSet<Edge>();
View Full Code Here

  public void testRemoval(Graph graph) {
    Node A = graph.addNode("A");
    graph.addNode("B");
    graph.addNode("C");

    Edge AB = graph.addEdge("AB", "A", "B");
    graph.addEdge("BC", "B", "C");
    Edge CA = graph.addEdge("CA", "C", "A");

    assertEquals(3, graph.getNodeCount());
    assertEquals(3, graph.getEdgeCount());

    // Remove a node. This should also remove two edges.

    Node n = graph.removeNode("A");

    assertEquals(2, graph.getNodeCount());
    assertEquals(1, graph.getEdgeCount());

    assertEquals(n, A);
    assertNull(graph.getEdge("AB"));
    assertNull(graph.getEdge("CA"));
    assertNull(graph.getNode("A"));

    assertNotNull(graph.getEdge("BC"));
    assertNotNull(graph.getNode("B"));
    assertNotNull(graph.getNode("C"));

    // Rebuild the graph and remove an edge.

    A = graph.addNode("A");
    AB = graph.addEdge("AB", "A", "B");
    CA = graph.addEdge("CA", "C", "A");

    assertEquals(3, graph.getNodeCount());
    assertEquals(3, graph.getEdgeCount());

    Edge e = graph.removeEdge("A", "B");

    assertEquals(3, graph.getNodeCount());
    assertEquals(2, graph.getEdgeCount());

    assertEquals(e, AB);
    assertNull(graph.getEdge("AB"));

    assertNotNull(graph.getNode("A"));
    assertNotNull(graph.getNode("B"));
    assertNotNull(graph.getNode("C"));
    assertNotNull(graph.getEdge("BC"));
    assertNotNull(graph.getEdge("CA"));

    // Now remove another edge in another way.

    e = graph.removeEdge("CA");

    assertEquals(3, graph.getNodeCount());
    assertEquals(1, graph.getEdgeCount());

    assertEquals(e, CA);
    assertNull(graph.getEdge("AB"));
    assertNull(graph.getEdge("CA"));

    assertNotNull(graph.getNode("A"));
    assertNotNull(graph.getNode("B"));
    assertNotNull(graph.getNode("C"));
    assertNotNull(graph.getEdge("BC"));
   
    // loop edges
    Edge AA = graph.addEdge("AA", "A", "A");
    assertEquals(2, graph.getEdgeCount());
    e = graph.removeEdge("AA");
    assertEquals(1, graph.getEdgeCount());
    assertEquals(AA, e);
    assertEquals(0, A.getDegree());
    assertNull(graph.getEdge("AA"));
   
    Edge BB = graph.addEdge("BB", "B", "B", true);
    assertEquals(2, graph.getEdgeCount());
    e = graph.removeEdge("BB");
    assertEquals(BB, e);
    assertEquals(1, graph.getNode("B").getDegree());
    assertNull(graph.getEdge("BB"));
View Full Code Here

    Node A = input.addNode("A");
    input.addNode("B");
    input.addNode("C");

    input.addEdge("AB", "A", "B");
    Edge BC = input.addEdge("BC", "B", "C");
    input.addEdge("CA", "C", "A");

    A.addAttribute("foo", "bar");
    BC.addAttribute("foo", "bar");

    assertEquals(3, input.getNodeCount());
    assertEquals(3, output.getNodeCount());
    assertEquals(3, input.getEdgeCount());
    assertEquals(3, output.getEdgeCount());

    assertNotNull(output.getNode("A"));
    assertNotNull(output.getNode("B"));
    assertNotNull(output.getNode("C"));
    assertNotNull(output.getEdge("AB"));
    assertNotNull(output.getEdge("BC"));
    assertNotNull(output.getEdge("CA"));

    assertEquals("bar", output.getNode("A").getAttribute("foo"));
    assertEquals("bar", output.getEdge("BC").getAttribute("foo"));

    // Now remove an attribute.

    A.removeAttribute("foo");

    assertFalse(output.hasAttribute("foo"));

    // Now remove a node.

    input.removeNode("A");

    assertEquals(2, input.getNodeCount());
    assertEquals(1, input.getEdgeCount());
    assertEquals(2, output.getNodeCount());
    assertEquals(1, output.getEdgeCount());

    // Now check that attribute change works.

    BC.changeAttribute("foo", "truc");

    assertEquals("truc", BC.getAttribute("foo"));
    assertEquals("truc", output.getEdge("BC").getAttribute("foo"));
  }
View Full Code Here

  protected void findCommunities(Graph graph, double threshold) {
    int nedges = graph.getEdgeCount();
    double avgDist = 0;
    double edgesDists[] = new double[nedges];
    for(int i=0; i<nedges; i++) {
      Edge edge = graph.getEdge(i);
      Point3 posFrom = GraphPosLengthUtils.nodePointPosition(edge.getNode0());
      Point3 posTo   = GraphPosLengthUtils.nodePointPosition(edge.getNode1());
      edgesDists[i= posFrom.distance(posTo);
      avgDist       += edgesDists[i];
    }
    avgDist /= nedges;
    // Nothing happened to the graph so the order remains.
    for(int i=0; i<nedges; i++) {
      Edge edge = graph.getEdge(i);
      if(edgesDists[i] > avgDist*threshold) {
        edge.addAttribute("ui.class", "cut");
      } else {
        edge.removeAttribute("ui.class");
      }
    }
  }
View Full Code Here

    Node A1 = g1.addNode("A");
    Node B1 = g1.addNode("B");
    Node C1 = g1.addNode("C");

    Edge AB1 = g1.addEdge("AB", "A", "B");
    Edge BC1 = g1.addEdge("BC", "B", "C");
    Edge CA1 = g1.addEdge("CA", "C", "A");

    A1.addAttribute("string", "an example");
    B1.addAttribute("double", 42.0);
    C1.addAttribute("array", new int[] { 1, 2, 3 });

    AB1.addAttribute("string", "an example");
    BC1.addAttribute("double", 42.0);
    CA1.addAttribute("array", new int[] { 1, 2, 3 });

    Replayable.Controller controller = g1.getReplayController();
    controller.addSink(g2);
    controller.replay();

    Node A2 = g2.getNode("A");
    Node B2 = g2.getNode("B");
    Node C2 = g2.getNode("C");

    assertNotNull(A2);
    assertNotNull(B2);
    assertNotNull(C2);

    checkAttribute(A1, A2);
    checkAttribute(B1, B2);
    checkAttribute(C1, C2);

    Edge AB2 = g2.getEdge("AB");
    Edge BC2 = g2.getEdge("BC");
    Edge CA2 = g2.getEdge("CA");

    assertNotNull(AB2);
    assertNotNull(BC2);
    assertNotNull(CA2);
View Full Code Here

TOP

Related Classes of org.graphstream.graph.Edge

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.