Ejemplo n.º 1
0
  private int Load_Nodes(DataInputStream inStream) {
    // need to open file and load data
    int node_id;
    int x_cor;
    int y_cor;
    // int n_nodes, n_edges, node_cnt, arrow_status;
    Node n;
    String line;
    String item1, item2, item3, item4;

    node_id = 0;
    x_cor = 0;
    y_cor = 0;
    // n_nodes = 0;
    // n_edges = 0;
    // arrow_status = -1;

    try {

      if ((line = inStream.readLine()) != null) {
        StringTokenizer Data = new StringTokenizer(line, " ");
        item1 = Data.nextToken();
        n_nodes = Integer.parseInt(item1);
        item2 = Data.nextToken();
        n_edges = Integer.parseInt(item2);
        item3 = Data.nextToken();
        arrow_status = Integer.parseInt(item3);
        // item4 = Data.nextToken();
        // type = Integer.parseInt( item4 );
        // graph = new GraphClass( n_nodes, n_edges, arrow_status );
        nodes = new Node[n_nodes];
        edges = new Edge[n_edges];

        // ???

        while ((this.Node_Cnt() < n_nodes) && ((line = inStream.readLine()) != null)) {
          Data = new StringTokenizer(line, " ");
          item1 = Data.nextToken();
          item2 = Data.nextToken();
          item3 = Data.nextToken();
          node_id = Integer.parseInt(item1);
          x_cor = Integer.parseInt(item2);
          y_cor = Integer.parseInt(item3);
          n = new Node(node_id, x_cor, y_cor);
          this.Add_Node(n);
        }
        if (n_nodes != 0) {
          source_node = nodes[0];
        }
      }
    } catch (IOException e) {
      System.err.println("error in file" + e.toString());
      System.exit(1);
    }
    return this.Node_Cnt();
  }
Ejemplo n.º 2
0
  private int Load_Edges(DataInputStream inStream, int num) {
    String line;
    String item1, item2, item3;
    int source_node;
    int dest_node;
    int value;
    int n_nodes, edge_cnt;
    // Node nodes_array[] = new Node[num]; // Wil
    Edge edge;
    n_nodes = num;
    Node nodes_array[];
    nodes_array = new Node[n_nodes];
    nodes_array = this.Node_Array(); // Wil
    edge_cnt = 0;

    try {
      while ((line = inStream.readLine()) != null) {
        StringTokenizer Data = new StringTokenizer(line, " ");
        item1 = Data.nextToken();
        item2 = Data.nextToken();
        item3 = Data.nextToken();
        source_node = Integer.parseInt(item1);
        dest_node = Integer.parseInt(item2);
        value = Integer.parseInt(item3);
        edge = new Edge(nodes_array[source_node - 1], nodes_array[dest_node - 1], value);
        this.Add_Edge(edge);
        edge_cnt++;
      }
      // inFile.close();
    } catch (IOException e) {
      System.err.println("Error in accessing URL: " + e.toString());
      System.exit(1);
    }
    return edge_cnt;
  }
Ejemplo n.º 3
0
 // --------------------------------------------------
 public void run() {
   String inputLine;
   try {
     while ((inputLine = is.readLine()) != null) {
       responseArea.appendText(inputLine + "\n");
     }
   } catch (IOException e) {
     responseArea.appendText("IO Exception" + "\n");
   }
 }