Minor adaptions to post-processing, BeanInspector.

This commit is contained in:
Marcel Kronfeld
2008-03-27 14:55:01 +00:00
parent ec20723dd9
commit 29b6c840ac
10 changed files with 451 additions and 150 deletions

View File

@@ -3,7 +3,6 @@ package javaeva;
import java.util.BitSet;
import java.util.Vector;
import javaeva.gui.BeanInspector;
import javaeva.server.go.IndividualInterface;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.InterfaceTerminator;
@@ -41,7 +40,6 @@ import javaeva.server.go.strategies.ParticleSwarmOptimization;
import javaeva.server.go.strategies.SimulatedAnnealing;
import javaeva.server.go.strategies.Tribes;
import javaeva.server.modules.GOParameters;
import javaeva.tools.SelectedTag;
/**
* <p>
@@ -73,49 +71,20 @@ public class OptimizerFactory {
private static InterfaceTerminator term = null;
public final static int STD_ES = 1;
public final static int CMA_ES = 2;
public final static int STD_GA = 3;
public final static int PSO = 4;
public final static int DE = 5;
public final static int TRIBES = 6;
public final static int RANDOM = 7;
public final static int HILLCL = 8;
public final static int CBN_ES = 9;
public final static int CL_HILLCL = 10;
public final static int defaultFitCalls = 10000;
public final static int randSeed = 0;
private static OptimizerRunnable lastRunnable = null;
/**
* The topologies for the PSO algorithm. Contains
* <ul>
* <li>Linear</li>
* <li>Grid</li>
* <li>Star</li>
* <li>Multi-Swarm</li>
* <li>Tree</li>
* <li>HPSO</li>
* <li>Random
* </ul>
*/
public static SelectedTag topology = new SelectedTag(
"Linear", "Grid",
"Star", "Multi-Swarm",
"Tree", "HPSO",
"Random");
/**
* Add an InterfaceTerminator to any new optimizer in a boolean combination.
* The old and the given terminator will be combined as in (TOld && TNew) if
@@ -176,19 +145,16 @@ public class OptimizerFactory {
es.setPlusStrategy(false);
// TODO improve this by adding getEAIndividual to AbstractEAIndividual?
Object maybeTemplate = BeanInspector.callIfAvailable(problem,
"getEAIndividual", null);
if ((maybeTemplate != null)
&& (maybeTemplate instanceof InterfaceESIndividual)) {
AbstractEAIndividual indyTemplate = problem.getIndividualTemplate();
if ((indyTemplate != null) && (indyTemplate instanceof InterfaceESIndividual)) {
// Set CMA operator for mutation
AbstractEAIndividual indy = (AbstractEAIndividual) maybeTemplate;
AbstractEAIndividual indy = (AbstractEAIndividual)indyTemplate;
MutateESCovarianceMartixAdaption cmaMut = new MutateESCovarianceMartixAdaption();
cmaMut.setCheckConstraints(true);
indy.setMutationOperator(cmaMut);
indy.setCrossoverOperator(new CrossoverESDefault());
} else {
System.err
.println("Error, CMA-ES is implemented for ES individuals only (requires double data types)");
System.err.println("Error, CMA-ES is implemented for ES individuals only (requires double data types)");
return null;
}
@@ -442,8 +408,7 @@ public class OptimizerFactory {
pso.setPhi1(phi1);
pso.setPhi2(phi2);
pso.setSpeedLimit(k);
topology.setSelectedTag(selectedTopology);
pso.setTopology(topology);
pso.getTopology().setSelectedTag(selectedTopology);
pso.addPopulationChangedEventListener(listener);
pso.init();
@@ -509,47 +474,43 @@ public class OptimizerFactory {
return defaultFitCalls;
}
public static OptimizerRunnable getOptRunnable(final int optType,
AbstractOptimizationProblem problem, int fitCalls, String outputFilePrefix) {
OptimizerRunnable opt = null;
///////////////////////////// constructing a default OptimizerRunnable
public static GOParameters getParams(final int optType, AbstractOptimizationProblem problem) {
switch (optType) {
case STD_ES:
opt = new OptimizerRunnable(standardES(problem), outputFilePrefix);
break;
return standardES(problem);
case CMA_ES:
opt = new OptimizerRunnable(cmaES(problem), outputFilePrefix);
break;
return cmaES(problem);
case STD_GA:
opt = new OptimizerRunnable(standardGA(problem), outputFilePrefix);
break;
return standardGA(problem);
case PSO:
opt = new OptimizerRunnable(standardPSO(problem), outputFilePrefix);
break;
return standardPSO(problem);
case DE:
opt = new OptimizerRunnable(standardDE(problem), outputFilePrefix);
break;
return standardDE(problem);
case TRIBES:
opt = new OptimizerRunnable(tribes(problem), outputFilePrefix);
break;
return tribes(problem);
case RANDOM:
opt = new OptimizerRunnable(monteCarlo(problem), outputFilePrefix);
break;
return monteCarlo(problem);
case HILLCL:
opt = new OptimizerRunnable(hillClimbing(problem), outputFilePrefix);
break;
return hillClimbing(problem);
case CBN_ES:
opt = new OptimizerRunnable(cbnES(problem), outputFilePrefix);
break;
return cbnES(problem);
case CL_HILLCL:
opt = new OptimizerRunnable(clusteringHillClimbing(problem),
outputFilePrefix);
break;
return clusteringHillClimbing(problem);
default:
System.err.println("Error: optimizer type " + optType + " is unknown!");
return null;
}
if (fitCalls != defaultFitCalls)
opt.getGOParams().setTerminator(new EvaluationTerminator(fitCalls));
}
public static OptimizerRunnable getOptRunnable(final int optType, AbstractOptimizationProblem problem, int fitCalls, String outputFilePrefix) {
OptimizerRunnable opt = null;
GOParameters params = getParams(optType, problem);
if (params != null) {
opt = new OptimizerRunnable(params, outputFilePrefix);
if (fitCalls != defaultFitCalls) opt.getGOParams().setTerminator(new EvaluationTerminator(fitCalls));
}
return opt;
}

View File

@@ -15,6 +15,7 @@ import javaeva.server.go.operators.postprocess.PostProcessParams;
import javaeva.server.go.populations.Population;
import javaeva.server.modules.GOParameters;
import javaeva.server.modules.Processor;
import javaeva.server.stat.AbstractStatistics;
import javaeva.server.stat.InterfaceTextListener;
import javaeva.server.stat.StatisticsStandalone;
@@ -37,6 +38,7 @@ public class OptimizerRunnable implements Runnable {
public OptimizerRunnable(GOParameters params, String outputFilePrefix, boolean restart) {
proc = new Processor(new StatisticsStandalone(outputFilePrefix), null, params);
((AbstractStatistics)proc.getStatistics()).setSaveParams(false);
doRestart = restart;
}
@@ -45,7 +47,9 @@ public class OptimizerRunnable implements Runnable {
}
public void setTextListener(InterfaceTextListener lsnr) {
proc.getStatistics().removeTextListener(listener);
this.listener = lsnr;
if (listener != null) proc.getStatistics().addTextListener(listener);
}
public void setDoRestart(boolean restart) {

View File

@@ -18,8 +18,12 @@ import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javaeva.tools.SelectedTag;
import javaeva.tools.Tag;
/*
* ==========================================================================*
* CLASS DECLARATION
@@ -30,7 +34,7 @@ public class BeanInspector {
// public static int step = 0;
// public static String check(String s) {
//
// s=s.replace('$','_');
// s=s.replace(';','_');
//// String ret = null;
@@ -44,10 +48,13 @@ public class BeanInspector {
// if (s.equals("[D")) return "Double_Array";
// if (s.startsWith("[D")) return s.substring(2);
// if (s.startsWith("[L")) return s.substring(2);
//
// return s;
// }
/**
* Check for equality based on bean properties of two target objects.
*/
public static boolean equalProperties(Object Target_1, Object Target_2) {
if (Target_1 == null || Target_2 == null) {
System.out.println("");
@@ -149,7 +156,7 @@ public class BeanInspector {
if (Target instanceof List) { // handle the list case
StringBuffer sbuf = new StringBuffer("[ ");
List lst = (List)Target;
List<?> lst = (List<?>)Target;
for (Object o : lst) {
sbuf.append(o.toString());
sbuf.append("; ");
@@ -292,7 +299,17 @@ public class BeanInspector {
}
}
/**
* Call a method by a given name with given arguments, if the method is available.
* Returns the return values of the call or null if it isnt found.
* This of course means that the caller is unable to distinguish between "method not found"
* and "method found and it returned null".
*
* @param obj
* @param mName
* @param args
* @return the return value of the called method or null
*/
public static Object callIfAvailable(Object obj, String mName, Object[] args) {
Method meth = hasMethod(obj, mName);
if (meth != null) {
@@ -305,13 +322,317 @@ public class BeanInspector {
} else return null;
}
/**
* Check whether an object has a method by the given name. Return
* it if found, or null if not.
*
* @param obj
* @param mName the method name
* @return the method or null if it isn't found
*/
public static Method hasMethod(Object obj, String mName) {
Class cls = obj.getClass();
Class<?> cls = obj.getClass();
Method[] meths = cls.getMethods();
for (Method method : meths) {
if (method.getName().equals(mName)) return method;
}
return null;
}
}
/**
* Just concatenates getClassDescription(obj) and getMemberDescriptions(obj, withValues).
*
* @param obj target object
* @param withValues if true, member values are displayed as well
* @return an info string about class and members of the given object
*/
public static String getDescription(Object obj, boolean withValues) {
StringBuffer sbuf = new StringBuffer(getClassDescription(obj));
sbuf.append("\n");
String[] mems = getMemberDescriptions(obj, withValues);
for (String str : mems) {
sbuf.append(str);
}
return sbuf.toString();
}
/**
* Check for info methods on the object to be provided by the developer
* and return their text as String.
*
* @param obj
* @return String information about the object's class
*/
public static String getClassDescription(Object obj) {
StringBuffer infoBf = new StringBuffer("Type: ");
infoBf.append(obj.getClass().getName());
infoBf.append("\t");
Object args[] = { };
Object ret;
for (String meth : new String[]{"getName", "globalInfo"}) {
ret = callIfAvailable(obj, meth, args);
if (ret != null) {
infoBf.append("\t");
infoBf.append((String)ret);
}
}
return infoBf.toString();
}
/**
* Return an info string on the members of the object class, containing name, type, optional
* value and tool tip text if available. The type is accompagnied by a tag "common" or "restricted",
* indicating whether the member property is normal or hidden, meaning it may have effect depending
* on settings of other members only, for instance.
*
* @param obj target object
* @param withValues if true, member values are displayed as well
* @return an info string about class and members of the given object
*/
public static String[] getMemberDescriptions(Object obj, boolean withValues) {
BeanInfo bi;
try {
bi = Introspector.getBeanInfo(obj.getClass());
} catch(IntrospectionException e) {
e.printStackTrace();
return null;
}
PropertyDescriptor[] m_Properties = bi.getPropertyDescriptors();
ArrayList<String> memberInfoList = new ArrayList<String>();
for (int i = 0; i < m_Properties.length; i++) {
if (m_Properties[i].isExpert()) continue;
String name = m_Properties[i].getDisplayName();
if (TRACE) System.out.println("PSP looking at "+ name);
Method getter = m_Properties[i].getReadMethod();
Method setter = m_Properties[i].getWriteMethod();
// Only display read/write properties.
if (getter == null || setter == null) continue;
try {
Object args[] = { };
Object value = getter.invoke(obj, args);
// Don't try to set null values:
if (value == null) {
// If it's a user-defined property we give a warning.
String getterClass = m_Properties[i].getReadMethod().getDeclaringClass().getName();
if (getterClass.indexOf("java.") != 0) System.err.println("Warning: Property \"" + name+ "\" has null initial value. Skipping.");
continue;
}
StringBuffer memberInfoBf = new StringBuffer("Member:\t");
memberInfoBf.append(name);
memberInfoBf.append("\tType: ");
if (m_Properties[i].isHidden()) {
memberInfoBf.append("restricted, ");
} else {
memberInfoBf.append("common, ");
}
String typeName = value.getClass().getName();
if (value instanceof SelectedTag) {
Tag[] tags = ((SelectedTag)value).getTags();
memberInfoBf.append("String in {");
for (int k=0; k<tags.length; k++) {
memberInfoBf.append(tags[k].getString());
if (k+1<tags.length) memberInfoBf.append(", ");
}
memberInfoBf.append("}");
} else memberInfoBf.append(typeName);
if (withValues) {
memberInfoBf.append('\t');
memberInfoBf.append("Value: \t");
memberInfoBf.append(toString(value));
}
// now look for a TipText method for this property
Method tipTextMethod = hasMethod(obj, name + "TipText");
if (tipTextMethod == null) {
memberInfoBf.append("\tNo further hint.");
} else {
memberInfoBf.append("\tHint: ");
memberInfoBf.append(toString(tipTextMethod.invoke(obj, args)));
}
memberInfoBf.append('\n');
memberInfoList.add(memberInfoBf.toString());
} catch (Exception ex) {
System.err.println("Skipping property "+name+" ; exception: " + ex.getMessage());
ex.printStackTrace();
} // end try
} // end for
return memberInfoList.toArray(new String[1]);
}
/**
* Take an object of primitive type (like int, Integer etc) and convert it to double.
*
* @param val
* @return
* @throws IllegalArgumentException
*/
public static double toDouble(Object val) throws IllegalArgumentException {
if (val instanceof Integer) return ((Integer)val).doubleValue();
else if (val instanceof Double) return ((Double)val).doubleValue();
else if (val instanceof Boolean) return (((Boolean)val) ? 1. : 0.);
else if (val instanceof Character) return ((Character)val).charValue();
else if (val instanceof Byte) return ((Byte)val).doubleValue();
else if (val instanceof Short) return ((Short)val).doubleValue();
else if (val instanceof Long) return ((Long)val).doubleValue();
else if (val instanceof Float) return ((Float)val).doubleValue();
else if (val instanceof Void) return 0;
throw new IllegalArgumentException("Illegal type, cant convert " + val.getClass() + " to double.");
}
/**
* Take a String and convert it to a destined data type using the appropriate function.
*
* @param str
* @param destType
* @return
*/
public static Object stringToPrimitive(String str, Class<?> destType) throws NumberFormatException {
if ((destType == Integer.class) || (destType == int.class)) return Integer.valueOf(str);
else if ((destType == Double.class) || (destType == double.class)) return Double.valueOf(str);
else if ((destType == Boolean.class) || (destType == boolean.class)) return Boolean.valueOf(str);
else if ((destType == Byte.class) || (destType == byte.class)) return Byte.valueOf(str);
else if ((destType == Short.class) || (destType == short.class)) return Short.valueOf(str);
else if ((destType == Long.class) || (destType == long.class)) return Long.valueOf(str);
else if ((destType == Float.class) || (destType == float.class)) return Float.valueOf(str);
else if ((destType == Character.class) || (destType == char.class)) return str.charAt(0);
else {
// if (destType == Void.class)
System.err.println("warning, value interpreted as void type");
return 0;
}
}
/**
* Take a double value and convert it to a primitive object.
*
* @param d
* @param destType
* @return
*/
public static Object doubleToPrimitive(Double d, Class<?> destType) {
if ((destType == Double.class) || (destType == double.class)) return d;
if ((destType == Integer.class) || (destType == int.class)) return new Integer(d.intValue());
else if ((destType == Boolean.class) || (destType == boolean.class)) return new Boolean(d != 0);
else if ((destType == Byte.class) || (destType == byte.class)) return new Byte(d.byteValue());
else if ((destType == Short.class) || (destType == short.class)) return new Short(d.shortValue());
else if ((destType == Long.class) || (destType == long.class)) return new Long(d.longValue());
else if ((destType == Float.class) || (destType == float.class)) return new Float(d.floatValue());
else { // this makes hardly sense...
System.err.println("warning: converting from double to character or void...");
if ((destType == Character.class) || (destType == char.class)) return new Character(d.toString().charAt(0));
else //if (destType == Void.class) return 0;
return 0;
}
}
/**
* Checks whether a type belongs to primitive (int, long, double, char etc.) or the Java encapsulations (Integer, Long etc.)
*
* @param cls
* @return
*/
public static boolean isJavaPrimitive(Class<?> cls) {
if (cls.isPrimitive()) return true;
if ((cls == Double.class) || (cls == Integer.class) || (cls == Boolean.class)
|| (cls == Byte.class) || (cls == Short.class) || (cls == Long.class) || (cls == Float.class)) return true;
return false;
}
/**
* Try to convert an object to a destination type, especially for primitive types (int, double etc.
* but also Integer, Double etc.).
*
* @param destType
* @param value
* @return
*/
public static Object decodeType(Class<?> destType, Object value) {
if (destType.isAssignableFrom(value.getClass())) {
// value is already of destType or assignable (subclass), so just return it
return value;
}
if (destType == String.class || destType == SelectedTag.class) {
if (value.getClass() == String.class) return value;
else return value.toString();
} else if (isJavaPrimitive(destType)) {
try {
if (value.getClass() == String.class) return stringToPrimitive((String)value, destType);
else {
return doubleToPrimitive(toDouble(value), destType);
}
} catch(Exception e) {
System.err.println("Error in converting type of " + value + " to " + destType.getName() + ": " + e.getMessage());
return null;
}
}
System.err.println("Error: unknown type, skipping decode " + value.getClass().getName() + " to " + destType.getName());
return value;
}
/**
* Try to set an object member to a given value.
* Returns true if successful, else false. The types are adapted as generally as possible,
* converting using the decodeType() method.
*
* @param obj
* @param mem
* @param val
* @return true if successful, else false
*/
public static boolean setMem(Object obj, String mem, Object val) {
BeanInfo bi;
try {
bi = Introspector.getBeanInfo(obj.getClass());
} catch(IntrospectionException e) {
e.printStackTrace();
return false;
}
PropertyDescriptor[] m_Properties = bi.getPropertyDescriptors();
// Method getter = null;
Method setter = null;
Class<?> type = null;
// System.err.println("looking at " + toString(obj));
for (int i = 0; i < m_Properties.length; i++) {
if (m_Properties[i].getDisplayName().equals(mem)) {
// System.err.println("looking at " + m_Properties[i].getDisplayName());
// getter = m_Properties[i].getReadMethod();
setter = m_Properties[i].getWriteMethod();
type = m_Properties[i].getPropertyType();
break;
}
}
if (setter != null) {
try {
// System.out.println("setting value...");
Object[] args = new Object[]{ decodeType(type, val) };
if (args[0] != null) {
setter.invoke(obj, args);
return true;
} else {
System.err.println("no value to set");
return false;
}
} catch (Exception e) {
System.err.println("Exception in invoking setter: "+e.getMessage());
// e.printStackTrace();
return false;
}
} else {
System.err.println("Setter method for " + mem + " not found!");
return false;
}
}
}

View File

@@ -215,8 +215,8 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
for (int i = 0; i < m_Properties.length; i++) {
// For each property do this
// Don't display hidden or expert properties.
//if (m_Properties[i].isHidden() || m_Properties[i].isExpert()) continue;
// we now display hidden properties (MK)
// if (m_Properties[i].isHidden() || m_Properties[i].isExpert()) continue;
// we now look at hidden properties, they can be shown or hidden dynamically (MK)
String name = m_Properties[i].getDisplayName();
if (TRACE) System.out.println("PSP looking at "+ name);

View File

@@ -488,53 +488,55 @@ public class PostProcess {
* a list of solutions after post processing.
*
* @param params
* @param solutions
* @param inputPop
* @param problem
* @param listener
* @return the clustered, post-processed population
*/
public static Population postProcess(InterfacePostProcessParams params, Population solutions, AbstractOptimizationProblem problem, InterfaceTextListener listener) {
public static Population postProcess(InterfacePostProcessParams params, Population inputPop, AbstractOptimizationProblem problem, InterfaceTextListener listener) {
if (params.isDoPostProcessing()) {
Population outputPop;
Population clusteredPop, outputPop;
if (params.getPostProcessClusterSigma() > 0) {
outputPop = (Population)PostProcess.clusterBest(solutions, params.getPostProcessClusterSigma(), 0, PostProcess.KEEP_LONERS, PostProcess.BEST_ONLY).clone();
if (outputPop.size() < solutions.size()) {
if (listener != null) listener.println("Initial clustering reduced population size from " + solutions.size() + " to " + outputPop.size());
clusteredPop = (Population)PostProcess.clusterBest(inputPop, params.getPostProcessClusterSigma(), 0, PostProcess.KEEP_LONERS, PostProcess.BEST_ONLY).clone();
if (clusteredPop.size() < inputPop.size()) {
if (listener != null) listener.println("Initial clustering reduced population size from " + inputPop.size() + " to " + clusteredPop.size());
} else if (listener != null) listener.println("Initial clustering yielded no size reduction.");
} else outputPop = solutions;
} else clusteredPop = inputPop;
if (params.getPostProcessSteps() > 0) {
processWithHC(outputPop, problem, params.getPostProcessSteps());
if (listener != null) listener.println("HC post processing done.");
processWithHC(clusteredPop, problem, params.getPostProcessSteps());
if (listener != null) listener.println("HC post processing: " + params.getPostProcessSteps() + " steps done.");
// some individuals may have now converged again
if (params.getPostProcessClusterSigma() > 0) {
// so if wished, cluster again.
outputPop = (Population)PostProcess.clusterBest(outputPop, params.getPostProcessClusterSigma(), 0, PostProcess.KEEP_LONERS, PostProcess.BEST_ONLY).clone();
if (outputPop.size() < solutions.size()) {
if (listener != null) listener.println("Second clustering reduced population size from " + solutions.size() + " to " + outputPop.size());
outputPop = (Population)PostProcess.clusterBest(clusteredPop, params.getPostProcessClusterSigma(), 0, PostProcess.KEEP_LONERS, PostProcess.BEST_ONLY).clone();
if (outputPop.size() < clusteredPop.size()) {
if (listener != null) listener.println("Second clustering reduced population size from " + clusteredPop.size() + " to " + outputPop.size());
} else if (listener != null) listener.println("Second clustering yielded no size reduction.");
}
}
} else outputPop = clusteredPop;
} else outputPop = clusteredPop;
double upBnd = PhenotypeMetric.norm(outputPop.getWorstEAIndividual().getFitness())*1.1;
upBnd = Math.pow(10,Math.floor(Math.log10(upBnd)+1));
double lowBnd = 0;
int[] sols = PostProcess.createFitNormHistogram(outputPop, lowBnd, upBnd, 20);
// PostProcessInterim.outputResult((AbstractOptimizationProblem)goParams.getProblem(), outputPop, 0.01, System.out, 0, 2000, 20, goParams.getPostProcessSteps());
if (outputPop.size()>1) {
if (listener != null) listener.println("measures: " + BeanInspector.toString(outputPop.getPopulationMeasures()));
if (listener != null) listener.println("solution histogram in [" + lowBnd + "," + upBnd + "]: " + BeanInspector.toString(sols));
}
//////////// multimodal data output?
if (problem instanceof InterfaceMultimodalProblemKnown) procMultiModalKnown(outputPop, (InterfaceMultimodalProblemKnown)problem, listener);
Population resPop = outputPop.getBestNIndividuals(params.getPrintNBest()); // n individuals are returned and sorted, all of them if n<=0
if (listener != null) listener.println("Best after post process:" + ((outputPop.size()>resPop.size()) ? ( "(first " + resPop.size() + " of " + outputPop.size() + ")") : ""));
Population nBestPop = outputPop.getBestNIndividuals(params.getPrintNBest()); // n individuals are returned and sorted, all of them if n<=0
if (listener != null) listener.println("Best after post process:" + ((outputPop.size()>nBestPop.size()) ? ( "(first " + nBestPop.size() + " of " + outputPop.size() + ")") : ""));
//////////// output some individual data
if (listener != null) for (int i=0; i<resPop.size(); i++) {
listener.println(AbstractEAIndividual.getDefaultStringRepresentation(resPop.getEAIndividual(i)));
if (listener != null) for (int i=0; i<nBestPop.size(); i++) {
listener.println(AbstractEAIndividual.getDefaultStringRepresentation(nBestPop.getEAIndividual(i)));
}
return resPop;
} else return solutions;
return nBestPop;
} else return inputPop;
}
}

View File

@@ -179,12 +179,12 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
}
/**
* This allows "anyone" to access the problem template and set operators etc.
* This allows "anyone" to access the problem's individual template and set operators etc.
* Subclasses may have a method getEAIndividual additionally with a more
* specific interface signature, which makes sense for the GUI which decides
* on what classes to present to the user based on the interface signature.
*
* @return
* @return the problem's individual template
*/
public AbstractEAIndividual getIndividualTemplate() {
return m_Template;

View File

@@ -169,7 +169,7 @@ public class DynJumpProblem extends AbstractDynTransProblem {
return "DynJumpProblem";
}
public String globalInfo() {
return "A real valued problem jumping";
return "A real valued problem jumping dynamically.";
}
public String severityTipText() {
@@ -182,10 +182,10 @@ public class DynJumpProblem extends AbstractDynTransProblem {
this.lambda = lambda;
}
public String lambdaTipText() {
return "direction of movement: [0,1] 0 = random, 1 = depending";
return "direction of movement: [0,1] 0 = random, 1 = dependent";
}
/**************************************************************************
* These are for debugging and determing the output file
* These are for debugging and determining the output file
*
*/

View File

@@ -333,14 +333,16 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
* @param listener
*/
public void performNewPostProcessing(PostProcessParams ppp, InterfaceTextListener listener) {
if (ppp.isDoPostProcessing()) {
ppp.hideHideable(); // a bit mean: as we may have several instances of ppp in different states, make sure Bean-"hidden" state is consistent for output.
if (listener != null) listener.println("Starting post processing... " + BeanInspector.toString(ppp));
if (listener != null) listener.println("Post processing params: " + BeanInspector.toString(ppp));
resPop = goParams.getOptimizer().getAllSolutions();
if (resPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) {
// System.err.println("bad case in Processor::performNewPostProcessing ");
// System.err.println("bad case in Processor::performNewPostProcessing ");
resPop.SetFunctionCalls(goParams.getOptimizer().getPopulation().getFunctionCalls());
}
if (!resPop.contains(m_Statistics.getBestSolution())) resPop.add(m_Statistics.getBestSolution()); // this is a minor cheat but guarantees that the best solution ever found is contained in the final results
resPop = PostProcess.postProcess(ppp, resPop, (AbstractOptimizationProblem)goParams.getProblem(), listener);
}
}
}

View File

@@ -21,6 +21,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
protected String startDate;
protected long startTime;
private boolean saveParams = true;
private boolean firstPlot = true;
protected int functionCalls;
protected int functionCallSum;
@@ -45,7 +47,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
}
public void addTextListener(InterfaceTextListener listener) {
textListeners.add(listener);
if (!textListeners.contains(listener)) textListeners.add(listener);
}
public boolean removeTextListener(InterfaceTextListener listener) {
@@ -73,6 +75,15 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
} else resultOut = null;
}
/**
* If set to true, before every run the parameters will be stored to a file.
*
* @param doSave
*/
public void setSaveParams(boolean doSave) {
saveParams = doSave;
}
public void startOptPerformed(String infoString, int runNumber) {
if (TRACE) System.out.println("AbstractStatistics.startOptPerformed " + runNumber);
if (runNumber == 0) {
@@ -80,7 +91,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
firstPlot = true;
optRunsPerformed = 0;
convergenceCnt = 0;
m_StatisticsParameter.saveInstance();
if (saveParams) m_StatisticsParameter.saveInstance();
initOutput();
bestCurrentIndividual = null;
bestIndivdualAllover = null;

View File

@@ -137,7 +137,7 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac
//System.out.println("m_FitnessMeanofALL "+m_FitnessMeanofALL);
m_FitnessMedianofALL = getMedian(m_BestFitnessAtEnd);
finalizeOutput();
// finalizeOutput();
}
}