示例#1
0
  static void graphsToFile(List<Triplet<FooGraph, List<Integer>, FooGraph>> l, String name) {
    try {
      PrintWriter writer = new PrintWriter(name, "UTF-8");
      writer.println("graph G {");
      int offset = 0;
      for (Triplet<FooGraph, List<Integer>, FooGraph> t : l) {
        FooGraph g = t.getValue0();
        List<Integer> markedNodes = t.getValue1();
        FooGraph markedEdges = t.getValue2();

        for (int i = 0; i < g.numVertices(); i++) {
          String vertex = "" + (offset + i);
          if (markedNodes != null && markedNodes.contains(i)) {
            vertex += " [fillcolor = red, style=filled]";
          }
          writer.println(vertex);
        }
        for (int i = 0; i < g.numVertices(); i++) {
          for (int j = i + 1; j < g.numVertices(); j++) {
            if (g.adj[i][j]) {
              String edge = (offset + i) + " -- " + (offset + j);
              if (markedEdges != null && markedEdges.adj[i][j]) {
                edge += " [color = red, penwidth=6.0]";
              }
              writer.println(edge);
            }
          }
        }
        writer.println("");
        offset += g.numVertices();
      }
      writer.println("}");
      writer.close();

    } catch (IOException e) {
      System.err.println("Caught IOException: " + e.getMessage());
    }
  }