Cleaning up BeanTest, nicer toString using Beans, cleaner statistics output (but not yet done)
This commit is contained in:
parent
e3f2768a29
commit
260d6e89ae
@ -5,15 +5,14 @@
|
||||
DefaultModule = Genetic_Optimization
|
||||
|
||||
## Uncomment this to show all loadable modules. Most are redundant, though.
|
||||
ShowModules
|
||||
# ShowModules
|
||||
|
||||
ServerList = localhost,134.2.172.14,ranode22
|
||||
|
||||
#################### Internals: Do not alter!
|
||||
|
||||
# base class for modules. Do not alter!
|
||||
ModulePackage = javaeva.server.modules
|
||||
|
||||
# filter class for modules. Do not alter!
|
||||
ModuleFilterClass = javaeva.server.modules.AbstractModuleAdapter
|
||||
|
||||
###################### The GO part ######################################
|
||||
# there are no further props necessary
|
278
src/javaeva/gui/BeanInspector.java
Normal file
278
src/javaeva/gui/BeanInspector.java
Normal file
@ -0,0 +1,278 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 202 $
|
||||
* $Date: 2007-10-25 16:12:49 +0200 (Thu, 25 Oct 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.beans.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/*
|
||||
* ==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
* ==========================================================================
|
||||
*/
|
||||
public class BeanInspector {
|
||||
public static boolean TRACE = false;
|
||||
|
||||
// public static int step = 0;
|
||||
// public static String check(String s) {
|
||||
//
|
||||
// s=s.replace('$','_');
|
||||
// s=s.replace(';','_');
|
||||
//// String ret = null;
|
||||
//// try {
|
||||
//// RE r = new RE("\\[");
|
||||
//// ret = r.subst(s,"");
|
||||
//// //ret.substring();
|
||||
//// //ret
|
||||
//// } catch (Exception e) {e.getMessage();};
|
||||
//// System.out.println("s="+s+" ret"+ret);
|
||||
// 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;
|
||||
// }
|
||||
|
||||
public static boolean equalProperties(Object Target_1, Object Target_2) {
|
||||
if (Target_1 == null || Target_2 == null) {
|
||||
System.out.println("");
|
||||
return false;
|
||||
}
|
||||
System.out.println("equalProperties: " + Target_1.getClass().getName() + " " + Target_2.getClass().getName());
|
||||
if (Target_1.getClass().getName().equals(Target_2.getClass().getName()) == false) {
|
||||
System.out.println("");
|
||||
return false;
|
||||
}
|
||||
// compare each of the properties !!
|
||||
BeanInfo Info_1 = null;
|
||||
BeanInfo Info_2 = null;
|
||||
PropertyDescriptor[] Properties_1 = null;
|
||||
PropertyDescriptor[] Properties_2 = null;
|
||||
try {
|
||||
|
||||
Info_1 = Introspector.getBeanInfo(Target_1.getClass());
|
||||
Info_2 = Introspector.getBeanInfo(Target_2.getClass());
|
||||
Properties_1 = Info_1.getPropertyDescriptors();
|
||||
Properties_2 = Info_2.getPropertyDescriptors();
|
||||
Info_1.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.out.println("BeanTest: Couldn't introspect !!!!!!!!!");
|
||||
return false;
|
||||
}
|
||||
boolean BeansInside = false;
|
||||
boolean BeansEqual = true;
|
||||
for (int i = 0; i < Properties_1.length; i++) {
|
||||
if (Properties_1[i].isHidden() || Properties_1[i].isExpert()) {
|
||||
continue;
|
||||
}
|
||||
//String name = Properties_1[i].getDisplayName(); //System.out.println("name = "+name );
|
||||
//Class type = Properties_1[i].getPropertyType(); //System.out.println("type = "+type.getName() );
|
||||
Method getter_1 = Properties_1[i].getReadMethod();
|
||||
Method getter_2 = Properties_2[i].getReadMethod();
|
||||
Method setter_1 = Properties_1[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter_1 == null || setter_1 == null) {
|
||||
continue;
|
||||
}
|
||||
System.out.println("getter_1 = " + getter_1.getName() + " getter_2 = " + getter_2.getName());
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Object args_1[] = {};
|
||||
Object args_2[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
try {
|
||||
Object value_1 = getter_1.invoke(Target_1, args_1);
|
||||
Object value_2 = getter_2.invoke(Target_2, args_2);
|
||||
BeansInside = true;
|
||||
if (BeanInspector.equalProperties(value_1, value_2) == false) {
|
||||
BeansEqual = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(" BeanTest.equalProperties " + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (BeansInside == true) {
|
||||
return BeansEqual;
|
||||
}
|
||||
// here we have Integer or Double ...
|
||||
if (Target_1 instanceof Integer ||
|
||||
Target_1 instanceof Boolean ||
|
||||
Target_1 instanceof Float ||
|
||||
Target_1 instanceof Double ||
|
||||
Target_1 instanceof Long ||
|
||||
Target_1 instanceof String) {
|
||||
return Target_1.equals(Target_2);
|
||||
}
|
||||
|
||||
System.out.println(" Attention no match !!!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Collect the accessible properties of an object and their values in a string.
|
||||
*
|
||||
* @param Target Description of the Parameter
|
||||
* @return Description of the Return Value
|
||||
*/
|
||||
public static String toString(Object Target) {
|
||||
String ret = "";
|
||||
// try the object itself
|
||||
if (Target instanceof String) return (String)Target; // directly return a string object
|
||||
|
||||
Class<? extends Object> type = Target.getClass();
|
||||
|
||||
if (type.isArray()) { // handle the array case
|
||||
StringBuffer sbuf = new StringBuffer("[");
|
||||
int len = Array.getLength(Target);
|
||||
for (int i=0; i<len; i++) {
|
||||
sbuf.append(toString(Array.get(Target, i)));
|
||||
if (i<len-1) sbuf.append(";");
|
||||
}
|
||||
sbuf.append("]");
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
Method[] methods = Target.getClass().getDeclaredMethods();
|
||||
for (int ii = 0; ii < methods.length; ii++) { // check if the object has its own toString method, in this case use it
|
||||
if (methods[ii].getName().equals("toString") && (methods[ii].getParameterTypes().length == 0)) {
|
||||
Object[] args = new Object[0];
|
||||
//args[0] = Target;
|
||||
try {
|
||||
ret = (String) methods[ii].invoke(Target, args);
|
||||
if (TRACE) System.out.println("toString on "+ Target.getClass() + " gave me " + ret);
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
System.err.println(" ERROR +"+ e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise try introspection and collect all public properties as strings
|
||||
BeanInfo Info = null;
|
||||
PropertyDescriptor[] Properties = null;
|
||||
// MethodDescriptor[] Methods = null;
|
||||
try {
|
||||
Info = Introspector.getBeanInfo(Target.getClass());
|
||||
Properties = Info.getPropertyDescriptors();
|
||||
Info.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.err.println("BeanTest: Couldn't introspect");
|
||||
return ret;
|
||||
}
|
||||
|
||||
StringBuffer sbuf = new StringBuffer(type.getName());
|
||||
sbuf.append("{");
|
||||
for (int i = 0; i < Properties.length; i++) {
|
||||
if (Properties[i].isHidden() || Properties[i].isExpert()) {
|
||||
continue;
|
||||
}
|
||||
String name = Properties[i].getDisplayName();
|
||||
//System.out.println("name = "+name );
|
||||
//Class type = Properties[i].getPropertyType();
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Method getter = Properties[i].getReadMethod();
|
||||
Method setter = Properties[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter == null || setter == null) {
|
||||
continue;
|
||||
}
|
||||
//System.out.println("name = "+name );
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Object args[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
|
||||
try {
|
||||
Object value = getter.invoke(Target, args);
|
||||
sbuf.append(name);
|
||||
sbuf.append("=");
|
||||
sbuf.append(toString(value));
|
||||
sbuf.append("; ");
|
||||
} catch (Exception e) {
|
||||
System.err.println("BeanTest ERROR +"+ e.getMessage());
|
||||
return sbuf.toString();
|
||||
}
|
||||
}
|
||||
sbuf.append("}");
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@param Target Description of the Parameter
|
||||
*/
|
||||
public static void showInfo(Object Target) {
|
||||
System.out.println("Inspecting " + Target.getClass().getName());
|
||||
// object itself
|
||||
try {
|
||||
if (Target instanceof java.lang.Integer) {
|
||||
System.out.println(" Prop = Integer" + Target.toString());
|
||||
}
|
||||
if (Target instanceof java.lang.Boolean) {
|
||||
System.out.println(" Prop = Boolean" + Target.toString());
|
||||
}
|
||||
if (Target instanceof java.lang.Long) {
|
||||
System.out.println(" Prop = Long" + Target.toString());
|
||||
}
|
||||
if (Target instanceof java.lang.Double) {
|
||||
System.out.println(" Prop = Long" + Target.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//System.out.println(" ERROR +"+ e.getMessage());
|
||||
}
|
||||
// then the properties
|
||||
BeanInfo Info = null;
|
||||
PropertyDescriptor[] Properties = null;
|
||||
// MethodDescriptor[] Methods = null;
|
||||
try {
|
||||
Info = Introspector.getBeanInfo(Target.getClass());
|
||||
Properties = Info.getPropertyDescriptors();
|
||||
Info.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.err.println("BeanTest: Couldn't introspect");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Properties.length; i++) {
|
||||
if (Properties[i].isHidden() || Properties[i].isExpert()) {
|
||||
continue;
|
||||
}
|
||||
String name = Properties[i].getDisplayName();
|
||||
//System.out.println("name = "+name );
|
||||
// Class type = Properties[i].getPropertyType();
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Method getter = Properties[i].getReadMethod();
|
||||
Method setter = Properties[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter == null || setter == null) {
|
||||
continue;
|
||||
}
|
||||
//System.out.println("name = "+name );
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Object args[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
try {
|
||||
Object value = getter.invoke(Target, args);
|
||||
System.out.println("Inspecting name = " + name);
|
||||
if (value instanceof Integer) {
|
||||
Object args2[] = {new Integer(999)};
|
||||
setter.invoke(Target, args2);
|
||||
}
|
||||
showInfo(value);
|
||||
} catch (Exception e) {
|
||||
System.out.println("BeanTest ERROR +" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,309 +0,0 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 202 $
|
||||
* $Date: 2007-10-25 16:12:49 +0200 (Thu, 25 Oct 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.beans.*;
|
||||
import java.lang.reflect.Method;
|
||||
//import javaeva.server.oa.es.mutation.*;
|
||||
import javaeva.tools.*;
|
||||
import javaeva.server.EvAServer;
|
||||
/*
|
||||
* ==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
* ==========================================================================
|
||||
*/
|
||||
public class BeanTest {
|
||||
public static boolean TRACE = false;
|
||||
|
||||
public static int step = 0;
|
||||
public static String check(String s) {
|
||||
|
||||
s=s.replace('$','_');
|
||||
s=s.replace(';','_');
|
||||
// String ret = null;
|
||||
// try {
|
||||
// RE r = new RE("\\[");
|
||||
// ret = r.subst(s,"");
|
||||
// //ret.substring();
|
||||
// //ret
|
||||
// } catch (Exception e) {e.getMessage();};
|
||||
// System.out.println("s="+s+" ret"+ret);
|
||||
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;
|
||||
}
|
||||
|
||||
public static boolean equalProperties(Object Target_1, Object Target_2) {
|
||||
if (Target_1 == null || Target_2 == null) {
|
||||
System.out.println("");
|
||||
return false;
|
||||
}
|
||||
System.out.println("equalProperties: " + Target_1.getClass().getName() + " " + Target_2.getClass().getName());
|
||||
if (Target_1.getClass().getName().equals(Target_2.getClass().getName()) == false) {
|
||||
System.out.println("");
|
||||
return false;
|
||||
}
|
||||
// compare each of the properties !!
|
||||
BeanInfo Info_1 = null;
|
||||
BeanInfo Info_2 = null;
|
||||
PropertyDescriptor[] Properties_1 = null;
|
||||
PropertyDescriptor[] Properties_2 = null;
|
||||
MethodDescriptor[] Methods_1 = null;
|
||||
MethodDescriptor[] Methods_2 = null;
|
||||
try {
|
||||
|
||||
Info_1 = Introspector.getBeanInfo(Target_1.getClass());
|
||||
Info_2 = Introspector.getBeanInfo(Target_2.getClass());
|
||||
Properties_1 = Info_1.getPropertyDescriptors();
|
||||
Properties_2 = Info_2.getPropertyDescriptors();
|
||||
Methods_1 = Info_1.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.out.println("BeanTest: Couldn't introspect !!!!!!!!!");
|
||||
return false;
|
||||
}
|
||||
boolean BeansInside = false;
|
||||
boolean BeansEqual = true;
|
||||
for (int i = 0; i < Properties_1.length; i++) {
|
||||
if (Properties_1[i].isHidden() || Properties_1[i].isExpert()) {
|
||||
continue;
|
||||
}
|
||||
//String name = Properties_1[i].getDisplayName(); //System.out.println("name = "+name );
|
||||
//Class type = Properties_1[i].getPropertyType(); //System.out.println("type = "+type.getName() );
|
||||
Method getter_1 = Properties_1[i].getReadMethod();
|
||||
Method getter_2 = Properties_2[i].getReadMethod();
|
||||
Method setter_1 = Properties_1[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter_1 == null || setter_1 == null) {
|
||||
continue;
|
||||
}
|
||||
System.out.println("getter_1 = " + getter_1.getName() + " getter_2 = " + getter_2.getName());
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Object args_1[] = {};
|
||||
Object args_2[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
try {
|
||||
Object value_1 = getter_1.invoke(Target_1, args_1);
|
||||
Object value_2 = getter_2.invoke(Target_2, args_2);
|
||||
BeansInside = true;
|
||||
if (BeanTest.equalProperties(value_1, value_2) == false) {
|
||||
BeansEqual = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(" BeanTest.equalProperties " + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (BeansInside == true) {
|
||||
return BeansEqual;
|
||||
}
|
||||
// here we have Integer or Double ...
|
||||
if (Target_1 instanceof Integer ||
|
||||
Target_1 instanceof Boolean ||
|
||||
Target_1 instanceof Float ||
|
||||
Target_1 instanceof Double ||
|
||||
Target_1 instanceof Long ||
|
||||
Target_1 instanceof String) {
|
||||
return Target_1.equals(Target_2);
|
||||
}
|
||||
|
||||
System.out.println(" Attention no match !!!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@param Target Description of the Parameter
|
||||
*@return Description of the Return Value
|
||||
*/
|
||||
public static String toString(Object Target) {
|
||||
String ret = "";
|
||||
// object itself
|
||||
try {
|
||||
Method[] methods = Target.getClass().getDeclaredMethods();
|
||||
for (int ii = 0; ii < methods.length; ii++) {
|
||||
if (methods[ii].getName().equals("toString") == true) {
|
||||
ret = (String) methods[ii].invoke(Target, (Object[])null);
|
||||
//System.out.println("calling to String off: "+Target.getClass().getName()+"=="+s);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//System.out.println(" ERROR +"+ e.getMessage());
|
||||
}
|
||||
// then the properties
|
||||
BeanInfo Info = null;
|
||||
PropertyDescriptor[] Properties = null;
|
||||
MethodDescriptor[] Methods = null;
|
||||
try {
|
||||
Info = Introspector.getBeanInfo(Target.getClass());
|
||||
Properties = Info.getPropertyDescriptors();
|
||||
Methods = Info.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.out.println("BeanTest: Couldn't introspect");
|
||||
return ret;
|
||||
}
|
||||
for (int i = 0; i < Methods.length; i++) {
|
||||
String name = Methods[i].getDisplayName();
|
||||
Method meth = Methods[i].getMethod();
|
||||
}
|
||||
for (int i = 0; i < Properties.length; i++) {
|
||||
if (Properties[i].isHidden() || Properties[i].isExpert()) {
|
||||
continue;
|
||||
}
|
||||
String name = Properties[i].getDisplayName();
|
||||
//System.out.println("name = "+name );
|
||||
Class type = Properties[i].getPropertyType();
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Method getter = Properties[i].getReadMethod();
|
||||
Method setter = Properties[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter == null || setter == null) {
|
||||
continue;
|
||||
}
|
||||
//System.out.println("name = "+name );
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Object args[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
|
||||
try {
|
||||
Object value = getter.invoke(Target, args);
|
||||
ret = ret + toString(value);
|
||||
} catch (Exception e) {
|
||||
//System.out.println("BeanTest ERROR +"+ e.getMessage());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@param Target Description of the Parameter
|
||||
*/
|
||||
public static void showInfo(Object Target) {
|
||||
System.out.println("Inspecting " + Target.getClass().getName());
|
||||
// object itself
|
||||
try {
|
||||
if (Target instanceof java.lang.Integer) {
|
||||
System.out.println(" Prop = Integer" + Target.toString());
|
||||
}
|
||||
if (Target instanceof java.lang.Boolean) {
|
||||
System.out.println(" Prop = Boolean" + Target.toString());
|
||||
}
|
||||
if (Target instanceof java.lang.Long) {
|
||||
System.out.println(" Prop = Long" + Target.toString());
|
||||
}
|
||||
if (Target instanceof java.lang.Double) {
|
||||
System.out.println(" Prop = Long" + Target.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//System.out.println(" ERROR +"+ e.getMessage());
|
||||
}
|
||||
// then the properties
|
||||
BeanInfo Info = null;
|
||||
PropertyDescriptor[] Properties = null;
|
||||
MethodDescriptor[] Methods = null;
|
||||
try {
|
||||
Info = Introspector.getBeanInfo(Target.getClass());
|
||||
Properties = Info.getPropertyDescriptors();
|
||||
Methods = Info.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.err.println("BeanTest: Couldn't introspect");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < Methods.length; i++) {
|
||||
String name = Methods[i].getDisplayName();
|
||||
Method meth = Methods[i].getMethod();
|
||||
}
|
||||
for (int i = 0; i < Properties.length; i++) {
|
||||
if (Properties[i].isHidden() || Properties[i].isExpert()) {
|
||||
continue;
|
||||
}
|
||||
String name = Properties[i].getDisplayName();
|
||||
//System.out.println("name = "+name );
|
||||
Class type = Properties[i].getPropertyType();
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Method getter = Properties[i].getReadMethod();
|
||||
Method setter = Properties[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter == null || setter == null) {
|
||||
continue;
|
||||
}
|
||||
//System.out.println("name = "+name );
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Object args[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
try {
|
||||
Object value = getter.invoke(Target, args);
|
||||
System.out.println("Inspecting name = " + name);
|
||||
if (value instanceof Integer) {
|
||||
Object args2[] = {new Integer(999)};
|
||||
setter.invoke(Target, args2);
|
||||
}
|
||||
showInfo(value);
|
||||
} catch (Exception e) {
|
||||
System.out.println("BeanTest ERROR +" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@param args The command line arguments
|
||||
*/
|
||||
// public static void main(String[] args) {
|
||||
// Tag t= new Tag();
|
||||
// System.out.println("name ========"+t.getClass().getName());
|
||||
// System.setProperty("java.security.policy","server.policy");
|
||||
// ESPopulation x = new ESPopulation();
|
||||
// x.add(new ESIndividual());
|
||||
// x.add(new ESIndividual());
|
||||
// x.add(new ESIndividual());
|
||||
// x.add(new ESIndividual());
|
||||
// x.add(new ESIndividual());
|
||||
//
|
||||
// ESPopulation y = new ESPopulation();
|
||||
// ESIndividual es = new ESIndividual();
|
||||
// MutationCMA ca = new MutationCMA();
|
||||
// es.setMutation(ca);
|
||||
// ca.setConstraints(true);
|
||||
// y.setIndividualTemplate(es);
|
||||
// System.out.println("***********");
|
||||
// //BeanTest.showInfo(x);
|
||||
// EvAServer xxx = new EvAServer(false,false);
|
||||
// //ObjectTOXML test = new ObjectTOXML();
|
||||
//// Element el = test.getXML(xxx,xxx.getClass(),false);
|
||||
//// Document doc = new Document(el);
|
||||
//// HTEFile f = HTEFile.getInstance();
|
||||
//// f.writeXMLFile(doc);
|
||||
//// System.out.println("***********");
|
||||
//// try{
|
||||
//// XMLEncoder e = new XMLEncoder(
|
||||
//// new BufferedOutputStream(
|
||||
//// new FileOutputStream("Test.xml")));
|
||||
//// e.writeObject(x);
|
||||
//// e.close();
|
||||
//// } catch (Exception ee ) {}
|
||||
//
|
||||
// //StandardESPopulation x = BeanTest.getRandomInstance(Class.forName("javaeva.server.oa.es.StandardESPopulation"));
|
||||
// //System.out.println("equal ??" + BeanTest.equalProperties(x, y));
|
||||
// }
|
||||
}
|
||||
|
||||
class mySecurityManager extends SecurityManager {
|
||||
public void checkMemberAccess( Class c, int which ) {
|
||||
System.out.println("KAKA") ; }// This is called only for
|
||||
// getDeclaredFields() and not for Field.get( )
|
||||
|
||||
public void checkPackageAccess( String p ) {}
|
||||
}
|
@ -846,26 +846,26 @@ public class GenericObjectEditor implements PropertyEditor {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void main(String [] args) {
|
||||
try {
|
||||
PropertyEditorManager.registerEditor(SelectedTag.class,TagEditor.class);
|
||||
PropertyEditorManager.registerEditor(double[].class,GenericArrayEditor.class);
|
||||
GenericObjectEditor editor = new GenericObjectEditor();
|
||||
editor.setClassType(StatisticsParameter.class);
|
||||
editor.setValue(new StatisticsParameterImpl());
|
||||
PropertyDialog pd = new PropertyDialog(editor,EVAHELP.cutClassName(editor.getClass().getName()),110, 120);
|
||||
pd.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
PropertyEditor pe = ((PropertyDialog)e.getSource()).getEditor();
|
||||
Object c = (Object)pe.getValue();
|
||||
String options = "";
|
||||
if (TRACE) System.out.println(c.getClass().getName() + " " + options);
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println(ex.getMessage());
|
||||
}
|
||||
}
|
||||
// public static void main(String [] args) {
|
||||
// try {
|
||||
// PropertyEditorManager.registerEditor(SelectedTag.class,TagEditor.class);
|
||||
// PropertyEditorManager.registerEditor(double[].class,GenericArrayEditor.class);
|
||||
// GenericObjectEditor editor = new GenericObjectEditor();
|
||||
// editor.setClassType(StatisticsParameter.class);
|
||||
// editor.setValue(new StatisticsParameterImpl());
|
||||
// PropertyDialog pd = new PropertyDialog(editor,EVAHELP.cutClassName(editor.getClass().getName()),110, 120);
|
||||
// pd.addWindowListener(new WindowAdapter() {
|
||||
// public void windowClosing(WindowEvent e) {
|
||||
// PropertyEditor pe = ((PropertyDialog)e.getSource()).getEditor();
|
||||
// Object c = (Object)pe.getValue();
|
||||
// String options = "";
|
||||
// if (TRACE) System.out.println(c.getClass().getName() + " " + options);
|
||||
// System.exit(0);
|
||||
// }
|
||||
// });
|
||||
// } catch (Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
// System.out.println(ex.getMessage());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ package javaeva.server.go.operators.terminators;
|
||||
*==========================================================================*/
|
||||
import java.io.Serializable;
|
||||
|
||||
import javaeva.gui.BeanInspector;
|
||||
import javaeva.server.go.PopulationInterface;
|
||||
import javaeva.server.go.TerminatorInterface;
|
||||
import javaeva.server.go.operators.distancemetric.PhenotypeMetric;
|
||||
@ -111,10 +112,9 @@ Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String toString() {
|
||||
String ret = "\r\nConvergenceTerminator";
|
||||
return ret;
|
||||
}
|
||||
// public String toString() {
|
||||
// return BeanTest.toString(this);
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
@ -131,7 +131,7 @@ Serializable {
|
||||
}
|
||||
|
||||
public String fitnessPerCentTipText() {
|
||||
return "Terminate if the population has not improved by the given percentage for n generations";
|
||||
return "Terminate if the fitness has not improved by this percentage for a whole stagnation time period";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ public class EvaluationTerminator implements TerminatorInterface,
|
||||
*
|
||||
*/
|
||||
public String toString() {
|
||||
String ret = "\r\nEvaluationTerminator fitness calls="+m_FitnessCalls;
|
||||
String ret = "EvaluationTerminator,calls="+m_FitnessCalls;
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ public class FitnessValueTerminator implements TerminatorInterface,
|
||||
*
|
||||
*/
|
||||
public String toString() {
|
||||
String ret = "\r\nFitnessValueTerminator m_FitnessValue ="+m_FitnessValue;
|
||||
String ret = "FitnessValueTerminator,m_FitnessValue="+m_FitnessValue;
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ public class GenerationTerminator implements TerminatorInterface,
|
||||
*
|
||||
*/
|
||||
public String toString() {
|
||||
String ret = "\r\nGenerations calls="+m_Generations;
|
||||
String ret = "Generations calls="+m_Generations;
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
|
@ -9,6 +9,7 @@ import javaeva.server.go.individuals.InterfaceDataTypeProgram;
|
||||
import javaeva.server.go.individuals.codings.gp.InterfaceProgram;
|
||||
import javaeva.server.go.operators.moso.MOSONoConvert;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.strategies.InterfaceOptimizer;
|
||||
|
||||
|
||||
import javax.swing.*;
|
||||
@ -333,6 +334,14 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param opt
|
||||
*/
|
||||
public void informAboutOptimizer(InterfaceOptimizer opt) {
|
||||
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
* These are for GUI
|
||||
|
@ -5,6 +5,9 @@ import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.AbstractOptimizationProblem;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.AbstractObjectEditor;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
import javaeva.tools.SelectedTag;
|
||||
|
||||
@ -436,6 +439,14 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
if (doSpeedAdaptation) setSpeedLimit(2*getInitialVelocity());
|
||||
}
|
||||
|
||||
|
||||
public void SetProblem (InterfaceOptimizationProblem problem) {
|
||||
super.SetProblem(problem);
|
||||
if (problem instanceof AbstractOptimizationProblem) {
|
||||
((AbstractOptimizationProblem)problem).informAboutOptimizer(this);
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will return a string describing all properties of the optimizer
|
||||
* and the applied methods.
|
||||
* @return A descriptive string
|
||||
|
@ -25,7 +25,7 @@ import javaeva.tools.SelectedTag;
|
||||
//import javax.vecmath.GMatrix;
|
||||
|
||||
/**
|
||||
* This implements particel swarm optimization by Kennedy and Eberhardt.
|
||||
* This implements particle swarm optimization by Kennedy and Eberhardt.
|
||||
* Works fine but is limited to real-valued genotypes and the original
|
||||
* version ignored range constraints on the decision variables. I've
|
||||
* implemented 'brakes' before an individual is updated it is checked
|
||||
|
@ -102,13 +102,13 @@ public class GOParameters implements InterfaceGOParameters, Serializable {
|
||||
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String toString() {
|
||||
String ret = "";//"\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem()+"\n"+this.m_Optimizer.getStringRepresentation();
|
||||
return ret;
|
||||
}
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// public String toString() {
|
||||
// String ret = "";//"\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem()+"\n"+this.m_Optimizer.getStringRepresentation();
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
|
@ -8,7 +8,7 @@ import java.io.OutputStreamWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import javaeva.gui.BeanTest;
|
||||
import javaeva.gui.BeanInspector;
|
||||
import javaeva.server.go.InterfaceGOParameters;
|
||||
import javaeva.server.go.InterfacePopulationChangedEventListener;
|
||||
import javaeva.server.go.InterfaceProcessor;
|
||||
@ -179,9 +179,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
m_Statistics.printToTextListener("****** Multirun "+runCounter);
|
||||
m_Statistics.startOptPerformed(Info,runCounter);
|
||||
m_Statistics.printToTextListener("Module parameters:");
|
||||
m_Statistics.printToTextListener(BeanTest.toString(m_ModulParameter));
|
||||
m_Statistics.printToTextListener(BeanInspector.toString(m_ModulParameter));
|
||||
m_Statistics.printToTextListener("Statistics parameters:");
|
||||
m_Statistics.printToTextListener(BeanTest.toString(m_Statistics.getStatisticsParameter()));
|
||||
m_Statistics.printToTextListener(BeanInspector.toString(m_Statistics.getStatisticsParameter()));
|
||||
|
||||
this.m_ModulParameter.getOptimizer().SetProblem(this.m_ModulParameter.getProblem());
|
||||
if (this.m_createInitialPopulations) this.m_ModulParameter.getOptimizer().init();
|
||||
@ -245,15 +245,15 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
|
||||
if (this.m_OutputFile != null) {
|
||||
// data to be stored in file
|
||||
double tmpd = 0;
|
||||
// double tmpd = 0;
|
||||
StringBuffer tmpLine = new StringBuffer("");
|
||||
tmpLine.append(population.getFunctionCalls());
|
||||
tmpLine.append("\t");
|
||||
tmpLine.append(population.getBestEAIndividual().getFitness(0));
|
||||
tmpLine.append("\t");
|
||||
for (int i = 0; i < population.size(); i++) tmpd += ((AbstractEAIndividual)population.get(i)).getFitness(0)/(double)population.size();
|
||||
tmpLine.append("\t");
|
||||
tmpLine.append(tmpd);
|
||||
double[] fit = population.getMeanFitness();
|
||||
//for (int i = 0; i < population.size(); i++) tmpd += ((AbstractEAIndividual)population.get(i)).getFitness(0)/(double)population.size();
|
||||
tmpLine.append(BeanInspector.toString(fit));
|
||||
tmpLine.append("\t");
|
||||
tmpLine.append(population.getWorstEAIndividual().getFitness(0));
|
||||
tmpLine.append("\t");
|
||||
@ -267,13 +267,14 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
* @param line The line that is to be added to the file
|
||||
*/
|
||||
private void writeToFile(String line) {
|
||||
String write = line + "\n";
|
||||
//String write = line + "\n";
|
||||
if (this.m_OutputFile == null) return;
|
||||
try {
|
||||
this.m_OutputFile.write(write, 0, write.length());
|
||||
this.m_OutputFile.write(line, 0, line.length());
|
||||
this.m_OutputFile.write('\n');
|
||||
this.m_OutputFile.flush();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Problems writing to output file!");
|
||||
System.err.println("Problems writing to output file!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,6 @@ public interface StatisticsParameter {
|
||||
public SelectedTag getPlotFitness();
|
||||
public void setPlotFitness(SelectedTag newMethod);
|
||||
public String getResultFileName();
|
||||
public void setConvergenceRateThreshold (double x);
|
||||
public double getConvergenceRateThreshold ();
|
||||
public void setConvergenceRateThreshold(double x);
|
||||
public double getConvergenceRateThreshold();
|
||||
}
|
@ -270,6 +270,10 @@ public class StatisticsParameterImpl implements StatisticsParameter, Serializabl
|
||||
return "File name for the result file, if 'none' no output file will be created.";
|
||||
}
|
||||
|
||||
public String convergenceRateThresholdTipText() {
|
||||
return "Provided the optimal fitness is at zero, give the threshold below which it is considered as 'reached'";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x
|
||||
|
@ -23,6 +23,8 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import wsi.ra.tool.StatisticUtils;
|
||||
|
||||
import javaeva.server.go.IndividualInterface;
|
||||
import javaeva.server.go.PopulationInterface;
|
||||
|
||||
@ -211,7 +213,7 @@ public class StatisticsStandalone implements Statistics, Serializable {
|
||||
|
||||
m_OptRunsPerformed++;
|
||||
if (m_BestIndividual != null) {
|
||||
if (m_BestIndividual.getFitness()[0] < this.m_StatisticsParameter.getConvergenceRateThreshold())
|
||||
if (StatisticUtils.norm(m_BestIndividual.getFitness()) < this.m_StatisticsParameter.getConvergenceRateThreshold())
|
||||
m_NumberOfConvergence++;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ import javaeva.tools.EVAERROR;
|
||||
import wsi.ra.jproxy.MainAdapterClient;
|
||||
import wsi.ra.jproxy.RMIProxyLocal;
|
||||
import wsi.ra.jproxy.RMIProxyRemote;
|
||||
import wsi.ra.tool.StatisticUtils;
|
||||
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
@ -76,6 +77,7 @@ public class StatisticsWithGUI implements Serializable, Statistics {
|
||||
// private String m_FileName = "";
|
||||
// private static boolean m_useMedian = false;
|
||||
private double[] m_SpecificData;
|
||||
private int m_ConvergenceCnt;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -112,6 +114,7 @@ public class StatisticsWithGUI implements Serializable, Statistics {
|
||||
m_MainAdapterClient);
|
||||
}
|
||||
m_OptRunsPerformed = 0;
|
||||
m_ConvergenceCnt = 0;
|
||||
if (TRACE)
|
||||
System.out.println("Constructor RMIStatistics --> end");
|
||||
}
|
||||
@ -122,6 +125,7 @@ public class StatisticsWithGUI implements Serializable, Statistics {
|
||||
public synchronized void startOptPerformed(String InfoString, int runnumber) {
|
||||
if (runnumber == 0) {
|
||||
m_OptRunsPerformed = 0;
|
||||
m_ConvergenceCnt = 0;
|
||||
m_firstPlot = true;
|
||||
m_StatisticsParameter.saveInstance();
|
||||
}
|
||||
@ -187,6 +191,12 @@ public class StatisticsWithGUI implements Serializable, Statistics {
|
||||
for (int i = 0; i < m_BestFitness.length; i++)
|
||||
s = s + " f[" + i + "]=" + m_BestFitness[i];
|
||||
}
|
||||
|
||||
if (m_BestIndividual != null) {
|
||||
if (StatisticUtils.norm(m_BestIndividual.getFitness()) < this.m_StatisticsParameter.getConvergenceRateThreshold()) {
|
||||
m_ConvergenceCnt++;
|
||||
}
|
||||
}
|
||||
|
||||
printToTextListener(" Best solution fitness: " + s);
|
||||
if (m_OptRunsPerformed <= m_StatisticsParameter.getMultiRuns()) {
|
||||
@ -219,7 +229,9 @@ public class StatisticsWithGUI implements Serializable, Statistics {
|
||||
}
|
||||
}
|
||||
if (m_OptRunsPerformed == m_StatisticsParameter.getMultiRuns()) {
|
||||
printToTextListener("*******\n Reached target " + m_ConvergenceCnt + " times with threshold " + m_StatisticsParameter.getConvergenceRateThreshold() + ", rate " + m_ConvergenceCnt/(double)m_StatisticsParameter.getMultiRuns());
|
||||
m_OptRunsPerformed = 0;
|
||||
m_ConvergenceCnt = 0;
|
||||
if (TRACE)
|
||||
System.out.println("stopOptPerformed");
|
||||
if (TRACE)
|
||||
|
@ -150,4 +150,26 @@ public class SelectedTag implements java.io.Serializable {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return m_Tags[m_Selected].getString();
|
||||
// Character selSign = '*';
|
||||
// Character separator = '|';
|
||||
// StringBuffer sbuf;
|
||||
// if (m_Selected != 0) sbuf = new StringBuffer(m_Tags[0].getString());
|
||||
// else {
|
||||
// sbuf = new StringBuffer(selSign.toString());
|
||||
// sbuf.append(m_Tags[0].getString());
|
||||
// sbuf.append(selSign);
|
||||
// }
|
||||
// for (int i=1; i<m_Tags.length; i++) {
|
||||
// sbuf.append(separator);
|
||||
// if (m_Selected == i) {
|
||||
// sbuf.append(selSign);
|
||||
// sbuf.append(m_Tags[i].getString());
|
||||
// sbuf.append(selSign);
|
||||
// } else sbuf.append(m_Tags[i].getString());
|
||||
// }
|
||||
// return sbuf.toString();
|
||||
}
|
||||
}
|
@ -13,26 +13,27 @@ package javaeva.tools;
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
public class Tag implements java.io.Serializable {
|
||||
protected int m_ID;
|
||||
protected String m_String;
|
||||
public Tag(){}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Tag(int ident, String readable) {
|
||||
m_ID = ident;
|
||||
m_String = readable;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getID() {
|
||||
return m_ID;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getString() {
|
||||
return m_String;
|
||||
}
|
||||
private static final long serialVersionUID = 1L;
|
||||
protected int m_ID;
|
||||
protected String m_String;
|
||||
public Tag(){}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Tag(int ident, String str) {
|
||||
m_ID = ident;
|
||||
m_String = str;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getID() {
|
||||
return m_ID;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getString() {
|
||||
return m_String;
|
||||
}
|
||||
}
|
||||
|
@ -320,6 +320,22 @@ public class StatisticUtils
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the 2-norm of an array of doubles.
|
||||
*
|
||||
* @param doubles the array of double
|
||||
* @return the 2-norm of the elements
|
||||
*/
|
||||
public static double norm(double[] doubles) {
|
||||
|
||||
double sqSum = 0;
|
||||
|
||||
for (int i = 0; i < doubles.length; i++) {
|
||||
sqSum += doubles[i]*doubles[i];
|
||||
}
|
||||
return Math.sqrt(sqSum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the sum of the elements of an array of integers.
|
||||
|
Loading…
x
Reference in New Issue
Block a user