/** * 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; }
/** * 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); }
/** * Reads the parameters of the algorithm. * * @param script Configuration script */ @Override protected void readParameters(String script) { String file; String line; StringTokenizer fileLines, tokens; file = Files.readFile(script); fileLines = new StringTokenizer(file, "\n\r"); // Discard in/out files definition fileLines.nextToken(); fileLines.nextToken(); fileLines.nextToken(); // Getting the seed line = fileLines.nextToken(); tokens = new StringTokenizer(line, "="); tokens.nextToken(); seed = Long.parseLong(tokens.nextToken().substring(1)); // Getting the K parameter line = fileLines.nextToken(); tokens = new StringTokenizer(line, "="); tokens.nextToken(); K = Integer.parseInt(tokens.nextToken().substring(1)); // Getting the M parameter line = fileLines.nextToken(); tokens = new StringTokenizer(line, "="); tokens.nextToken(); M = Double.parseDouble(tokens.nextToken().substring(1)); // Getting the Max Iterations parameter line = fileLines.nextToken(); tokens = new StringTokenizer(line, "="); tokens.nextToken(); maxIterations = Integer.parseInt(tokens.nextToken().substring(1)); // Getting the delta parameter line = fileLines.nextToken(); tokens = new StringTokenizer(line, "="); tokens.nextToken(); delta = Double.parseDouble(tokens.nextToken().substring(1)); } // end-method
/** * It obtains all the neccesary information of the parameter file<br> * First, it reads the names of the training and tests data-set files<br> * Then, it reads the output files<br> * Finally, it reads the algorithm parameters, such as the seed or the number of iterations<br> * * @param nomFichero Name of the parameter file */ private void preparaArgumentos(String nomFichero) { StringTokenizer linea, datos; String fichero = Files.readFile(nomFichero); // guardo todo el fichero como un String para procesarlo: String una_linea; linea = new StringTokenizer(fichero, "\n\r"); linea.nextToken(); // Algorithm name una_linea = linea.nextToken(); datos = new StringTokenizer(una_linea, " = \" "); datos.nextToken(); // inputData ficheroTrain = datos.nextToken(); ficheroEval = datos.nextToken(); // Validation file ficheroTest = datos.nextToken(); una_linea = linea.nextToken(); datos = new StringTokenizer(una_linea, " = \" "); datos.nextToken(); // outputData ficheroSalidatr = datos.nextToken(); ficheroSalidatst = datos.nextToken(); ficheroSalida = datos.nextToken(); una_linea = linea.nextToken(); datos = new StringTokenizer(una_linea, " = \" "); datos.nextToken(); // covered seCubre = Double.parseDouble(datos.nextToken()); una_linea = linea.nextToken(); datos = new StringTokenizer(una_linea, " = \" "); datos.nextToken(); // star size tamEstrella = Integer.parseInt(datos.nextToken()); una_linea = linea.nextToken(); datos = new StringTokenizer(una_linea, " = \" "); datos.nextToken(); // accurate String eficaciaAux = datos.nextToken(); eficacia = 0; if (eficaciaAux.compareTo("YES") == 0) { eficacia = 1; } };