Package org.graphstream.graph

Examples of org.graphstream.graph.Graph


    }
  }

  @Test
  public void testAttributes() throws IOException {
    Graph g = getGraph("data/attributes.dgs");

    HashMap<String, Integer> map = new HashMap<String, Integer>();
    map.put("a", 1);
    map.put("b", 2);
    map.put("c", 3);
View Full Code Here


    }
  }

  @Test
  public void testElements() throws IOException {
    Graph g = getGraph("data/elements.dgs");

    Node A, B, C;
    Edge AB, AC, BC;

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

    assertEquals(g.getNodeCount(), 3);

    assertNotNull(A);
    assertNotNull(B);
    assertNotNull(C);

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

    assertEquals(g.getEdgeCount(), 3);

    assertNotNull(AB);
    assertNotNull(AC);
    assertNotNull(BC);
View Full Code Here

  @Test
  public void testEOL() throws IOException {
    String base = "DGS004%neol 0 0%n%nan A%n";
    String[] eols = { /* LF */ "\n", /* CR+LF */ "\r\n" };
    FileSourceDGS source = new FileSourceDGS();
    Graph g = new AdjacencyListGraph("eol");

    source.addSink(g);

    for (String eol : eols) {
      String dgs = base.replace("%n", eol);
      StringReader in = new StringReader(dgs);

      try {
        source.readAll(in);
        assertNotNull(g.getNode("A"));
        g.clear();
      } catch (IOException e) {
        if (e.getCause() instanceof ParseException)
          fail();
        else
          throw e;
View Full Code Here

  }

  @Test
  public void testAttributeRemoved() throws IOException {
    FileSourceDGS source = new FileSourceDGS();
    Graph g = new AdjacencyListGraph("eol");

    source.addSink(g);
    g.addSink(new TestAttributeRemoved("A", g));
    g.addSink(new VerboseSink());
   
    source.begin(getClass().getResourceAsStream("data/removeAttribute.dgs"));
   
    while (source.nextStep())
      ;
View Full Code Here

      Thread t = new Thread() {

        @Override
        public void run() {

          Graph g = new MultiGraph("G", false, true);
          NetStreamSender nsc = null;
          try {
            nsc = new NetStreamSender("localhost", 2000);
          } catch (UnknownHostException e1) {
            error(e1.toString());
            return;
          } catch (IOException e1) {
            error(e1.toString());
            return;
          }

          g.addSink(nsc);

          g.addAttribute("attribute", "foo");
          g.changeAttribute("attribute", false);
          Edge e = g.addEdge("AB", "A", "B");
          e.addAttribute("attribute", "foo");
          e.changeAttribute("attribute", false);
          Node n = e.getNode0();
          n.addAttribute("attribute", "foo");
          n.changeAttribute("attribute", false);
View Full Code Here

      e.printStackTrace();
    }
  }
 
  public void test() throws IOException {
    Graph graph = new MultiGraph("test GML");
    FileSinkGML out1 = new FileSinkGML();
    FileSinkDynamicGML out2 = new FileSinkDynamicGML();
 
    out1.begin("TestSinkGML.gml");
    out2.begin("TestSinkGML.dgml");
   
    graph.addSink(out1);
    graph.addSink(out2);
   
    graph.addNode("A");
    graph.getNode("A").addAttribute("s", "foo bar");
    graph.addNode("B");
    graph.stepBegins(1);
    graph.addEdge("AB", "A", "B", true);
    graph.getEdge("AB").addAttribute("n", 1);
    graph.stepBegins(2);
    graph.addAttribute("b", true);
    graph.getNode("B").addAttribute("c", 'X');
    graph.getNode("B").addAttribute("d", 'Y');
    graph.stepBegins(3);
    graph.getNode("B").removeAttribute("c");
    graph.removeAttribute("b");
    graph.removeNode("A");
    graph.removeNode("B");
   
    out1.end();
    out2.end();
  }
View Full Code Here

    Thread t = new Thread() {

      @Override
      public void run() {

        Graph g = new MultiGraph("G");
        NetStreamSender nsc = null;
        try {
          nsc = new NetStreamSender("localhost", 2001);
        } catch (UnknownHostException e1) {
          error(e1.toString());
          return;
        } catch (IOException e1) {
          error(e1.toString());
          return;
        }

        nsc.setPacker(new Base64Packer());

        g.addSink(nsc);

        g.addAttribute("intArray", 0, Integer.MAX_VALUE,
            Integer.MIN_VALUE);
        g.addAttribute("floatArray", 0f, Float.MAX_VALUE,
            Float.MIN_VALUE);
        g.addAttribute("doubleArray", 0.0, Double.MAX_VALUE,
            Double.MIN_VALUE);
        g.addAttribute("shortArray", (short) 0, Short.MAX_VALUE,
            Short.MIN_VALUE);
        g.addAttribute("longArray", 0L, Long.MAX_VALUE, Long.MIN_VALUE);
        g.addAttribute("byteArray", (byte) 0, Byte.MAX_VALUE,
            Byte.MIN_VALUE);
        g.addAttribute("booleanArray", true, false);
        // Object[] three = {new Short((short) 3),new Long(3L),"3"};
        // g.addAttribute("typeArray","one", 2 , three);
        g.addAttribute("int", 1);
        g.addAttribute("float", 1f);
        g.addAttribute("double", 1.0);
        g.addAttribute("short", (short) 0);
        g.addAttribute("long", 1L);
        g.addAttribute("byte", (byte) 0);
        g.addAttribute("boolean", true);
        g.addAttribute("string", "true");

        try {
          nsc.close();
        } catch (IOException e) {
          e.printStackTrace();
View Full Code Here

   */
  @Test
  public void testNetStreamMultiThreadSenders() {
    errors.clear();

    Graph g1 = new MultiGraph("G1");
    Graph g2 = new MultiGraph("G2");
    NetStreamReceiver net = null;
    try {
      net = new NetStreamReceiver("localhost", 2002, debug);
    } catch (UnknownHostException e1) {
      fail(e1.toString());
    } catch (IOException e1) {
      fail(e1.toString());
    }

    ThreadProxyPipe pipe1 = net.getStream("G1");
    ThreadProxyPipe pipe2 = net.getStream("G2");

    pipe1.addSink(g1);
    pipe2.addSink(g2);

    Thread t1 = launchClient(2002, "G1", "0");
    Thread t2 = launchClient(2002, "G1", "1");
    Thread t3 = launchClient(2002, "G2", "0");

    try {
      t1.join();
      t2.join();
      t3.join();
    } catch (InterruptedException e) {
      fail(e.getMessage());
    }

    while (pipe1.hasPostRemaining() || pipe2.hasPostRemaining()
        || net.hasActiveConnections()) {
      pipe1.pump();
      pipe2.pump();

      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
      }
    }

    if (errors.size() > 0) {
      for (String s : errors) {
        System.err.println(s);
        fail(s);
      }
    }

    assertEquals("G1", g1.getAttribute("id"));
    assertEquals("G2", g2.getAttribute("id"));
    assertEquals(180, g1.getNodeCount());
    assertEquals(90, g2.getNodeCount());

    try {
      net.quit();
      net.join();
    } catch (InterruptedException e) {
View Full Code Here

      final String prefix) {
    Thread t = new Thread() {

      @Override
      public void run() {
        Graph g = new MultiGraph(id + prefix);

        NetStreamSender nsc = null;
        try {
          nsc = new NetStreamSender(id, "localhost", port);
        } catch (UnknownHostException e1) {
          error(e1.toString());
          return;
        } catch (IOException e1) {
          error(e1.toString());
          return;
        }
        g.addSink(nsc);

        g.addAttribute("id", id);

        for (int i = 0; i < 30; i++) {
          g.addNode(prefix + i + "_1");
          g.addNode(prefix + i + "_0");
          g.addNode(prefix + i + "_2");
          try {
            Thread.sleep(1);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
View Full Code Here

   */
  @Test
  public void testNetStreamEvents() {
    errors.clear();

    final Graph g1 = new DefaultGraph("G");
    NetStreamReceiver net = null;
    try {
      net = new NetStreamReceiver("localhost", 2002, debug);
    } catch (UnknownHostException e1) {
      fail(e1.toString());
    } catch (IOException e1) {
      fail(e1.toString());
    }

    ThreadProxyPipe pipe = net.getDefaultStream();

    pipe.addSink(g1);

    g1.addSink(new Sink() {

      public void graphAttributeAdded(String sourceId, long timeId,
          String attribute, Object value) {
        assertEquals(0, value);
        assertEquals("graphAttribute", attribute);
      }

      public void graphAttributeChanged(String sourceId, long timeId,
          String attribute, Object oldValue, Object newValue) {
        assertTrue((Integer) newValue == 0 || (Integer) newValue == 1);
        assertEquals("graphAttribute", attribute);
      }

      public void graphAttributeRemoved(String sourceId, long timeId,
          String attribute) {
        assertEquals("graphAttribute", attribute);
      }

      public void nodeAttributeAdded(String sourceId, long timeId,
          String nodeId, String attribute, Object value) {
        assertEquals(0, value);
        assertEquals("nodeAttribute", attribute);
      }

      public void nodeAttributeChanged(String sourceId, long timeId,
          String nodeId, String attribute, Object oldValue,
          Object newValue) {
        assertTrue((Integer) newValue == 0 || (Integer) newValue == 1);
        assertEquals("nodeAttribute", attribute);
      }

      public void nodeAttributeRemoved(String sourceId, long timeId,
          String nodeId, String attribute) {
        assertEquals("nodeAttribute", attribute);
      }

      public void edgeAttributeAdded(String sourceId, long timeId,
          String edgeId, String attribute, Object value) {
        assertEquals(0, value);
        assertEquals("edgeAttribute", attribute);
      }

      public void edgeAttributeChanged(String sourceId, long timeId,
          String edgeId, String attribute, Object oldValue,
          Object newValue) {
        assertTrue((Integer) newValue == 0 || (Integer) newValue == 1);
        assertEquals("edgeAttribute", attribute);
      }

      public void edgeAttributeRemoved(String sourceId, long timeId,
          String edgeId, String attribute) {
        assertEquals("edgeAttribute", attribute);
      }

      public void nodeAdded(String sourceId, long timeId, String nodeId) {
        assertTrue("node0".equals(nodeId) || "node1".equals(nodeId));
      }

      public void nodeRemoved(String sourceId, long timeId, String nodeId) {
        assertTrue("node0".equals(nodeId) || "node1".equals(nodeId));
      }

      public void edgeAdded(String sourceId, long timeId, String edgeId,
          String fromNodeId, String toNodeId, boolean directed) {
        assertEquals("edge", edgeId);
        assertEquals("node0", fromNodeId);
        assertEquals("node1", toNodeId);
        assertEquals(true, directed);
      }

      public void edgeRemoved(String sourceId, long timeId, String edgeId) {
        assertEquals("edge", edgeId);
      }

      public void graphCleared(String sourceId, long timeId) {

      }

      public void stepBegins(String sourceId, long timeId, double step) {
        assertEquals(1.1, step);
      }
    });

    Thread t = new Thread() {

      @Override
      public void run() {

        Graph g = new MultiGraph("G", false, true);

        NetStreamSender nsc = null;

        try {
          nsc = new NetStreamSender("localhost", 2002);
        } catch (UnknownHostException e1) {
          error(e1.toString());
          return;
        } catch (IOException e1) {
          error(e1.toString());
          return;
        }

        g.addSink(nsc);
        Node node0 = g.addNode("node0");
        Edge edge = g.addEdge("edge", "node0", "node1", true);
        node0.addAttribute("nodeAttribute", 0);
        node0.changeAttribute("nodeAttribute", 1);
        node0.removeAttribute("nodeAttribute");
        edge.addAttribute("edgeAttribute", 0);
        edge.changeAttribute("edgeAttribute", 1);
        edge.removeAttribute("edgeAttribute");
        g.addAttribute("graphAttribute", 0);
        g.changeAttribute("graphAttribute", 1);
        g.removeAttribute("graphAttribute");
        g.stepBegins(1.1);
        g.removeEdge("edge");
        g.removeNode("node0");
        g.clear();

        try {
          nsc.close();
        } catch (IOException e1) {
        }
View Full Code Here

TOP

Related Classes of org.graphstream.graph.Graph

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.