Package org.graphstream.graph

Examples of org.graphstream.graph.Graph


    String id = "merge";

    for (Graph g : graphs)
      id += "-" + g.getId();

    Graph result;

    try {
      Class<? extends Graph> cls = graphs[0].getClass();
      result = cls.getConstructor(String.class).newInstance(id);
    } catch (Exception e) {
View Full Code Here


   * @param g
   *            the graph to clone
   * @return a copy of g
   */
  public static Graph clone(Graph g) {
    Graph copy;

    try {
      Class<? extends Graph> cls = g.getClass();
      copy = cls.getConstructor(String.class).newInstance(g.getId());
    } catch (Exception e) {
            logger.warning(String.format("Cannot create a graph of %s.", g.getClass().getName()));
      copy = new AdjacencyListGraph(g.getId());
    }

    copyAttributes(g, copy);

    for (int i = 0; i < g.getNodeCount(); i++) {
      Node source = g.getNode(i);
      Node target = copy.addNode(source.getId());

      copyAttributes(source, target);
    }

    for (int i = 0; i < g.getEdgeCount(); i++) {
      Edge source = g.getEdge(i);
      Edge target = copy.addEdge(source.getId(), source.getSourceNode()
          .getId(), source.getTargetNode().getId(), source
          .isDirected());

      copyAttributes(source, target);
    }
View Full Code Here

    return buffer.toString();
  }

  public static void main(String... args) {
    GraphSpells graphSpells = new GraphSpells();
    Graph g = new AdjacencyListGraph("g");

    g.addSink(graphSpells);

    g.addNode("A");
    g.addNode("B");
    g.addNode("C");
    g.stepBegins(1);
    g.getNode("A").setAttribute("test1", 100);
    g.addEdge("AB", "A", "B");
    g.addEdge("AC", "A", "C");
    g.stepBegins(2);
    g.addEdge("CB", "C", "B");
    g.removeNode("A");
    g.stepBegins(3);
    g.addNode("A");
    g.addEdge("AB", "A", "B");
    g.stepBegins(4);
    g.removeNode("C");
    g.stepBegins(5);

    System.out.println(graphSpells);
  }
View Full Code Here

  public void clearSinks() {
    pipe.clearSinks();
  }

  public static void main(String... strings) throws Exception {
    Graph g = new AdjacencyListGraph("g");
    Timeline timeline = new Timeline();
    timeline.addSink(new VerboseSink());

    timeline.begin(g);

    g.stepBegins(0.0);
    g.addNode("A");
    g.addNode("B");
    g.stepBegins(1.0);
    g.addNode("C");

    timeline.end();

    System.out.printf("############\n");
    System.out.printf("# Play :\n");
View Full Code Here

      events.add(e);
    }
  }

  public static void main(String... args) throws Exception {
    Graph g1 = new AdjacencyListGraph("g1");
    Graph g2 = new AdjacencyListGraph("g2");

    Node a1 = g1.addNode("A");
    a1.addAttribute("attr1", "test");
    a1.addAttribute("attr2", 10.0);
    a1.addAttribute("attr3", 12);

    Node a2 = g2.addNode("A");
    a2.addAttribute("attr1", "test1");
    a2.addAttribute("attr2", 10.0);
    g2.addNode("B");
    g2.addNode("C");

    GraphDiff diff = new GraphDiff(g2, g1);
    System.out.println(diff);
  }
View Full Code Here

  }

  @Test
  public void testReplay() {
    AbstractGraph g1 = new AdjacencyListGraph("g1");
    Graph g2 = new AdjacencyListGraph("g2");

    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

    new DemoLayoutAndViewer();
  }

  public DemoLayoutAndViewer() {
    boolean loop = true;
    Graph graph = new MultiGraph("test");
    Viewer viewer = new Viewer(new ThreadProxyPipe(graph));
    ProxyPipe fromViewer = viewer.newThreadProxyOnGraphicGraph();
    LinLog layout = new LinLog(false);
   
    layout.configure(a, r, true, force);

    graph.addAttribute("ui.antialias");
    graph.addAttribute("ui.stylesheet", styleSheet);
    fromViewer.addSink(graph);
    viewer.addDefaultView(true);
    graph.addSink(layout);
    layout.addAttributeSink(graph);

    FileSource dgs = GRAPH.endsWith(".gml") ? new FileSourceGML() : new FileSourceDGS();

    dgs.addSink(graph);
    try {
      dgs.begin(getClass().getResourceAsStream(GRAPH));
      for (int i = 0; i < 5000 && dgs.nextEvents(); i++) {
//        fromViewer.pump();
//        layout.compute();
//        sleep(100);
      }
      dgs.end();
    } catch (IOException e1) {
      e1.printStackTrace();
      System.exit(1);
    }
   
    System.out.println("Finished creating the graph.");

    while (loop) {
      fromViewer.pump();

      if (graph.hasAttribute("ui.viewClosed")) {
        loop = false;
      } else {
        //sleep(1000);       
        layout.compute();
        findCommunities(graph, 1.3);
View Full Code Here

    // (input).
    // We populate (or remove elements from) the input and check the output
    // to see
    // if it is a copy of the input.

    Graph output = new MultiGraph("outout");

    input.addSink(output);

    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 boolean loop = true;

  public DemoViewerColorInterpolation() {
    Graph graph = new MultiGraph("main graph");
    ViewerPipe pipe = graph.display(false).newViewerPipe();

    // graph.addAttribute( "ui.quality" );
    graph.addAttribute("ui.antialias");

    pipe.addViewerListener(this);

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

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

    A.addAttribute("xyz", 0, 1, 0);
    B.addAttribute("xyz", 1, 0, 0);
    C.addAttribute("xyz", -1, 0, 0);

    graph.addAttribute("ui.stylesheet", styleSheet);

    float color = 0;
    float dir = 0.01f;

    while (loop) {
View Full Code Here

  }
 
  public DemoAllInSwing() {
    // On est dans le thread main.
   
    Graph graph  = new MultiGraph("mg");
   
    // On demande au viewer de consid�rer que le graphe ne sera lu et modifi� que
    // dans le thread Swing.
   
    Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
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.