@Override public String toString() { return BeanInspector.toString(doubleArray); }
/** * @param prop * @param value * @return */ public static PropertyEditor findEditor(PropertyDescriptor prop, Object value) { PropertyEditor editor = null; Class pec = prop.getPropertyEditorClass(); Class type = prop.getPropertyType(); try { if (pec != null) { editor = (PropertyEditor) pec.newInstance(); } } catch (Exception e) { editor = null; } if (editor == null) { if (value != null) { // Try to unwrap primitives if (Primitives.isWrapperType(value.getClass())) { editor = PropertyEditorManager.findEditor(Primitives.unwrap(value.getClass())); } else { editor = PropertyEditorManager.findEditor(value.getClass()); } } if (editor == null && (BeanInspector.isJavaPrimitive(value.getClass()))) { Class<?> prim = BeanInspector.getBoxedType(value.getClass()); if (prim != null) { editor = PropertyEditorManager.findEditor(prim); } if (editor == null) { prim = BeanInspector.getUnboxedType(value.getClass()); if (prim != null) { editor = PropertyEditorManager.findEditor(prim); } } } if (editor == null) { editor = PropertyEditorManager.findEditor(type); } if ((editor == null) && useDefaultGOE) { if (type.isArray()) { Class<?> unwrapped = Primitives.isWrapperType(type.getComponentType()) ? Primitives.unwrap(type.getComponentType()) : type; if (unwrapped.isPrimitive()) { editor = new ArrayEditor(); } else { editor = new ObjectArrayEditor<>(unwrapped.getComponentType()); } } else if (type.isEnum()) { editor = new EnumEditor(); } else { editor = new GenericObjectEditor(); ((GenericObjectEditor) editor).setClassType(type); } } } if (editor == null) { // If it's a user-defined property we give a warning. String getterClass = prop.getReadMethod().getDeclaringClass().getName(); if (getterClass.indexOf("java.") != 0) { System.err.println( "Warning: Can't find public property editor" + " for property \"" + prop.getDisplayName() + "\" (class \"" + type.getName() + "\"). Skipping."); } } else if (editor instanceof GenericObjectEditor) { ((GenericObjectEditor) editor).setClassType(type); } return editor; }
/** * This method represents the application code that we'd like to run on a separate thread. It * simulates slowly computing a value, in this case just a string 'All Done'. It updates the * progress bar every half second to remind the user that we're still busy. */ public Object doWork() { try { this.optimizationParameters.saveInstance(); if (this.show) { this.statusField.setText("Optimizing..."); } RNG.setRandomSeed(optimizationParameters.getRandomSeed()); // opening output file... if (!this.outputFileName.equalsIgnoreCase("none")) { String name = ""; SimpleDateFormat formatter = new SimpleDateFormat("E'_'yyyy.MM.dd'_'HH.mm.ss"); String startDate = formatter.format(new Date()); name = this.outputPath + this.outputFileName + "_" + this.experimentName + "_" + startDate + ".dat"; try { this.outputFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(name))); } catch (FileNotFoundException e) { System.out.println("Could not open output file! Filename: " + name); } } else { this.outputFile = null; } // initialize problem this.optimizationParameters.getProblem().initializeProblem(); this.optimizationParameters .getOptimizer() .setProblem(this.optimizationParameters.getProblem()); // int optimizer and population // this.optimizationParameters.getOptimizer().initialize(); // initialize the log data ArrayList tmpMultiRun = new ArrayList(); this.performedRuns.add(tmpMultiRun); // something to log file // if (outputFile != null) // this.writeToFile(this.optimizationParameters.getOptimizer().getStringRepresentation()); // this.writeToFile("Here i'll write something characterizing the algorithm."); for (int j = 0; j < this.multiRuns; j++) { this.optimizationParameters .getProblem() .initializeProblem(); // in the loop as well, dynamic probs may need that (MK) this.tmpData = new ArrayList<>(); this.currentRun = j; if (this.show) { this.statusField.setText( "Optimizing Run " + (j + 1) + " of " + this.multiRuns + " Multi Runs..."); } if (Thread.interrupted()) { throw new InterruptedException(); } // write header to file this.writeToFile( " FitnessCalls\t Best\t Mean\t Worst \t" + BeanInspector.toString( this.optimizationParameters.getProblem().getAdditionalDataHeader(), '\t', false, "")); if ((this.continueFlag) && (this.backupPopulation != null)) { this.recentFunctionCalls += this.backupPopulation.getFunctionCalls(); this.optimizationParameters.getOptimizer().getProblem().initializeProblem(); this.optimizationParameters.getOptimizer().addPopulationChangedEventListener(null); this.optimizationParameters.getOptimizer().setPopulation(this.backupPopulation); this.optimizationParameters .getOptimizer() .getProblem() .evaluate(this.optimizationParameters.getOptimizer().getPopulation()); this.optimizationParameters .getOptimizer() .getProblem() .evaluate(this.optimizationParameters.getOptimizer().getPopulation().getArchive()); this.optimizationParameters .getOptimizer() .initializeByPopulation(this.backupPopulation, false); this.optimizationParameters.getOptimizer().getPopulation().setFunctionCalls(0); this.optimizationParameters.addPopulationChangedEventListener(this); } else { this.recentFunctionCalls = 0; this.optimizationParameters.getOptimizer().initialize(); } // while (this.optimizationParameters.getOptimizer().getPopulation().getFunctionCalls() < // this.functionCalls) { while (!this.optimizationParameters .getTerminator() .isTerminated(this.optimizationParameters.getOptimizer().getPopulation())) { // System.out.println("Simulated Function calls "+ // this.optimizer.getPopulation().getFunctionCalls()); if (Thread.interrupted()) { throw new InterruptedException(); } optimizationParameters.getOptimizer().optimize(); } System.gc(); // @TODO if you want the final report include this // this.writeToFile(this.optimizationParameters.getProblem().getStringRepresentationForProblem(this.optimizationParameters.getOptimizer())); tmpMultiRun.add(this.tmpData); } if (this.show) { this.plot.setInfoString(this.currentExperiment, this.experimentName, 0.5f); } if (this.show) { this.draw(); } this.experimentName = this.optimizationParameters.getOptimizer().getName() + "-" + this.performedRuns.size(); } catch (InterruptedException e) { updateStatus(0); if (this.show) { this.statusField.setText("Interrupted..."); } return "Interrupted"; } if (this.outputFile != null) { try { this.outputFile.close(); } catch (IOException e) { System.out.println("Failed to close output file!"); } } if (this.show) { for (int i = 0; i < this.multiRuns; i++) { this.plot.clearGraph(1000 + i); } } updateStatus(0); if (this.show) { this.statusField.setText("Finished..."); } return "All Done"; }