Package org.graphstream.graph

Examples of org.graphstream.graph.Node


    // Iterating on all nodes
    start = System.currentTimeMillis();
    Iterator<Node> nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      if (n.hasAttribute("foo"))
        foo++;
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.GRAPH_NODE_IT, end - start);
View Full Code Here


    // For each node n, iterating on all edges of n
    start = System.currentTimeMillis();
    Iterator<Node> nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      Iterator<Edge> edgeIt = n.getEdgeIterator();
      while (edgeIt.hasNext()) {
        Edge e = edgeIt.next();
        if (e.hasAttribute("foo"))
          foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.NODE_EDGE_IT, end - start);

    // For each node n, iterating on all entering edges of n
    start = System.currentTimeMillis();
    nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      Iterator<Edge> edgeIt = n.getEnteringEdgeIterator();
      while (edgeIt.hasNext()) {
        Edge e = edgeIt.next();
        if (e.hasAttribute("foo"))
          foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.NODE_ENTERING_EDGE_IT, end - start);

    // For each node n, iterating on all leaving edges of n
    start = System.currentTimeMillis();
    nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      Iterator<Edge> edgeIt = n.getLeavingEdgeIterator();
      while (edgeIt.hasNext()) {
        Edge e = edgeIt.next();
        if (e.hasAttribute("foo"))
          foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.NODE_LEAVING_EDGE_IT, end - start);

    // For each node n, iterating on all neighbors of n
    start = System.currentTimeMillis();
    nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      Iterator<Node> neighborIt = n.getNeighborNodeIterator();
      while (neighborIt.hasNext()) {
        Node neighbor = neighborIt.next();
        if (neighbor.hasAttribute("foo"))
          foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.NODE_NEIGHBOR_IT, end - start);

    // For each node n, iterating on all edges of n using n.getEdge(i)
    start = System.currentTimeMillis();
    nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      for (int i = 0; i < n.getDegree(); i++) {
        Edge e = n.getEdge(i);
        if (e.hasAttribute("foo"))
          foo++;
      }
    }
    end = System.currentTimeMillis();
View Full Code Here

    start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
      Iterator<Node> bfsIt = g.getNode(nodeIds.get(i))
          .getBreadthFirstIterator();
      while (bfsIt.hasNext()) {
        Node node = bfsIt.next();
        if (node.hasAttribute("foo"))
          foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.BFS_IT, end - start);

    // DFS from 1000 nodes - tested only for new implementations
    // because of a bug in the old
    start = System.currentTimeMillis();
    if (g instanceof org.graphstream.graph.implementations.AbstractGraph) {
      for (int i = 0; i < 1000; i++) {
        Iterator<Node> dfsIt = g.getNode(nodeIds.get(i))
            .getDepthFirstIterator();
        while (dfsIt.hasNext()) {
          Node node = dfsIt.next();
          if (node.hasAttribute("foo"))
            foo++;
        }
      }
    }
    end = System.currentTimeMillis();
View Full Code Here

    start = System.currentTimeMillis();
    int count = 0;
    for (Node n0 : g) {
      int d = n0.getDegree();
      for (int i = 0; i < d; i++) {
        Node n1 = n0.getEdge(i).getOpposite(n0);
        String n1id = n1.getId();
        for (int j = i + 1; j < d; j++) {
          Node n2 = n0.getEdge(j).getOpposite(n0);
          if (n2.hasEdgeBetween(n1id))
            count++;
        }
      }
    }
    end = System.currentTimeMillis();
View Full Code Here

    start = System.currentTimeMillis();
    int count = 0;
    for (Node n0 : g) {
      int d = n0.getDegree();
      for (int i = 0; i < d; i++) {
        Node n1 = n0.getEdge(i).getOpposite(n0);
        if (n0.getIndex() < n1.getIndex()) {
          for (int j = i + 1; j < d; j++) {
            Node n2 = n0.getEdge(j).getOpposite(n0);
            if (n1.getIndex() < n2.getIndex() && n2.hasEdgeBetween(n1))
              count++;
          }
        }
      }
    }
View Full Code Here

    int foo = 0;

    // for each pair of nodes (n1, n2) find the edge between n1 and n2
    long start = System.currentTimeMillis();
    for (String id1 : nodeIds) {
      Node n1 = g.getNode(id1);
      for (String id2 : nodeIds) {
        Edge e = n1.getEdgeBetween(id2);
        if (e != null && e.hasAttribute("foo"))
          foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.EDGE_BETWEEN, end - start);

    // for each pair of nodes (n1, n2) find the edge from n1 to n2
    start = System.currentTimeMillis();
    for (String id1 : nodeIds) {
      Node n1 = g.getNode(id1);
      for (String id2 : nodeIds) {
        Edge e = n1.getEdgeToward(id2);
        if (e != null && e.hasAttribute("foo"))
          foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.EDGE_TOWARD, end - start);

    // for each pair of nodes (n1, n2) find the edge from n2 to n1
    start = System.currentTimeMillis();
    for (String id1 : nodeIds) {
      Node n1 = g.getNode(id1);
      for (String id2 : nodeIds) {
        Edge e = n1.getEdgeFrom(id2);
        if (e != null && e.hasAttribute("foo"))
          foo++;
      }
    }
    end = System.currentTimeMillis();
View Full Code Here

public class TestElement {
  @Test(expected=NullAttributeException.class)
  public void testElementSimpleAttributes() {
    Graph graph = new MultiGraph("g1");

    Node A = graph.addNode("A");

    assertEquals("A", A.getId());
    assertEquals(0, A.getAttributeCount());

    // Simple attributes.

    A.addAttribute("foo");

    assertEquals(1, A.getAttributeCount());
    assertTrue(A.hasAttribute("foo"));
    assertTrue(A.hasAttribute("foo", Boolean.class));
    assertFalse(A.hasLabel("foo"));
    assertFalse(A.hasNumber("foo"));
    assertFalse(A.hasVector("foo"));
    assertFalse(A.hasArray("foo"));
    assertFalse(A.hasHash("foo"));
    assertNotNull(A.getAttribute("foo"));
    assertEquals(true, A.getAttribute("foo"));
    assertEquals(Boolean.TRUE, A.getAttribute("foo"));

    // Change.

    A.changeAttribute("foo", false);

    assertEquals(1, A.getAttributeCount());
    assertTrue(A.hasAttribute("foo"));
    assertTrue(A.hasAttribute("foo", Boolean.class));
    assertFalse(A.hasLabel("foo"));
    assertFalse(A.hasNumber("foo"));
    assertFalse(A.hasVector("foo"));
    assertFalse(A.hasArray("foo"));
    assertFalse(A.hasHash("foo"));
    assertNotNull(A.getAttribute("foo"));
    assertEquals(false, A.getAttribute("foo"));
    assertEquals(Boolean.FALSE, A.getAttribute("foo"));

    // Removal.

    A.removeAttribute("foo");
    assertEquals(0, A.getAttributeCount());
    assertFalse(A.hasAttribute("foo"));
    assertNull(A.getAttribute("foo"));
   
    // Test null attributes checking.
   
    assertFalse(graph.nullAttributesAreErrors());
    graph.setNullAttributesAreErrors(true);
    assertTrue(graph.nullAttributesAreErrors());
    A.getAttribute("foo")// NullAttributeException thrown here.
  }
View Full Code Here

  @Test
  public void testElementValueAttributes() {
    Graph graph = new MultiGraph("g1");

    Node A = graph.addNode("A");

    assertEquals("A", A.getId());
    assertEquals(0, A.getAttributeCount());

    // Label attributes.

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

    assertEquals(1, A.getAttributeCount());
    assertTrue(A.hasAttribute("foo"));
    assertTrue(A.hasAttribute("foo", String.class));
    assertTrue(A.hasLabel("foo"));
    assertFalse(A.hasNumber("foo"));
    assertFalse(A.hasVector("foo"));
    assertFalse(A.hasArray("foo"));
    assertFalse(A.hasHash("foo"));
    assertNotNull(A.getAttribute("foo"));
    assertEquals("bar", A.getAttribute("foo"));

    // Number attributes.

    A.addAttribute("pi", 3.1415);

    assertEquals(2, A.getAttributeCount());
    assertTrue(A.hasAttribute("pi"));
    assertTrue(A.hasAttribute("pi", Number.class));
    assertFalse(A.hasLabel("pi"));
    assertTrue(A.hasNumber("pi"));
    assertFalse(A.hasVector("pi"));
    assertFalse(A.hasArray("pi"));
    assertFalse(A.hasHash("pi"));
    assertNotNull(A.getAttribute("pi"));
    assertEquals(3.1415, A.getAttribute("pi"));
    assertEquals(new Double(3.1415), A.getAttribute("pi"));

    A.setAttribute("pi", "3.1415");
   
    assertEquals(3.1415, A.getNumber("pi"), 0);
   
    // Vector of numbers.

    ArrayList<Number> numbers = new ArrayList<Number>();

    numbers.add(3);
    numbers.add(1.4);
    numbers.add(1.5f);

    A.addAttribute("v", numbers);

    assertEquals(3, A.getAttributeCount());
    assertTrue(A.hasAttribute("v"));
    assertTrue(A.hasAttribute("v", ArrayList.class));
    assertFalse(A.hasLabel("v"));
    assertFalse(A.hasNumber("v"));
    assertTrue(A.hasVector("v"));
    assertFalse(A.hasArray("v"));
    assertFalse(A.hasHash("v"));
    assertNotNull(A.getAttribute("v"));
    assertEquals(numbers, A.getAttribute("v"));
    assertEquals(numbers, A.getVector("v"));

    // Hashes 1.

    HashMap<String, String> map = new HashMap<String, String>();

    map.put("A", "a");
    map.put("B", "b");
    map.put("C", "c");

    A.addAttribute("map", map);

    assertEquals(4, A.getAttributeCount());
    assertTrue(A.hasAttribute("map"));
    assertTrue(A.hasAttribute("map", HashMap.class));
    assertFalse(A.hasLabel("map"));
    assertFalse(A.hasNumber("map"));
    assertFalse(A.hasVector("map"));
    assertFalse(A.hasArray("map"));
    assertTrue(A.hasHash("map"));
    assertNotNull(A.getAttribute("map"));
    assertEquals(map, A.getAttribute("map"));
    assertEquals(map, A.getHash("map"));

    // Hashes 2.

    MyAttribute attr = new MyAttribute();

    attr.put("A", "a");
    attr.put("B", "b");
    attr.put("C", "c");

    A.addAttribute("ca", attr);

    assertEquals(5, A.getAttributeCount());
    assertTrue(A.hasAttribute("ca"));
    assertTrue(A.hasAttribute("ca", MyAttribute.class));
    assertFalse(A.hasLabel("ca"));
    assertFalse(A.hasNumber("ca"));
    assertFalse(A.hasVector("ca"));
    assertFalse(A.hasArray("ca"));
    assertTrue(A.hasHash("ca"));
    assertNotNull(A.getAttribute("ca"));
    assertEquals(attr, A.getAttribute("ca"));
    assertEquals(attr, A.getHash("ca"));

    // Clear

    A.clearAttributes();

    assertEquals(0, A.getAttributeCount());
  }
View Full Code Here

      sink.register("//localhost/" + name);
    } catch (RemoteException e) {
      fail();
    }

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

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

    A.addAttribute("int", 1);
    B.addAttribute("string", "test");
    C.addAttribute("double", 2.0);

    AB.addAttribute("points",
        (Object) (new double[][] { { 1, 1 }, { 2, 2 } }));
    LinkedList<Integer> list = new LinkedList<Integer>();
    list.add(1);
    list.add(2);
    AC.addAttribute("list", list);
    BC.addAttribute("boolean", true);

    // -----

    A = g2.getNode("A");
    B = g2.getNode("B");
    C = g2.getNode("C");

    assertNotNull(A);
    assertNotNull(B);
    assertNotNull(C);
    assertEquals(g2.getNodeCount(), 3);

    AB = g2.getEdge("AB");
    AC = g2.getEdge("AC");
    BC = g2.getEdge("BC");

    assertNotNull(AB);
    assertNotNull(AC);
    assertNotNull(BC);
    assertEquals(g2.getEdgeCount(), 3);

    assertEquals("A", AB.getNode0().getId());
    assertEquals("B", AB.getNode1().getId());
    assertEquals("A", AC.getNode0().getId());
    assertEquals("C", AC.getNode1().getId());
    assertEquals("B", BC.getNode0().getId());
    assertEquals("C", BC.getNode1().getId());
   
    assertTrue(!AB.isDirected());
    assertTrue(AC.isDirected());
    assertTrue(!BC.isDirected());
   
    assertEquals(A.getAttribute("int"), 1);
    assertEquals(B.getAttribute("string"), "test");
    assertEquals(C.getAttribute("double"), 2.0);

    try {
      double[][] points = AB.getAttribute("points");

      assertEquals(points.length, 2);
View Full Code Here

  @Test
  public void testElementMultiAttributes() {
    Graph graph = new MultiGraph("g1");

    Node A = graph.addNode("A");

    assertEquals("A", A.getId());
    assertEquals(0, A.getAttributeCount());

    // Arrays

    A.addAttribute("array", 0, 1.1, 1.3f, "foo");

    Object expected[] = { 0, 1.1, 1.3f, "foo" };

    assertEquals(1, A.getAttributeCount());
    assertTrue(A.hasAttribute("array"));
    assertTrue(A.hasAttribute("array", Object[].class));
    assertFalse(A.hasLabel("array"));
    assertFalse(A.hasNumber("array"));
    assertFalse(A.hasVector("array"));
    assertTrue(A.hasArray("array"));
    assertFalse(A.hasHash("array"));
    assertArrayEquals(expected, (Object[]) A.getAttribute("array"));
    assertArrayEquals(expected, A.getArray("array"));
    assertNotNull(A.getAttribute("array"));
  }
View Full Code Here

TOP

Related Classes of org.graphstream.graph.Node

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.