/** * Obtains the parameters used in the execution of the algorithm and stores them in the private * variables of the class * * @param ficheroScript Name of the configuration script that indicates the parameters that are * going to be used during the execution of the algorithm */ public void leerConfiguracion(String ficheroScript) { String fichero, linea, token; StringTokenizer lineasFichero, tokens; byte line[]; int i, j; ficheroSalida = new String[2]; fichero = Fichero.leeFichero(ficheroScript); lineasFichero = new StringTokenizer(fichero, "\n\r"); lineasFichero.nextToken(); linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); token = tokens.nextToken(); /*Getting the names of the training and test files*/ line = token.getBytes(); for (i = 0; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroTraining = new String(line, i, j - i); for (i = j + 1; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroTest = new String(line, i, j - i); /*Getting the path and base name of the results files*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); token = tokens.nextToken(); /*Getting the names of output files*/ line = token.getBytes(); for (i = 0; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroSalida[0] = new String(line, i, j - i); for (i = j + 1; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroSalida[1] = new String(line, i, j - i); /*Getting the seed*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); semilla = Long.parseLong(tokens.nextToken().substring(1)); /*Getting the number of neighbors*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); k = Integer.parseInt(tokens.nextToken().substring(1)); }
protected static void escribeSalida( String nombreFichero, String instanciasIN[], String instanciasOUT[], Attribute entradas[], Attribute salida, int nEntradas, String relation) { String cadena = ""; int i, j, k; int aux; /* Printing input attributes */ cadena += "@relation " + relation + "\n"; for (i = 0; i < nEntradas; i++) { cadena += "@attribute " + entradas[i].getName() + " "; if (entradas[i].getType() == Attribute.NOMINAL) { cadena += "{"; for (j = 0; j < entradas[i].getNominalValuesList().size(); j++) { cadena += (String) entradas[i].getNominalValuesList().elementAt(j); if (j < entradas[i].getNominalValuesList().size() - 1) { cadena += ", "; } } cadena += "}\n"; } else { if (entradas[i].getType() == Attribute.INTEGER) { cadena += "integer"; cadena += " [" + String.valueOf((int) entradas[i].getMinAttribute()) + ", " + String.valueOf((int) entradas[i].getMaxAttribute()) + "]\n"; } else { cadena += "real"; cadena += " [" + String.valueOf(entradas[i].getMinAttribute()) + ", " + String.valueOf(entradas[i].getMaxAttribute()) + "]\n"; } } } /* Printing output attribute */ cadena += "@attribute " + salida.getName() + " "; if (salida.getType() == Attribute.NOMINAL) { cadena += "{"; for (j = 0; j < salida.getNominalValuesList().size(); j++) { cadena += (String) salida.getNominalValuesList().elementAt(j); if (j < salida.getNominalValuesList().size() - 1) { cadena += ", "; } } cadena += "}\n"; } else { cadena += "integer [" + String.valueOf((int) salida.getMinAttribute()) + ", " + String.valueOf((int) salida.getMaxAttribute()) + "]\n"; } /* Printing the data */ cadena += "@data\n"; Fichero.escribeFichero(nombreFichero, cadena); cadena = ""; for (i = 0; i < instanciasIN.length; i++) { cadena += instanciasIN[i] + " " + instanciasOUT[i]; cadena += "\n"; } Fichero.AnadirtoFichero(nombreFichero, cadena); }
/** * Reads configuration script, and extracts its contents. * * @param ficheroScript Name of the configuration script */ public void leerConfiguracion(String ficheroScript) { String fichero, linea, token; StringTokenizer lineasFichero, tokens; byte line[]; int i, j; ficheroSalida = new String[2]; fichero = Fichero.leeFichero(ficheroScript); lineasFichero = new StringTokenizer(fichero, "\n\r"); lineasFichero.nextToken(); linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); token = tokens.nextToken(); /*Getting the names of training and test files*/ line = token.getBytes(); for (i = 0; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroTraining = new String(line, i, j - i); for (i = j + 1; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroTest = new String(line, i, j - i); /*Getting the path and base name of the results files*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); token = tokens.nextToken(); /*Getting the names of output files*/ line = token.getBytes(); for (i = 0; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroSalida[0] = new String(line, i, j - i); for (i = j + 1; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroSalida[1] = new String(line, i, j - i); /*Getting the seed*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); semilla = Long.parseLong(tokens.nextToken().substring(1)); /*Getting the mutation and cross probability*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); pMutacion1to0 = Double.parseDouble(tokens.nextToken().substring(1)); linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); pMutacion0to1 = Double.parseDouble(tokens.nextToken().substring(1)); linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); pCruce = Double.parseDouble(tokens.nextToken().substring(1)); /*Getting the size of the population and number of evaluations*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); tamPoblacion = Integer.parseInt(tokens.nextToken().substring(1)); linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); nEval = Integer.parseInt(tokens.nextToken().substring(1)); /*Getting the alfa equilibrate factor*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); alfa = Double.parseDouble(tokens.nextToken().substring(1)); /*Getting the type of selection*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); token = tokens.nextToken(); token = token.substring(1); if (token.equalsIgnoreCase("binary_tournament")) torneo = true; else torneo = false; linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); kNeigh = Integer.parseInt(tokens.nextToken().substring(1)); /*Getting the type of distance function*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); distanceEu = tokens.nextToken().substring(1).equalsIgnoreCase("Euclidean") ? true : false; } // end-method
public void leerConfiguracion(String ficheroScript) { String fichero, linea, token; StringTokenizer lineasFichero, tokens; byte line[]; int i, j; ficheroSalida = new String[2]; fichero = Fichero.leeFichero(ficheroScript); lineasFichero = new StringTokenizer(fichero, "\n\r"); lineasFichero.nextToken(); linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); token = tokens.nextToken(); /*Getting the names of the training and test files*/ line = token.getBytes(); for (i = 0; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroTraining = new String(line, i, j - i); for (i = j + 1; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroTest = new String(line, i, j - i); /*Getting the path and base name of the results files*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); token = tokens.nextToken(); /*Getting the names of output files*/ line = token.getBytes(); for (i = 0; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroSalida[0] = new String(line, i, j - i); for (i = j + 1; line[i] != '\"'; i++) ; i++; for (j = i; line[j] != '\"'; j++) ; ficheroSalida[1] = new String(line, i, j - i); /*Getting the number of neighbours*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); k = Integer.parseInt(tokens.nextToken().substring(1)); /*Getting the k' */ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); k2 = Integer.parseInt(tokens.nextToken().substring(1)); /*Getting the type of distance function*/ linea = lineasFichero.nextToken(); tokens = new StringTokenizer(linea, "="); tokens.nextToken(); distanceEu = tokens.nextToken().substring(1).equalsIgnoreCase("Euclidean") ? true : false; }