📄 digraph.java
字号:
line = " {" + src + ", " + dst + ", " + "1.0" + ", " + "true" +"}"; } else { line = " {" + src + ", " + dst + ", " + wei +"}"; } file.print(line); start = true; } } //end for loop n } }// end for loop w break; } } if (selfloop == true) { file.println(","); } selfloop =false; // check if the vertex has any children // if (vertex.getOutDegree() > 0) { if(selfloop ==true) file.println(","); start = false; // get the vector of children // Vector children = (Vector)vertex.getChildren(); // loop over all children and write the arcs // for (int j=0; j < children.size(); j++) { // get the current child // Vertex child = (Vertex)children.elementAt(j); for(int k = 0; k < graphArc.from.size(); k++) { if((Vertex)graphArc.from.get(k) == vertex && (Vertex)graphArc.to.get(k) == child) { wei = (String)graphArc.weights.get(k); if(wei==null) wei=""+"1.0"; double tmpw; tmpw = Double.valueOf(wei).doubleValue(); if(wei.equals("0.0") || tmpw == 0.0) tmpw = -23.02585093; else tmpw = Math.log(tmpw); wei = Double.toString(tmpw); epi = (String)graphArc.epsilon.get(k); break; } } for(int p = 0; p < wordVertex.size(); p++) { SymbolTable s2 = (SymbolTable)wordVertex.elementAt(p); if(s2.nodeIndex.equals(vertex.vertexName)) { src = new String("" + p); if(child.getVertexType() == STOP) { dst = new String("T"); if (start == true) { file.println(","); } if(epi == "true") { line = " {" + src + ", " + dst + ", " + "1.0" + ", " + "true" +"}"; } else { line = " {" + src + ", " + dst + ", " + wei +"}"; } file.print(line); start = true; } for(int w = 0; w < wordVertex.size(); w++) { SymbolTable s1 = (SymbolTable)wordVertex.elementAt(w); if(s1.nodeIndex.equals(child.vertexName)) { if (start) { file.println(","); } dst = new String("" + w); if(epi == "true") { line = " {" + src + ", " + dst + ", " + "1.0" + ", " + "true" +"}"; } else { line = " {" + src + ", " + dst + ", " + wei +"}"; } file.print(line); start = true; } } // end for loop w }//end if }//end foor loop p=0 }//end for loop j=0 } } } } // method: write // // arguments: none // return : none // // writes the sof file // public void write() { // declare local variables // FileOutputStream fout = null; PrintWriter file = null; String line = null; // reset the save flag to indicate the obvious // saveWork = false; // open the selected file for writing // try { // initialize the variables // line = new String(); // initialize the file output stream // fout = new FileOutputStream(paramFile); file = new PrintWriter(fout); // write the file header // file.println(HEADER_TAG_00); file.println(HEADER_TAG_01); file.println(); // write the system configuration parameters // file.println(); // write the vertex data // for (int i=0; i < vertices.size(); i++) { // get the current vertex // Vertex vertex = (Vertex)vertices.elementAt(i); // write the data data if the vertex is a data // if ((vertex.getVertexType() == START) || (vertex.getVertexType() == STOP) || (vertex.getVertexType() == CUSTOM)) { // write the data tag // line = ALGO_TAG + " " + vertices.indexOf(vertex) + " @"; file.println(line); // write the data's location // Point point = vertex.getLocation(); file.println(LOCATION_KEY + " " + point.x + " " + point.y); // write the name tag // line = " name = " + BUFFER_TAG + ";"; file.println(line); // write the variable tag // if (vertex.getVertexType() == CUSTOM) { line = " variable = " + vertex.getVertexName() + ";"; file.println(line); } else if (vertex.getVertexType() == STOP ) { line = " variable = " + "Stop" + ";"; file.println(line); } else { line = " variable = " + "Start" + ";"; file.println(line); } // write the implementation // if (vertex.getVertexImpl() == START) { line = " type = " + START_STR + ";"; file.println(line); file.println(); } else if (vertex.getVertexImpl() == STOP) { line = " type = " + STOP_STR + ";"; file.println(line); file.println(); } else { line = " type = " + INTERNAL_STR + ";"; file.println(line); file.println(); } } } // write the algorithm data if the vertex is a algorithm // for (int i=0; i < vertices.size(); i++) { // get the current vertex // Vertex vertex = (Vertex)vertices.elementAt(i); if (vertex.getVertexType() == CONTAINER) { // write the algorithm tag // line = ALGO_TAG + " " + vertices.indexOf(vertex) + " @"; file.println(line); // write the algorithm data // writeAlgorithmData(file, vertex); file.println(); } } // write the DiGraph header // file.println(DIGRAPH_TAG + "0 @"); // indicated that we have a weighted arc // file.println(WEIGHTED_KEY); // write the vertex information // writeDiGraphVertices(file, vertices, false, -1); // write the arcs information // writeDiGraphArcs(file, vertices, false, -1); // close the file descriptor // file.close(); } // catch and deal with any file I/O exceptions // catch(IOException e1) {} } // method: writeDiGraphVertices // // arguments: // BufferedReader file: (input) file descriptor // Vector vec: (input) vector of input vertices // Boolean flag: indicating a container vertex // Boolean offset: container sof tag // return: none // // write the vertices that correspond to the digraph // public void writeDiGraphVertices(PrintWriter file, Vector vec, boolean flag, int offset) { // declare local variables // String line = null; // write the vertex tag // file.println(VERTICES_TAG); // loop over all vertices and write the vertex tags // for (int i=0; i < vec.size(); i++) { int id = i+(offset * CONT_OFFSET); if (i == vec.size() - 1) { if (flag) { line = " {" + id + ", {" + id + "}};"; } else { line = " {" + i + ", {" + i + "}};"; } } else { if (flag) { line = " {" + id + ", {" + id + "}},"; } else { line = " {" + i + ", {" + i + "}},"; } } file.println(line); } } // method: writeDiGraphArcs // // arguments: // BufferedReader file: (input) file descriptor // Vector vec: (input) vector of input vertices // Boolean flag: indicating a container vertex // Boolean offset: container sof tag // return: none // // write the arcs that correspond to the digraph // public void writeDiGraphArcs(PrintWriter file, Vector vec, boolean flag, int offset) { // declare local variables // String src = null; String dst = null; String line = null; String wei = null; String epi = null; // write the arc information // file.println(ARCS_TAG); // loop over all vertices and examine the children // boolean start = false; for (int i=0; i < vec.size(); i++) { //get the start vertex // Vertex vertex = (Vertex)vec.elementAt(i); if(vertex.getVertexType() == START) { int index = i; // check if the vertex has any children // if (vertex.getOutDegree() > 0) { // get the vector of children // Vector children = (Vector)vertex.getChildren(); // loop over all children and write the arcs // for (int j=0; j < children.size(); j++) { // get the current child // Vertex child = (Vertex)children.elementAt(j); for(int k = 0; k < graphArc.from.size(); k++) { if((Vertex)graphArc.from.get(k) == vertex && (Vertex)graphArc.to.get(k) == child) { wei = (String)graphArc.weights.get(k); if(wei==null) wei="1.0"; epi = (String)graphArc.epsilon.get(k); break; } } if (start) { file.println(","); } src = new String("" + vec.indexOf(vertex)); dst = new String("" + vec.indexOf(child)); if(epi == "true") { line = " {" + src + ", " + dst + ", " + "epi" + ", " + "true" +"}"; } else { line = " {" + src + ", " + dst + ", " + wei + ", " + "true" +"}"; } file.print(line); start = true; } } break; } } //file.println(","); writeSubDiGraphArcs(file, vec); file.println(";"); } public void writeSubDiGraphArcs(PrintWriter file, Vector vec) { // declare local variables // String src = null; String dst = null; String wei = null; String epi = null; String line = null; boolean start = false; for (int i=0; i < vec.size(); i++) { // get the current vertex // Vertex vertex = (Vertex)vec.elementAt(i); if(vertex.getVertexType() != START && vertex.getVertexType() != STOP) { file.println(","); start = false; //check if the vertex has self arc // for(int k = 0; k < graphArc.from.size(); k++) { if((Vertex)graphArc.from.get(k) == vertex && (Vertex)graphArc.to.get(k) == vertex) { wei = (String)graphArc.weights.get(k); if(wei==null) wei="1.0"; epi = (String)graphArc.epsilon.get(k); src = new String("" + i); dst = new String("" + i); if(epi == "true") { line = " {" + src + ", " + dst + ", " + "epi" + ", " + "true" +"}"; } else { line = " {" + src + ", " + dst + ", " + wei + ", " + "true" +"}"; } file.print(line); file.println(","); break; } } // check if the vertex has any children // if (vertex.getOutDegree() > 0) { // get the vector of children // Vector children = (Vector)vertex.getChildren(); // loop over all children and write the arcs // for (int j=0; j < children.size(); j++) { // get the current child // Vertex child = (Vertex)children.elementAt(j); for(int k = 0; k < graphArc.from.size(); k++) { if((Vertex)graphArc.from.get(k) == vertex && (Vertex)graphArc.to.get(k) == child) { wei = (String)graphArc.weights.get(k); if(wei==null) wei="1.0"; epi = (String)graphArc.epsilon.get(k); break; } } if (start) { file.println(","); } src = new String("" + vec.indexOf(vertex)); dst = new String("" + vec.indexOf(child)); if(epi == "true") { line = " {" + src + ", " + dst + ", " + "epi" + ", " + "true" +"}"; } else { line = " {" + src + ", " + dst + ", " + wei + ", " + "true" +"}"; } file.print(line); start = true; } } } } } // method: writeAlgorithmData // // arguments: // PrintWriter file: (input) file descriptor // Vertex vertex: (input) algorithm vertex // return: none // // write the data associated with each algorithm in the algorithm vertex // public void writeAlgorithmData(PrintWriter file, Vertex vertex) { // declare local variables // Point position = null; // store the location of the connector // position = (Point)vertex.getLocation(); // write the location of the output to file // if (position != null) { file.print(LOCATION_KEY + " " + position.x + " " + position.y); file.println(); } // write the algorithm name to the file // file.println(" name = \"" + vertex.vertexName + "\";"); // write the algorithm type to the file // if ((vertex.getType() == "Start") || (vertex.getType() == "Stop")) { file.println(" type = \"" + vertex.getType() + "\";"); } // write all other data associated with algorithm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -