diff --git a/src/eva2/EvAInfo.java b/src/eva2/EvAInfo.java index 155fef82..4fab4713 100644 --- a/src/eva2/EvAInfo.java +++ b/src/eva2/EvAInfo.java @@ -5,7 +5,7 @@ package eva2; * * --- Changelog * 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. * 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. diff --git a/src/eva2/client/ClassPreloader.java b/src/eva2/client/ClassPreloader.java new file mode 100644 index 00000000..3f5f5854 --- /dev/null +++ b/src/eva2/client/ClassPreloader.java @@ -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]); + } + } + } + +} diff --git a/src/eva2/client/EvAClient.java b/src/eva2/client/EvAClient.java index 636f3de4..8d99aef1 100644 --- a/src/eva2/client/EvAClient.java +++ b/src/eva2/client/EvAClient.java @@ -150,12 +150,16 @@ public class EvAClient implements RemoteStateListener, Serializable { public EvAClient(final String hostName) { final SplashScreen fSplashScreen = new SplashScreen(EvAInfo.splashLocation); - fSplashScreen.splash(); + // preload some classes (into system cache) in a parallel thread + preloadClasses(); + + // activate the splash screen (show later using SwingUtilities) + fSplashScreen.splash(); currentModule = null; m_ComAdapter = EvAComAdapter.getInstance(); - + SwingUtilities.invokeLater( new Runnable() { public void run(){ long startTime = System.currentTimeMillis(); @@ -170,7 +174,12 @@ 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(); + } + /** * */ @@ -660,16 +669,12 @@ public class EvAClient implements RemoteStateListener, Serializable { private void showLicense() { HtmlDemo temp = new HtmlDemo(EvAInfo.licenseFile); temp.show(); - } - + } 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); } - /** - * - */ private void selectAvailableHostToKill(String[] HostNames) { if (TRACE) System.out.println("SelectAvailableHostToKill"); if (HostNames == null || HostNames.length == 0) { @@ -686,9 +691,6 @@ public class EvAClient implements RemoteStateListener, Serializable { // m_LogPanel.statusMessage(""); } - /** - * - */ private void selectAllAvailableHostToKill(String[] HostNames) { System.out.println("SelectAllAvailableHostToKill"); if (HostNames == null || HostNames.length == 0) { @@ -730,12 +732,6 @@ public class EvAClient implements RemoteStateListener, Serializable { 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 { diff --git a/src/eva2/gui/GenericObjectEditor.java b/src/eva2/gui/GenericObjectEditor.java index 73064e26..9b22e74e 100644 --- a/src/eva2/gui/GenericObjectEditor.java +++ b/src/eva2/gui/GenericObjectEditor.java @@ -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 getClassesFromClassPath(String className) { ArrayList classes = new ArrayList(); int dotIndex = className.lastIndexOf('.'); @@ -519,7 +529,7 @@ public class GenericObjectEditor implements PropertyEditor { 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); classes.add(className); } else { diff --git a/src/eva2/server/go/problems/AbstractProblemDouble.java b/src/eva2/server/go/problems/AbstractProblemDouble.java index 88d56d66..83b90612 100644 --- a/src/eva2/server/go/problems/AbstractProblemDouble.java +++ b/src/eva2/server/go/problems/AbstractProblemDouble.java @@ -8,7 +8,7 @@ import eva2.server.go.strategies.InterfaceOptimizer; import wsi.ra.math.RNG; 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_Noise = 0; @@ -107,7 +107,7 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem * * @return a range array */ - protected double[][] makeRange() { + public double[][] makeRange() { double[][] range = new double[this.getProblemDimension()][2]; for (int i = 0; i < range.length; 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 */ 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 */ protected double getRangeUpperBound(int dim) { - return m_DefaultRange; + return getDefaultRange(); } @Override @@ -194,7 +194,7 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem * * @return value of the absolute range limit */ - public double getDefaultRange() { + protected double getDefaultRange() { return m_DefaultRange; } /** diff --git a/src/eva2/server/go/problems/F13Problem.java b/src/eva2/server/go/problems/F13Problem.java index c42ca949..e725ce1e 100644 --- a/src/eva2/server/go/problems/F13Problem.java +++ b/src/eva2/server/go/problems/F13Problem.java @@ -25,7 +25,7 @@ public class F13Problem extends F1Problem implements InterfaceMultimodalProblem return (Object) new F13Problem(this); } - protected double[][] makeRange() { + public double[][] makeRange() { double[][] range = new double[this.m_ProblemDimension][2]; for (int i = 0; i < range.length; i++) { range[i][0] = -512.03; diff --git a/src/eva2/server/go/problems/InterfaceProblemDouble.java b/src/eva2/server/go/problems/InterfaceProblemDouble.java new file mode 100644 index 00000000..7921bb93 --- /dev/null +++ b/src/eva2/server/go/problems/InterfaceProblemDouble.java @@ -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(); +} diff --git a/src/eva2/server/go/problems/MatlabProblem.java b/src/eva2/server/go/problems/MatlabProblem.java index 8c860e6f..e2dd079e 100644 --- a/src/eva2/server/go/problems/MatlabProblem.java +++ b/src/eva2/server/go/problems/MatlabProblem.java @@ -156,11 +156,11 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex return problemDimension; } - public String problemDimensionTipTex() { + public String problemDimensionTipText() { return "The dimension of the problem."; } - protected double[][] makeRange() { + public double[][] makeRange() { if (range==null) range=super.makeRange(); return range; }