/** * It selects the best solution according to objective 0 and generates the given RB * * @return the RB with the best value for objective 0 */ private ArrayList<String> getAllSolutions() { ArrayList<String> solutions = new ArrayList<String>(); // This procedure can be updated in order to select any other desirable solution Files function = new Files(); String funcionStr = function.readFile(header + ".var"); StringTokenizer lines = new StringTokenizer(funcionStr, "\n"); while (lines.hasMoreTokens()) { StringTokenizer token = new StringTokenizer(lines.nextToken(), " "); String solutionFS = token.nextToken(); solutionFS = solutionFS.replace("\t", ""); if (solutionFS.contains("1")) { String solutionIS = token.nextToken(); solutionIS = solutionIS.replace("\t", ""); if (solutionIS.contains("1")) { solutions.add(solutionFS); // 111010110101 solutions.add(solutionIS); // 111010110101 } else { System.err.println("Skipping empty solution (FS)"); } } else { System.err.println("Skipping empty solution (FS)"); } } return solutions; }
private static void initOai(Ini ini) throws Exception { Section section = ini.get("HARVESTER"); String username = section.get("username"); String passwordFile = section.get("passwordFile"); File file = new File(passwordFile); String password = (Files.readFile(file)).trim(); authenticate(username, password); }
private static String readStartDate(String filename) { File file = new File(filename); if (!file.exists()) return getStartDateNow(); else { try { return Files.readFile(file).trim(); } catch (Exception e) { logger.warn("Error reading " + filename + " - using current time"); return getStartDateNow(); } } }
/** * Constructor of the Class Parametros * * @param nombreFileParametros is the pathname of input parameter file */ Parametros(String nombreFileParametros) { try { int i; String fichero, linea, tok; StringTokenizer lineasFile, tokens; /* read the parameter file using Files class */ fichero = Files.readFile(nombreFileParametros); fichero += "\n"; /* remove all \r characters. it is neccesary for a correst use in Windows and UNIX */ fichero = fichero.replace('\r', ' '); /* extracts the differents tokens of the file */ lineasFile = new StringTokenizer(fichero, "\n"); i = 0; while (lineasFile.hasMoreTokens()) { linea = lineasFile.nextToken(); i++; tokens = new StringTokenizer(linea, " ,\t"); if (tokens.hasMoreTokens()) { tok = tokens.nextToken(); if (tok.equalsIgnoreCase("algorithm")) nameAlgorithm = getParamString(tokens); else if (tok.equalsIgnoreCase("inputdata")) getInputFiles(tokens); else if (tok.equalsIgnoreCase("outputdata")) getOutputFiles(tokens); else if (tok.equalsIgnoreCase("seed")) seed = getParamLong(tokens); else throw new java.io.IOException("Syntax error on line " + i + ": [" + tok + "]\n"); } } } catch (java.io.FileNotFoundException e) { System.err.println(e + "Parameter file"); } catch (java.io.IOException e) { System.err.println(e + "Aborting program"); System.exit(-1); } /** show the read parameter in the standard output */ String contents = "-- Parameters echo --- \n"; contents += "Algorithm name: " + nameAlgorithm + "\n"; contents += "Input Train File: " + trainFileNameInput + "\n"; contents += "Input Test File: " + testFileNameInput + "\n"; contents += "Output Train File: " + trainFileNameOutput + "\n"; contents += "Output Test File: " + testFileNameOutput + "\n"; System.out.println(contents); }
/** * This method has to invoque for to create the report. Verify the type of problem, type partition * and paths for to create the report. Read in iterative way the files of results */ @SuppressWarnings("hiding") public void running() { String modelContents = ""; // read model if (listPathFilesExtra.size() > 0) { modelContents += "\n\n===================================\n Model generated \n===================================\n"; modelContents += Files.readFile((String) listPathFilesExtra.get(0)); } else { modelContents += "\n\nThis method does not provide information about its model.\n"; } if (experimentType == CLASSIFICATION) { String cad = ""; String cad2 = ""; // Reading from training dataset and results datasets String originalFeatures = ""; try { fr = new FileReader(pathDatasetFiles.get(0)); br = new BufferedReader(fr); // @relation ... cad = br.readLine(); while (cad != null) { try { cad = br.readLine(); if (cad.startsWith("@attribute class") == false) { StringTokenizer st = null; st = new StringTokenizer(cad); st.nextToken(); originalFeatures = originalFeatures + st.nextToken() + " "; } else break; } catch (IOException e) { e.printStackTrace(); } } } catch (IOException e) { e.printStackTrace(); } String selectedFeatures = ""; cad = ""; int contAux = 0; boolean salida = false; while (salida == false) { try { File file = new File(pathOutputFiles[contAux]); if (file.exists() == true) { fr = new FileReader(pathOutputFiles[contAux]); br = new BufferedReader(fr); // @relation ... cad = br.readLine(); while (cad != null) { try { cad = br.readLine(); if (cad.startsWith("@attribute class") == false) { StringTokenizer st = null; st = new StringTokenizer(cad); st.nextToken(); selectedFeatures = selectedFeatures + st.nextToken() + " "; } else break; } catch (IOException e) { e.printStackTrace(); } } salida = true; } else { contAux++; } } catch (IOException e) { e.printStackTrace(); } } for (int i = 0; i < ((pathOutputFiles.length) / 2); i++) { try { File file = new File(pathResultFilesTxt.get(i)); if (file.exists() == true) { fr = new FileReader(pathResultFilesTxt.get(i)); br = new BufferedReader(fr); bw.newLine(); bw.write("Partition " + (i + 1)); bw.newLine(); bw.write("================"); bw.newLine(); bw.write("Original Features:"); bw.newLine(); bw.write("------------------"); bw.newLine(); bw.write(originalFeatures); bw.newLine(); bw.newLine(); bw.write("Selected Features:"); bw.newLine(); bw.write("------------------"); bw.newLine(); bw.write(selectedFeatures); bw.newLine(); bw.newLine(); bw.write("Errors:"); bw.newLine(); bw.write("-------"); bw.newLine(); cad = ""; while (cad != null) { try { if (cad.startsWith("Error") == true) { bw.write(cad); bw.newLine(); } cad = br.readLine(); } catch (IOException e) { e.printStackTrace(); } } int init = 2 * i; int stop = 2; // Training and Testing files while (stop > 0) { int exist = 0; // result files try { file = new File(pathOutputFiles[init]); if (file.exists() == true) { exist = 1; fr = new FileReader(pathOutputFiles[init]); br = new BufferedReader(fr); } } catch (IOException e) { e.printStackTrace(); } if (exist == 1) { if (init % 2 == 0) { try { bw.newLine(); bw.write("Obtained Training Dataset"); bw.newLine(); bw.write("-------------------------"); bw.newLine(); bw.newLine(); } catch (IOException e) { e.printStackTrace(); } } else { try { bw.newLine(); bw.write("Obtained Testing Dataset"); bw.newLine(); bw.write("------------------------"); bw.newLine(); bw.newLine(); } catch (IOException e) { e.printStackTrace(); } } try { cad2 = br.readLine(); } catch (IOException e) { e.printStackTrace(); } while (cad2 != null) { try { bw.write(cad2); bw.newLine(); cad2 = br.readLine(); } catch (IOException e) { e.printStackTrace(); } } } // if exits stop--; init++; } // while } // if } catch (IOException e) { e.printStackTrace(); } } // for try { bw.write(modelContents); br.close(); bw.close(); } catch (IOException e) { e.printStackTrace(); } } else if (experimentType == REGRESSION) { } }