Package org.graphstream.graph.implementations

Examples of org.graphstream.graph.implementations.MultiGraph


      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


    testSmallFile();
  }
 
  public void testDynFile() {
    try {
      Graph graph = new MultiGraph("Dynamic !");
      FileSourceGML source = new FileSourceGML();
     
      graph.addAttribute("ui.quality");
      graph.addAttribute("ui.antialias");
      graph.display();
      source.addSink(graph);
      source.begin(TestSourceGML.class.getResourceAsStream("dynamic.gml"));
      int step = 0;
      while(source.nextStep()) {
        System.err.printf("Step %d%n", step);
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

    } catch(Exception e) {}
  }
 
  public void testBigFile() {
    try {
      Graph graph = new MultiGraph("foo");
      FileSourceGML source = new FileSourceGML();

      graph.addAttribute("ui.quality");
      graph.addAttribute("ui.antialias");
      graph.addAttribute("ui.stylesheet", "node { text-size:8; text-color: #0008; text-alignment: at-right; } edge { text-size:8; text-color: #0008; }");
      graph.display(false);
      source.addSink(graph);
      source.begin(TestSourceGML.class.getResourceAsStream("example2.sif.gml"));
      while(source.nextEvents()) {}
      source.end();
    }
View Full Code Here

      e.printStackTrace();
    }
  }
  public void testSmallFile() {
    try {
      Graph graph = new MultiGraph("foo");
      FileSourceGML source = new FileSourceGML();

      graph.addAttribute("ui.quality");
      graph.addAttribute("ui.antialias");
      //graph.addAttribute("ui.stylesheet", "node { text-size:8; text-color: #0008; text-alignment: at-right; } edge { text-size:8; text-color: #0008; }");
      graph.display();
      source.addSink(graph);
      source.begin(TestSourceGML.class.getResourceAsStream("SmallTest.gml"));
      while(source.nextEvents()) {}
      source.end();
    }
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

    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

  public static void main(String[] args) throws UnknownHostException,
      IOException, InterruptedException {
    // ----- On the receiver side -----
    //
    // - a graph that will display the received events
    Graph g = new MultiGraph("G");
    g.display();
    // - the receiver that waits for events
    NetStreamReceiver net = new NetStreamReceiver(2001);
   
    net.setUnpacker(new Base64Unpacker());
    net.setDebugOn(false);
   
    // - received events end up in the "default" pipe
    ThreadProxyPipe pipe = net.getDefaultStream();
    // - plug the pipe to the sink of the graph
    pipe.addSink(g);

    // ----- The sender side (in another thread) ------
    //
    new Thread() {

      public void run() {
        // - the original graph from which events are generated
        Graph g = new MultiGraph("G");
        // - the sender
        NetStreamSender nsc = null;
        try {
          nsc = new NetStreamSender(2001);
        } catch (UnknownHostException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
       
        nsc.setPacker(new Base64Packer());

       
        // - plug the graph to the sender so that graph events can be
        // sent automatically
        g.addSink(nsc);
        // - generate some events on the client side
        String style = "node{fill-mode:plain;fill-color:#567;size:6px;}";
        g.addAttribute("stylesheet", style);
        g.addAttribute("ui.antialias", true);
        g.addAttribute("layout.stabilization-limit", 0);
        for (int i = 0; i < 5000; i++) {
          g.addNode(i + "");
          if (i > 0) {
            g.addEdge(i + "-" + (i - 1), i + "", (i - 1) + "");
            g.addEdge(i + "--" + (i / 2), i + "", (i / 2) + "");
          }
        }
      }
    }.start();
View Full Code Here

  }

  @Test
  public void Test1_GraphToWardGraph() {
    Graph source = new MultiGraph("g1");
    Graph target = new MultiGraph("g2");

    // Start to populate the graph to test the "replay" feature of the
    // proxy.

    source.addNode("A");
    source.addNode("B");
    source.addNode("C");
    source.addEdge("AB", "A", "B");
    source.addEdge("BC", "B", "C");
    source.addEdge("CA", "C", "A");

    source.getNode("A").addAttribute("A1", "foo");
    source.getNode("A").addAttribute("A2", "foo");

    ThreadProxyPipe proxy = new ThreadProxyPipe();
    proxy.addSink(target);
    proxy.init(source, true);

    Thread other = new Thread(new AnotherThread(proxy, target) {
      public void run() {
        // The second part of the test starts
        // in this target thread.

        boolean loop = true;

        do {
          proxy.pump();

          if (target.hasAttribute("STOP!"))
            loop = false;
        } while (loop);
      }

    });
View Full Code Here

TOP

Related Classes of org.graphstream.graph.implementations.MultiGraph

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.