コード例 #1
0
ファイル: CSVExporterTest.java プロジェクト: jgrapht/jgrapht
  public void testDirectedMatrixNoNodeIdWeighted() {
    DirectedWeightedPseudograph<Integer, DefaultWeightedEdge> g =
        new DirectedWeightedPseudograph<>(DefaultWeightedEdge.class);
    g.addVertex(1);
    g.addVertex(2);
    g.addVertex(3);
    g.addVertex(4);
    g.addVertex(5);
    g.addEdge(1, 2);
    g.addEdge(1, 3);
    g.addEdge(3, 1);
    g.addEdge(3, 4);
    g.addEdge(4, 5);
    g.addEdge(5, 1);
    g.addEdge(5, 2);
    g.addEdge(5, 3);
    g.addEdge(5, 4);
    g.addEdge(5, 5);

    g.setEdgeWeight(g.getEdge(1, 3), 13);
    g.setEdgeWeight(g.getEdge(5, 3), 53);

    CSVExporter<Integer, DefaultWeightedEdge> exporter =
        new CSVExporter<>(nameProvider, CSVFormat.MATRIX, ';');
    exporter.setParameter(CSVFormat.Parameter.MATRIX_FORMAT_EDGE_WEIGHTS, true);
    StringWriter w = new StringWriter();
    exporter.exportGraph(g, w);
    assertEquals(DIRECTED_MATRIX_NO_NODEID_WEIGHTED, w.toString());
  }
コード例 #2
0
ファイル: CSVExporterTest.java プロジェクト: jgrapht/jgrapht
  public void testDirectedMatrixNoNodeIdZeroMissingEdges() {
    DirectedGraph<Integer, DefaultEdge> g = new DirectedPseudograph<>(DefaultEdge.class);
    g.addVertex(1);
    g.addVertex(2);
    g.addVertex(3);
    g.addVertex(4);
    g.addVertex(5);
    g.addEdge(1, 2);
    g.addEdge(1, 3);
    g.addEdge(3, 1);
    g.addEdge(3, 4);
    g.addEdge(4, 5);
    g.addEdge(5, 1);
    g.addEdge(5, 2);
    g.addEdge(5, 3);
    g.addEdge(5, 4);
    g.addEdge(5, 5);

    CSVExporter<Integer, DefaultEdge> exporter =
        new CSVExporter<>(nameProvider, CSVFormat.MATRIX, ';');
    exporter.setParameter(CSVFormat.Parameter.MATRIX_FORMAT_ZERO_WHEN_NO_EDGE, true);
    StringWriter w = new StringWriter();
    exporter.exportGraph(g, w);
    assertEquals(DIRECTED_MATRIX_NO_NODEID_ZERO_NO_EDGE, w.toString());
  }
コード例 #3
0
ファイル: CSVExporterTest.java プロジェクト: jgrapht/jgrapht
  public void testUndirectedAdjacencyList() {
    UndirectedGraph<Integer, DefaultEdge> g = new Pseudograph<>(DefaultEdge.class);
    g.addVertex(1);
    g.addVertex(2);
    g.addVertex(3);
    g.addVertex(4);
    g.addVertex(5);
    g.addEdge(1, 2);
    g.addEdge(1, 3);
    g.addEdge(3, 1);
    g.addEdge(3, 4);
    g.addEdge(4, 5);
    g.addEdge(5, 1);
    g.addEdge(5, 2);
    g.addEdge(5, 3);
    g.addEdge(5, 4);
    g.addEdge(5, 5);
    g.addEdge(5, 5);

    CSVExporter<Integer, DefaultEdge> exporter =
        new CSVExporter<>(nameProvider, CSVFormat.ADJACENCY_LIST, ';');
    StringWriter w = new StringWriter();
    exporter.exportGraph(g, w);
    assertEquals(UNDIRECTED_ADJACENCY_LIST, w.toString());
  }
コード例 #4
0
  public void testLaplacian() {
    UndirectedGraph<String, DefaultEdge> g =
        new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);
    g.addVertex(V1);
    g.addVertex(V2);
    g.addEdge(V1, V2);
    g.addVertex(V3);
    g.addEdge(V3, V1);

    StringWriter w = new StringWriter();
    exporter.exportLaplacianMatrix(w, g);
    assertEquals(LAPLACIAN, w.toString());

    w = new StringWriter();
    exporter.exportNormalizedLaplacianMatrix(w, g);
    assertEquals(NORMALIZED_LAPLACIAN, w.toString());
  }
コード例 #5
0
ファイル: GmlExporterTest.java プロジェクト: Elinow/jgrapht
  public void testUndirected() {
    UndirectedGraph<String, DefaultEdge> g =
        new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);
    g.addVertex(V1);
    g.addVertex(V2);
    g.addEdge(V1, V2);
    g.addVertex(V3);
    g.addEdge(V3, V1);

    StringWriter w = new StringWriter();
    exporter.export(w, g);
    assertEquals(UNDIRECTED, w.toString());
  }
コード例 #6
0
  public void testAdjacencyUndirected() {
    UndirectedGraph<String, DefaultEdge> g =
        new Pseudograph<String, DefaultEdge>(DefaultEdge.class);
    g.addVertex(V1);
    g.addVertex(V2);
    g.addEdge(V1, V2);
    g.addVertex(V3);
    g.addEdge(V3, V1);
    g.addEdge(V1, V1);

    StringWriter w = new StringWriter();
    exporter.exportAdjacencyMatrix(w, g);
    assertEquals(UNDIRECTED_ADJACENCY, w.toString());
  }
コード例 #7
0
ファイル: CSVExporterTest.java プロジェクト: jgrapht/jgrapht
  public void testEdgeListWithStringsDirectedUnweightedWithSemicolon() throws ImportException {
    DirectedPseudograph<String, DefaultEdge> g =
        new DirectedPseudograph<>(DefaultWeightedEdge.class);
    g.addVertex("'john doe'");
    g.addVertex("fred");
    g.addVertex("fred\n\"21\"");
    g.addVertex("who;;");
    g.addEdge("'john doe'", "fred");
    g.addEdge("fred", "fred\n\"21\"");
    g.addEdge("fred\n\"21\"", "who;;");
    g.addEdge("who;;", "'john doe'");

    CSVExporter<String, DefaultEdge> exporter =
        new CSVExporter<>(stringNameProvider, CSVFormat.EDGE_LIST, ';');
    StringWriter w = new StringWriter();
    exporter.exportGraph(g, w);
    assertEquals(DIRECTED_EDGE_LIST_ESCAPE, w.toString());
  }
コード例 #8
0
ファイル: CSVExporterTest.java プロジェクト: jgrapht/jgrapht
  public void testDirectedEdgeList() {
    DirectedGraph<Integer, DefaultEdge> g = new SimpleDirectedGraph<>(DefaultEdge.class);
    g.addVertex(1);
    g.addVertex(2);
    g.addVertex(3);
    g.addVertex(4);
    g.addVertex(5);
    g.addEdge(1, 2);
    g.addEdge(1, 3);
    g.addEdge(3, 1);
    g.addEdge(3, 4);
    g.addEdge(4, 5);
    g.addEdge(5, 1);

    CSVExporter<Integer, DefaultEdge> exporter =
        new CSVExporter<>(nameProvider, CSVFormat.EDGE_LIST, ';');
    StringWriter w = new StringWriter();
    exporter.exportGraph(g, w);
    assertEquals(DIRECTED_EDGE_LIST, w.toString());
  }