Example #1
0
  /**
   * printToFileWithColors - prints a specified graph as a series of colored nodes and their
   * neighbors to a file in the following manner:
   *
   * <p>0(Y) X: XX(Y) XX(Y) XX(Y) X: XX(Y) XX(Y) ....
   *
   * @param g: the graph to be printed
   */
  protected static void printToFileWithColors(Graph g, String fileName)
      throws FileNotFoundException, UnsupportedEncodingException {
    fileName = "TestFiles\\" + fileName + ".txt";
    writer = new PrintWriter(fileName, "UTF-8");

    for (int i = 0; i < g.getNumNodes(); i++) {
      if (i == 0) {
        writer.println(g.graph[i].getName() + "(" + g.graph[i].getColor() + ")");
        writer.print(g.graph[i].getName() + ": ");
        for (int j = 0; j < g.graph[i].getMetNeighbors(); j++) {
          writer.print(g.graph[i].neighbors[j] + "(" + g.graph[i].getColor() + ") ");
        }
        writer.println();
      } else if (g.graph[i].getMetNeighbors() > 1) {
        writer.print(g.graph[i].getName() + ": ");

        for (int j = 1; j < g.graph[i].getMetNeighbors(); j++) {
          writer.print(g.graph[i].neighbors[j] + "(" + g.graph[i].getColor() + ") ");
        }
        writer.println();
      }
    }
    writer.println();
    writer.close();
  }
Example #2
0
 /**
  * printListWithColors - prints a specified graph as a series of colored nodes and their neighbors
  * in the following manner:
  *
  * <p>0(Y) X: XX(Y) XX(Y) XX(Y) X: XX(Y) XX(Y) ....
  *
  * @param g: the graph to be printed
  */
 protected static void printListWithColors(Graph g) {
   System.out.println(g.graph[0].getName() + "(" + g.graph[0].getColor() + ")");
   for (int i = 0; i < g.getNumNodes(); i++) {
     if (g.graph[i].getMetNeighbors() > 1) {
       System.out.print(g.graph[i].getName() + ": ");
       for (int j = 1; j < g.graph[i].getMetNeighbors(); j++) {
         System.out.print(
             g.graph[i].neighbors[j] + "(" + g.graph[g.graph[i].neighbors[j]].getColor() + ") ");
       }
     } else if ((g.graph[i].getMetNeighbors() == 1)
         && (i != (g.getNumNodes() - 1))
         && (i < g.graph[i].neighbors[0])) {
       System.out.print(g.graph[i].getName() + ": ");
       for (int j = 0; j < g.graph[i].getMetNeighbors(); j++) {
         System.out.print(
             g.graph[i].neighbors[j] + "(" + g.graph[g.graph[i].neighbors[j]].getColor() + ") ");
       }
     }
     System.out.println();
   }
   System.out.println();
 }
Example #3
0
  protected static void printList_leadZero(Graph g) {
    for (int i = 0; i < g.getNumNodes(); i++) {
      if (g.graph[i].getMetNeighbors() > 1) {
        System.out.print(g.graph[i].getName() + ": ");

        for (int j = 1; j < g.graph[i].getMetNeighbors(); j++) {
          System.out.print(g.graph[i].neighbors[j] + " ");
        }
        System.out.println();
      }
    }
    System.out.println();
  }
Example #4
0
 /**
  * printListWithColors_ZeroFirst - prints a specified graph as a series of colored nodes and their
  * neighbors in the following manner suitable for NON-SPINE GRAPHS:
  *
  * <p>0(Y) X: XX(Y) XX(Y) XX(Y) X: XX(Y) XX(Y) ....
  *
  * @param g: the graph to be printed
  */
 protected static void printListWithColors_ZeroFirst(Graph g) {
   System.out.println(g.graph[0].getName() + "(" + g.graph[0].getColor() + ")");
   for (int i = 0; i < g.getNumNodes(); i++) {
     if (g.graph[i].getMetNeighbors() > 1) {
       System.out.print(g.graph[i].getName() + ": ");
       if (g.graph[i].neighbors[0] == 0) {
         for (int j = 1; j < g.graph[i].getMetNeighbors(); j++) {
           System.out.print(
               g.graph[i].neighbors[j] + "(" + g.graph[g.graph[i].neighbors[j]].getColor() + ") ");
         }
       } else
         for (int j = 0; j < g.graph[i].getMetNeighbors(); j++) {
           System.out.print(
               g.graph[i].neighbors[j] + "(" + g.graph[g.graph[i].neighbors[j]].getColor() + ") ");
         }
       System.out.println();
     }
   }
   System.out.println();
 }