Merging mk rev 140:141 (preloader thread, InterfaceProblemDouble)

This commit is contained in:
Marcel Kronfeld 2008-08-07 14:32:27 +00:00
parent 72c83a3c77
commit 93fdeff913
8 changed files with 98 additions and 27 deletions

View File

@ -5,7 +5,7 @@ package eva2;
* *
* --- Changelog * --- Changelog
* 2.029: Tuned the 2d-graphs which now paints quicker and changes size depending on the * 2.029: Tuned the 2d-graphs which now paints quicker and changes size depending on the
* surrounding plot window. * surrounding plot window. Added a preloader-thread to accelerate the GUI at starting time.
* 2.028: Tuned the Population to sort only when necessary on calls to getBestN... Added StatisticsDummy. * 2.028: Tuned the Population to sort only when necessary on calls to getBestN... Added StatisticsDummy.
* Slightly tuned SimpleProblemWrapper to call initProblem of simple problems if available. * Slightly tuned SimpleProblemWrapper to call initProblem of simple problems if available.
* 2.027: Renamed SetData and SetDataLamarckian from individual datatype interfaces to SetGenotype and SetPhenotype. * 2.027: Renamed SetData and SetDataLamarckian from individual datatype interfaces to SetGenotype and SetPhenotype.

View File

@ -0,0 +1,34 @@
package eva2.client;
import eva2.gui.GenericObjectEditor;
/**
* This Runnable just requests a number of classes as does the GenericObjectEditor
* so that they are loaded into the system cache. It can be done at startup time and
* accelerates later reloading.
*
* @author mkron
*
*/
public class ClassPreloader implements Runnable {
String[] clsNames = null;
private static boolean TRACE=false;
public ClassPreloader(String ... strs) {
setClassNames(strs);
}
private void setClassNames(String[] strs) {
clsNames = strs;
}
public void run() {
if (clsNames !=null) {
for (int i = 0; i < clsNames.length; i++) {
if (TRACE) System.out.println("Preloading " + clsNames[i]);
GenericObjectEditor.getClassesFromClassPath(clsNames[i]);
}
}
}
}

View File

@ -150,6 +150,10 @@ public class EvAClient implements RemoteStateListener, Serializable {
public EvAClient(final String hostName) { public EvAClient(final String hostName) {
final SplashScreen fSplashScreen = new SplashScreen(EvAInfo.splashLocation); final SplashScreen fSplashScreen = new SplashScreen(EvAInfo.splashLocation);
// preload some classes (into system cache) in a parallel thread
preloadClasses();
// activate the splash screen (show later using SwingUtilities)
fSplashScreen.splash(); fSplashScreen.splash();
currentModule = null; currentModule = null;
@ -171,6 +175,11 @@ public class EvAClient implements RemoteStateListener, Serializable {
}); });
} }
private void preloadClasses() {
ClassPreloader cp = new ClassPreloader( "eva2.server.go.strategies.InterfaceOptimizer", "eva2.server.go.problems.InterfaceOptimizationProblem", "eva2.server.go.InterfaceTerminator");
new Thread(cp).start();
}
/** /**
* *
*/ */
@ -662,14 +671,10 @@ public class EvAClient implements RemoteStateListener, Serializable {
temp.show(); temp.show();
} }
private void showNoHostFoundDialog() { private void showNoHostFoundDialog() {
JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No host with running EVASERVER found. Please start one or \nadd the correct address to the properties list.", EvAInfo.infoTitle, 1); JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No host with running EVASERVER found. Please start one or \nadd the correct address to the properties list.", EvAInfo.infoTitle, 1);
} }
/**
*
*/
private void selectAvailableHostToKill(String[] HostNames) { private void selectAvailableHostToKill(String[] HostNames) {
if (TRACE) System.out.println("SelectAvailableHostToKill"); if (TRACE) System.out.println("SelectAvailableHostToKill");
if (HostNames == null || HostNames.length == 0) { if (HostNames == null || HostNames.length == 0) {
@ -686,9 +691,6 @@ public class EvAClient implements RemoteStateListener, Serializable {
// m_LogPanel.statusMessage(""); // m_LogPanel.statusMessage("");
} }
/**
*
*/
private void selectAllAvailableHostToKill(String[] HostNames) { private void selectAllAvailableHostToKill(String[] HostNames) {
System.out.println("SelectAllAvailableHostToKill"); System.out.println("SelectAllAvailableHostToKill");
if (HostNames == null || HostNames.length == 0) { if (HostNames == null || HostNames.length == 0) {
@ -730,12 +732,6 @@ public class EvAClient implements RemoteStateListener, Serializable {
SwingUtilities.invokeLater(doSetProgressBarValue); SwingUtilities.invokeLater(doSetProgressBarValue);
} }
} }
//
// public void test(Object o) {
// System.out.println("hello from EvAClient.test!");
// System.out.println("object gives " + o);
// }
} }
final class SplashScreen extends Frame { final class SplashScreen extends Frame {

View File

@ -504,6 +504,16 @@ public class GenericObjectEditor implements PropertyEditor {
} }
} }
/**
* Return the names of all classes in the same package that are assignable
* from the named class, and that can be loaded through the classpath.
* If a class has a declared field called "hideFromGOE" this method will skip it.
* Abstract classes and interfaces will be skipped as well.
*
* @see ReflectPackage.getAssignableClassesInPackage
* @param className
* @return
*/
public static ArrayList<String> getClassesFromClassPath(String className) { public static ArrayList<String> getClassesFromClassPath(String className) {
ArrayList<String> classes = new ArrayList<String>(); ArrayList<String> classes = new ArrayList<String>();
int dotIndex = className.lastIndexOf('.'); int dotIndex = className.lastIndexOf('.');
@ -519,7 +529,7 @@ public class GenericObjectEditor implements PropertyEditor {
clsArr = null; clsArr = null;
} }
if (clsArr == null) { if (clsArr == null) {
System.out.println("Warning: No configuration property found in: " System.err.println("Warning: No configuration property found in: "
+EvAInfo.propertyFile + " "+"for "+className); +EvAInfo.propertyFile + " "+"for "+className);
classes.add(className); classes.add(className);
} else { } else {

View File

@ -8,7 +8,7 @@ import eva2.server.go.strategies.InterfaceOptimizer;
import wsi.ra.math.RNG; import wsi.ra.math.RNG;
import eva2.server.go.problems.Interface2DBorderProblem; import eva2.server.go.problems.Interface2DBorderProblem;
public abstract class AbstractProblemDouble extends AbstractOptimizationProblem implements Interface2DBorderProblem { public abstract class AbstractProblemDouble extends AbstractOptimizationProblem implements InterfaceProblemDouble, Interface2DBorderProblem {
private double m_DefaultRange = 10; private double m_DefaultRange = 10;
private double m_Noise = 0; private double m_Noise = 0;
@ -107,7 +107,7 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
* *
* @return a range array * @return a range array
*/ */
protected double[][] makeRange() { public double[][] makeRange() {
double[][] range = new double[this.getProblemDimension()][2]; double[][] range = new double[this.getProblemDimension()][2];
for (int i = 0; i < range.length; i++) { for (int i = 0; i < range.length; i++) {
range[i][0] = getRangeLowerBound(i); range[i][0] = getRangeLowerBound(i);
@ -126,7 +126,7 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
* @return the lower bound of the double range in the given dimension * @return the lower bound of the double range in the given dimension
*/ */
protected double getRangeLowerBound(int dim) { protected double getRangeLowerBound(int dim) {
return -m_DefaultRange; return -getDefaultRange();
} }
/** /**
@ -139,7 +139,7 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
* @return the upper bound of the double range in the given dimension * @return the upper bound of the double range in the given dimension
*/ */
protected double getRangeUpperBound(int dim) { protected double getRangeUpperBound(int dim) {
return m_DefaultRange; return getDefaultRange();
} }
@Override @Override
@ -194,7 +194,7 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
* *
* @return value of the absolute range limit * @return value of the absolute range limit
*/ */
public double getDefaultRange() { protected double getDefaultRange() {
return m_DefaultRange; return m_DefaultRange;
} }
/** /**

View File

@ -25,7 +25,7 @@ public class F13Problem extends F1Problem implements InterfaceMultimodalProblem
return (Object) new F13Problem(this); return (Object) new F13Problem(this);
} }
protected double[][] makeRange() { public double[][] makeRange() {
double[][] range = new double[this.m_ProblemDimension][2]; double[][] range = new double[this.m_ProblemDimension][2];
for (int i = 0; i < range.length; i++) { for (int i = 0; i < range.length; i++) {
range[i][0] = -512.03; range[i][0] = -512.03;

View File

@ -0,0 +1,31 @@
package eva2.server.go.problems;
/**
* A minimal interface for double valued problems.
*
* @author mkron
*
*/
public interface InterfaceProblemDouble {
/**
* Evaluate a double vector, representing the target function.
*
* @param x the vector to evaluate
* @return the target function value
*/
public double[] eval(double[] x);
/**
* Get the problem dimension.
*
* @return the problem dimension
*/
public int getProblemDimension();
/**
* Create a new range array by using the getRangeLowerBound and getRangeUpperBound methods.
*
* @return a range array
*/
public double[][] makeRange();
}

View File

@ -156,11 +156,11 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex
return problemDimension; return problemDimension;
} }
public String problemDimensionTipTex() { public String problemDimensionTipText() {
return "The dimension of the problem."; return "The dimension of the problem.";
} }
protected double[][] makeRange() { public double[][] makeRange() {
if (range==null) range=super.makeRange(); if (range==null) range=super.makeRange();
return range; return range;
} }