Minor modifications.

This commit is contained in:
Marcel Kronfeld 2008-06-03 15:12:33 +00:00
parent 8136704b1b
commit ec2e012cf5
15 changed files with 288 additions and 136 deletions

View File

@ -158,7 +158,6 @@ public class OptimizerFactory {
es.setLambda(50); es.setLambda(50);
es.setPlusStrategy(false); es.setPlusStrategy(false);
// TODO improve this by adding getEAIndividual to AbstractEAIndividual?
AbstractEAIndividual indyTemplate = problem.getIndividualTemplate(); AbstractEAIndividual indyTemplate = problem.getIndividualTemplate();
if ((indyTemplate != null) if ((indyTemplate != null)
&& (indyTemplate instanceof InterfaceESIndividual)) { && (indyTemplate instanceof InterfaceESIndividual)) {

View File

@ -83,6 +83,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
public static boolean TRACE = false; public static boolean TRACE = false;
private static String m_ProductName = "EvA 2"; private static String m_ProductName = "EvA 2";
private static String m_ProductLongName = "Evolutionary Algorithms Workbench 2";
// private int PREFERRED_WIDTH = 680; // private int PREFERRED_WIDTH = 680;
// private int PREFERRED_HEIGHT = 550; // private int PREFERRED_HEIGHT = 550;
public JEFrame m_Frame; public JEFrame m_Frame;
@ -654,9 +655,12 @@ public class EvAClient implements RemoteStateListener, Serializable {
private void showAboutDialog() { private void showAboutDialog() {
JOptionPane.showMessageDialog JOptionPane.showMessageDialog
(m_Frame, (m_Frame,
m_ProductName + m_ProductName + " - " + m_ProductLongName +
"\n University of Tuebingen\n Computer Architecture\n H. Ulmer & F. Streichert & H. Planatscher & M. de Paly & M. Kronfeld\n Prof. Dr. Andreas Zell \n (c) 2008 \n Version " + "\n University of Tuebingen\n Computer Architecture\n " +
EvAServer.Version + " \n http://www.ra.cs.uni-tuebingen.de/software/EvA2", infoTitle, 1); "M. Kronfeld, H. Planatscher, M. de Paly, F. Streichert & H. Ulmer\n " +
// "H. Ulmer & F. Streichert & H. Planatscher & M. de Paly & M. Kronfeld\n" +
"Prof. Dr. Andreas Zell \n (c) 2008 \n Version " + EvAServer.Version +
"\n http://www.ra.cs.uni-tuebingen.de/software/EvA2", infoTitle, 1);
} }
private void showNoHostFoundDialog() { private void showNoHostFoundDialog() {

View File

@ -29,8 +29,8 @@ import java.net.InetAddress;
* *
*/ */
public class EvAServer { public class EvAServer {
/* Version string of the server application. */ /* Main version string of the EvA2 application. Change for minor releases, please.*/
public static final String Version = new String ("2.00"); public static final String Version = new String ("2.02");
public static boolean TRACE = false; public static boolean TRACE = false;
/* MainAdapterImp object. This is need for the first /* MainAdapterImp object. This is need for the first
connection between the server and the client program. */ connection between the server and the client program. */

View File

@ -3,7 +3,6 @@ package eva2.server.go.individuals;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet; import java.util.BitSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import wsi.ra.math.RNG; import wsi.ra.math.RNG;
@ -42,8 +41,11 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
private long m_ID = 0; private long m_ID = 0;
private static long m_IDcounter = 0; private static long m_IDcounter = 0;
private int logParentLen = 10; // private int logParentLen = 10;
private LinkedList<Long[]> heritage = null; private boolean logParents = true;
// heritage is to contain a list of all parents of the individual
private Long[] parentIDs = null;
private AbstractEAIndividual[] parentTree = null;
protected double[] m_Fitness = new double[1]; protected double[] m_Fitness = new double[1];
private double m_ConstraintViolation = 0; private double m_ConstraintViolation = 0;
@ -114,7 +116,12 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
m_ConstraintViolation = individual.m_ConstraintViolation; m_ConstraintViolation = individual.m_ConstraintViolation;
m_AreaConst4ParallelViolated = individual.m_AreaConst4ParallelViolated; m_AreaConst4ParallelViolated = individual.m_AreaConst4ParallelViolated;
m_Marked = individual.m_Marked; m_Marked = individual.m_Marked;
if (individual.heritage != null) heritage = new LinkedList<Long[]>(individual.heritage); if (individual.parentIDs != null) {
parentIDs = new Long[individual.parentIDs.length];
System.arraycopy(individual.parentIDs, 0, parentIDs, 0, parentIDs.length);
parentTree = new AbstractEAIndividual[individual.parentTree.length];
for (int i=0; i<parentTree.length; i++) parentTree[i] = individual.parentTree[i];
}
System.arraycopy(individual.m_Identifiers,0,m_Identifiers,0,individual.m_Identifiers.length); System.arraycopy(individual.m_Identifiers,0,m_Identifiers,0,individual.m_Identifiers.length);
System.arraycopy(individual.m_Objects,0,m_Objects,0,individual.m_Objects.length); System.arraycopy(individual.m_Objects,0,m_Objects,0,individual.m_Objects.length);
} }
@ -259,7 +266,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
AbstractEAIndividual[] result; AbstractEAIndividual[] result;
if (RNG.flipCoin(this.m_CrossoverProbability)) { if (RNG.flipCoin(this.m_CrossoverProbability)) {
result = this.m_CrossoverOperator.mate(this, partners); result = this.m_CrossoverOperator.mate(this, partners);
if (logParentLen > 0) { if (logParents) {
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
result[i].setParents(this, partners); result[i].setParents(this, partners);
} }
@ -271,7 +278,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
for (int i = 0; i < partners.size(); i++) { for (int i = 0; i < partners.size(); i++) {
result[i+1] = (AbstractEAIndividual) ((AbstractEAIndividual)partners.get(i)).clone(); result[i+1] = (AbstractEAIndividual) ((AbstractEAIndividual)partners.get(i)).clone();
} }
if (logParentLen > 0) { if (logParents) {
result[0].setParent(this); result[0].setParent(this);
for (int i = 0; i < partners.size(); i++) { for (int i = 0; i < partners.size(); i++) {
result[i+1].setParent(partners.getEAIndividual(i)); result[i+1].setParent(partners.getEAIndividual(i));
@ -284,59 +291,101 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
return result; return result;
} }
/** // /**
* Toggle the parent logging mechanism. It keeps track of the ancestor IDs of an individual // * Toggle the parent logging mechanism. It keeps track of the ancestor IDs of an individual
* if mutation/crossover are used. Set the desired length of logging history (generations) or // * if mutation/crossover are used. Set the desired length of logging history (generations) or
* set it to 0 to deactivate heritage logging. // * set it to 0 to deactivate heritage logging.
* // *
* @param logPs // * @param logPs
*/ // */
public void setLogHeritagetLen(int logLen) { // public void setLogHeritagetLen(int logLen) {
logParentLen = logLen; // logParentLen = logLen;
} // }
/** /**
* Add an ancestor generation with multiple parents. * Add an ancestor generation with multiple parents.
* *
* @param parents * @param parents
*/ */
private void setParents(AbstractEAIndividual parent, Population parents) { protected void setParents(AbstractEAIndividual parent, Population parents) {
if (heritage == null) heritage = new LinkedList<Long[]>(); int parentCnt = (parents == null) ? 1 : (1+parents.size());
Long[] parentIDs = new Long[1+parents.size()]; parentIDs = new Long[parentCnt];
parentTree = new AbstractEAIndividual[parentCnt];
parentIDs[0] = parent.getIndyID(); parentIDs[0] = parent.getIndyID();
for (int i=0; i<parents.size(); i++) parentIDs[i+1] = parents.getEAIndividual(i).getIndyID(); parentTree[0] = (AbstractEAIndividual)parent.clone();
addHeritage(parentIDs); if ((parents != null) && (parents.size() > 0)) {
for (int i=0; i<parents.size(); i++) {
parentIDs[i+1] = parents.getEAIndividual(i).getIndyID();
parentTree[i+1] = (AbstractEAIndividual)parents.getEAIndividual(i).clone();
}
}
// addHeritage(parentIDs);
} }
private void addHeritage(Long[] parentIDs) { /**
heritage.add(parentIDs); * Add an ancestor list with multiple parents.
if (heritage.size() > logParentLen) heritage.remove(0); *
* @param parents
*/
public void setParents(List<AbstractEAIndividual> parents) {
if ((parents == null) || (parents.size() == 0)) {
parentIDs = null;
parentTree = null;
} else {
int parentCnt = parents.size();
parentIDs = new Long[parentCnt];
parentTree = new AbstractEAIndividual[parentCnt];
for (int i=0; i<parentCnt; i++) {
parentIDs[i] = parents.get(i).getIndyID();
parentTree[i] = (AbstractEAIndividual)parents.get(i).clone();
}
}
} }
public String getHeritageTree(int depth) {
StringBuffer sb = new StringBuffer();
sb.append(getIndyID());
sb.append(" ");
if ((depth > 0) && (parentTree != null)) {
sb.append("[ ");
for (int i=0; i<parentTree.length; i++) {
sb.append(parentTree[i].getHeritageTree(depth - 1));
// if ((i+1) < parentTree.length) sb.append(", ");
}
sb.append("] ");
}
return sb.toString();
}
// private void addHeritage(Long[] parentIDs) {
// heritage.add(parentIDs);
//// if (heritage.size() > logParentLen) heritage.remove(0);
// }
/** /**
* Add an ancestor generation with only one parent. * Add an ancestor generation with only one parent.
* *
* @param parent * @param parent
*/ */
protected void setParent(AbstractEAIndividual parent) { protected void setParent(AbstractEAIndividual parent) {
if (heritage == null) heritage = new LinkedList<Long[]>(); setParents(parent, null);
Long[] parentID = new Long[1];
parentID[0] = parent.getIndyID();
addHeritage(parentID);
} }
public List<Long[]> getHeritageList() { public Long[] getParentIDs() {
return heritage; return parentIDs;
} }
/** // /**
* Returns the last set of parental IDs or null if none are available. // * Returns the last set of parental IDs or null if none are available.
* @return the last set of parental IDs or null if none are available // *
*/ // * @return the last set of parental IDs or null if none are available
public Long[] getHeritage() { // */
if (heritage != null) return heritage.getLast(); // public Long[] getHeritage() {
else return null; // if (heritage != null) return heritage.getLast();
} // else return null;
// }
/** This method will allow you to get the current age of an individual /** This method will allow you to get the current age of an individual
* Zero means it has not even been evaluated. * Zero means it has not even been evaluated.
@ -757,7 +806,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
sb.append(", ID: "); sb.append(", ID: ");
sb.append(individual.getIndyID()); sb.append(individual.getIndyID());
sb.append(", parents: "); sb.append(", parents: ");
sb.append(BeanInspector.toString(individual.getHeritage())); sb.append(BeanInspector.toString(individual.getParentIDs()));
return sb.toString(); return sb.toString();
} }

View File

@ -581,13 +581,13 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
return idList; return idList;
} }
public Long[][] getParentalIDList() { // public Long[][] getParentalIDList() {
Long[][] idList = new Long[size()][]; // Long[][] idList = new Long[size()][];
for (int i=0; i<idList.length; i++) { // for (int i=0; i<idList.length; i++) {
idList[i]=getEAIndividual(i).getHeritage(); // idList[i]=getEAIndividual(i).getHeritage();
} // }
return idList; // return idList;
} // }
public String getIndyList() { public String getIndyList() {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();

View File

@ -1,6 +1,5 @@
package eva2.server.go.problems; package eva2.server.go.problems;
import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.populations.Population; import eva2.server.go.populations.Population;
/** /**

View File

@ -122,10 +122,12 @@ public class MatlabEvalMediator implements Runnable {
} }
void setSolution(double[] sol) { void setSolution(double[] sol) {
//System.out.println("setting Sol");
optSolution = sol; optSolution = sol;
} }
void setSolutionSet(double[][] solSet) { void setSolutionSet(double[][] solSet) {
//System.out.println("setting SolSet " + ((solSet != null) ? solSet.length : 0));
optSolSet = solSet; optSolSet = solSet;
} }
@ -134,6 +136,7 @@ public class MatlabEvalMediator implements Runnable {
* @return * @return
*/ */
public double[] getSolution() { public double[] getSolution() {
//System.out.println("getting Sol");
return optSolution; return optSolution;
} }
@ -142,6 +145,7 @@ public class MatlabEvalMediator implements Runnable {
* @return * @return
*/ */
public double[][] getSolutionSet() { public double[][] getSolutionSet() {
//System.out.println("getting SolSet" + ((optSolSet != null) ? optSolSet.length : 0));
return optSolSet; return optSolSet;
} }
} }

View File

@ -238,9 +238,18 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex
InterfaceOptimizer opt = runnable.getGOParams().getOptimizer(); InterfaceOptimizer opt = runnable.getGOParams().getOptimizer();
for (int i=0; i<specParams.length; i++) { // loop over settings for (int i=0; i<specParams.length; i++) { // loop over settings
log("try setting " + specParams[i] + " to " + specValues[i]); log("try setting " + specParams[i] + " to " + specValues[i]);
if (!BeanInspector.setMem(opt, (String)specParams[i], specValues[i])) { String paramName = null;
try {
paramName = (String)specParams[i];
} catch (ClassCastException e) {
paramName = "" + specParams[i];
if (!(specParams[i] instanceof Character)) {
System.err.println("Error, parameter "+ specParams[i] + " could not be cast to String, trying " + paramName);
}
}
if ((paramName == null) || (!BeanInspector.setMem(opt, paramName, specValues[i]))) {
log("... Fail!\n"); log("... Fail!\n");
System.err.println("Unable to set parameter " + specParams[i] + ", skipping..."); System.err.println("Unable to set parameter " + paramName + ", skipping...");
} else log("... Ok.\n"); } else log("... Ok.\n");
} }
log(BeanInspector.toString(BeanInspector.getMemberDescriptions(opt, true))); log(BeanInspector.toString(BeanInspector.getMemberDescriptions(opt, true)));
@ -319,7 +328,6 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex
// //
void exportResultPopulationToMatlab(Population pop) { void exportResultPopulationToMatlab(Population pop) {
double[][] solSet; double[][] solSet;
if ((pop != null) && (pop.size()>0)) { if ((pop != null) && (pop.size()>0)) {
solSet = new double[pop.size()][]; solSet = new double[pop.size()][];
for (int i=0; i<pop.size(); i++) { for (int i=0; i<pop.size(); i++) {
@ -454,6 +462,7 @@ class WaitForEvARunnable implements Runnable {
mp.exportResultPopulationToMatlab(null); mp.exportResultPopulationToMatlab(null);
} }
mp.notifyFinished(); mp.notifyFinished();
mp.log("notified finish...");
} }
} }

View File

@ -50,6 +50,9 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
private InterfaceOptimizer m_Optimizer = new GeneticAlgorithm(); private InterfaceOptimizer m_Optimizer = new GeneticAlgorithm();
private InterfaceClustering m_CAForSpeciesDifferentation = new ClusteringDensityBased(); private InterfaceClustering m_CAForSpeciesDifferentation = new ClusteringDensityBased();
private InterfaceClustering m_CAForSpeciesConvergence = new ClusteringDensityBased(); private InterfaceClustering m_CAForSpeciesConvergence = new ClusteringDensityBased();
//private Distraction distraction = null;
// private boolean useDistraction = false;
// private double distrDefaultStrength = 1.;
transient private String m_Identifier = ""; transient private String m_Identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener m_Listener;
@ -76,6 +79,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
public ClusterBasedNichingEA() { public ClusterBasedNichingEA() {
this.m_CAForSpeciesConvergence = new ClusteringDensityBased(); this.m_CAForSpeciesConvergence = new ClusteringDensityBased();
((ClusteringDensityBased)this.m_CAForSpeciesConvergence).setMinimumGroupSize(m_minGroupSize); ((ClusteringDensityBased)this.m_CAForSpeciesConvergence).setMinimumGroupSize(m_minGroupSize);
// if (useDistraction) distraction = new Distraction();
} }
public ClusterBasedNichingEA(ClusterBasedNichingEA a) { public ClusterBasedNichingEA(ClusterBasedNichingEA a) {
@ -337,6 +341,15 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
if (TRACE) System.out.println("correcting popsize after opt: " + retPop.getPopulationSize() + " to " + retPop.size()); if (TRACE) System.out.println("correcting popsize after opt: " + retPop.getPopulationSize() + " to " + retPop.size());
retPop.setPopulationSize(retPop.size()); retPop.setPopulationSize(retPop.size());
} }
// if (useDistraction) {
// if ((distraction != null) && (!distraction.isEmpty())) {
// System.out.println("Distraction step!!!");
// for (int i=0; i<retPop.size(); i++) {
// distraction.applyDistractionTo(retPop.getEAIndividual(i));
// }
// }
// }
return retPop; return retPop;
} }
@ -394,7 +407,13 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
int reinitCount = -1; int reinitCount = -1;
if (m_UseArchive) { // if (useDistraction) {
// if (distraction == null) distraction = new Distraction(distrDefaultStrength, Distraction.METH_BEST);
// distraction.addDistractorFrom(curSpecies);
// System.out.println("** Adding distractor! " + BeanInspector.toString(distraction.getDistractionCenter(curSpecies, distraction.getDistractionMethod().getSelectedTagID())));
// }
if (m_UseArchive) {
m_Archive.add(best); m_Archive.add(best);
m_Species.remove(i); //REMOVES the converged Species m_Species.remove(i); //REMOVES the converged Species
reinitCount = curSpecies.size(); // add all as new reinitCount = curSpecies.size(); // add all as new
@ -442,12 +461,12 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
m_Undifferentiated.incrFunctionCallsby(m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize)); m_Undifferentiated.incrFunctionCallsby(m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize));
} else if (TRACE) System.out.println("### undiff active: " + isActive(m_Undifferentiated)); } else if (TRACE) System.out.println("### undiff active: " + isActive(m_Undifferentiated));
// possible species differentation and convergence // possible species differentiation and convergence
if (this.m_Undifferentiated.getGeneration()%this.m_SpeciesCycle == 0) { if (this.m_Undifferentiated.getGeneration()%this.m_SpeciesCycle == 0) {
if (TRACE) System.out.println("Species cycle:"); if (TRACE) System.out.println("Species cycle:");
if (this.m_UseSpeciesDifferentation) { if (this.m_UseSpeciesDifferentation) {
///////////////////////////// species differentation phase ///////////////////////////// species differentiation phase
if (TRACE) System.out.println("-Species Differentation:"); if (TRACE) System.out.println("-Species Differentation:");
Population[] ClusterResult; Population[] ClusterResult;
ArrayList<Population> newSpecies = new ArrayList<Population>(); ArrayList<Population> newSpecies = new ArrayList<Population>();
@ -589,7 +608,10 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
if (TRACE) System.out.println("Population size: " + this.m_Population.size()); if (TRACE) System.out.println("Population size: " + this.m_Population.size());
// if (TRACE) { // if (TRACE) {
// Distraction distr = new Distraction(5., 0, m_Species); // Distraction distr = new Distraction(5., 0, m_Species);
// if (m_Undifferentiated.size()>0) distr.calcDistractionFor(m_Undifferentiated.getBestEAIndividual()); // if (!distr.isEmpty()) {
// double[] distVect = distr.calcDistractionFor(m_Undifferentiated.getBestEAIndividual());
// System.out.println("species distract best towards " + BeanInspector.toString(distVect));
// }
// } // }
this.firePropertyChangedEvent("NextGenerationPerformed"); this.firePropertyChangedEvent("NextGenerationPerformed");
} }
@ -615,16 +637,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
spec.clear(); spec.clear();
spec.add(survivor); spec.add(survivor);
} }
// /**
// * Deactivate a given species by removing all but the best individual as representative and
// * setting the population size to one.
// *
// * @param spec
// */
// protected void deactivateSpecies(Population spec) {
//// deactivate a species keeping a representative
// deactivateSpecies(spec, spec.getBestEAIndividual());
// }
/** This method allows an optimizer to register a change in the optimizer. /** This method allows an optimizer to register a change in the optimizer.
* @param source The source of the event. * @param source The source of the event.

View File

@ -1,5 +1,8 @@
package eva2.server.go.strategies; package eva2.server.go.strategies;
import java.util.Vector;
import wsi.ra.math.RNG;
import eva2.server.go.InterfacePopulationChangedEventListener; import eva2.server.go.InterfacePopulationChangedEventListener;
import eva2.server.go.individuals.AbstractEAIndividual; import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.individuals.InterfaceESIndividual; import eva2.server.go.individuals.InterfaceESIndividual;
@ -9,10 +12,9 @@ import eva2.server.go.problems.AbstractMultiObjectiveOptimizationProblem;
import eva2.server.go.problems.AbstractOptimizationProblem; import eva2.server.go.problems.AbstractOptimizationProblem;
import eva2.server.go.problems.F1Problem; import eva2.server.go.problems.F1Problem;
import eva2.server.go.problems.InterfaceOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem;
import wsi.ra.math.RNG;
import eva2.tools.EVAERROR; import eva2.tools.EVAERROR;
import eva2.tools.Pair;
import eva2.tools.SelectedTag; import eva2.tools.SelectedTag;
import eva2.tools.Tag;
/** Differential evolution implementing DE1 and DE2 following the paper of Storm and /** Differential evolution implementing DE1 and DE2 following the paper of Storm and
* Price and the Trigonometric DE published rectently, which doesn't really work that * Price and the Trigonometric DE published rectently, which doesn't really work that
@ -34,6 +36,9 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
private double m_Lambda = 0.6; private double m_Lambda = 0.6;
private double m_Mt = 0.05; private double m_Mt = 0.05;
private int maximumAge = -1; private int maximumAge = -1;
// to log the parents of a newly created indy.
private boolean doLogParents = false; // TODO deactivate for better performance
private Vector<AbstractEAIndividual> parents = null;
private String m_Identifier = ""; private String m_Identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener m_Listener;
@ -99,8 +104,8 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
} }
/** /**
* This method return a difference vector between two random individuals from the population. * This method returns a difference vector between two random individuals from the population.
* This method should make sure that the delta is not zero. * This method should make sure that delta is not zero.
* *
* @param pop The population to choose from * @param pop The population to choose from
* @return The delta vector * @return The delta vector
@ -111,12 +116,17 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
boolean isEmpty; boolean isEmpty;
int iterations = 0; int iterations = 0;
x1 = getRandomGenotype(pop); AbstractEAIndividual x1Indy = getRandomIndy(pop);
x1 = getGenotype(x1Indy);
if (parents != null) parents.add(x1Indy);
result = new double[x1.length]; result = new double[x1.length];
isEmpty = true; isEmpty = true;
AbstractEAIndividual x2Indy = null;
while (isEmpty && (iterations < pop.size())) { while (isEmpty && (iterations < pop.size())) {
x2 = getRandomGenotype(pop); x2Indy = getRandomIndy(pop);
x2 = getGenotype(x2Indy);
for (int i = 0; i < x1.length; i++) { for (int i = 0; i < x1.length; i++) {
result[i] = x1[i] - x2[i]; result[i] = x1[i] - x2[i];
@ -124,13 +134,18 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
} }
iterations++; iterations++;
} }
while (isEmpty) { // so now the hard way: construct a random vector if (!isEmpty && (parents != null)) parents.add(x2Indy);
while (isEmpty) {
// for n (popSize) iterations there were only zero vectors found
// so now the hard way: construct a random vector
for (int i = 0; i < x1.length; i++) { for (int i = 0; i < x1.length; i++) {
if (RNG.flipCoin(1/(double)x1.length)) if (RNG.flipCoin(1/(double)x1.length))
result[i] = 0.01*RNG.gaussianDouble(0.1); result[i] = 0.01*RNG.gaussianDouble(0.1);
else result[i] = 0; else result[i] = 0;
isEmpty = (isEmpty && (result[i]==0)); isEmpty = (isEmpty && (result[i]==0));
} }
// single parent! dont add another one
} }
return result; return result;
@ -144,21 +159,26 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
* @return the delta vector * @return the delta vector
*/ */
private double[] fetchDeltaBest(Population pop, InterfaceESIndividual indy) { private double[] fetchDeltaBest(Population pop, InterfaceESIndividual indy) {
double[] x1, xb, result; double[] x1, result;
AbstractEAIndividual xbIndy;
x1 = indy.getDGenotype(); x1 = indy.getDGenotype();
result = new double[x1.length]; result = new double[x1.length];
if (m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) { if (m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) {
// implements MODE for the multi-objective case: a dominating individual is selected for difference building // implements MODE for the multi-objective case: a dominating individual is selected for difference building
Population domSet = pop.getDominatingSet((AbstractEAIndividual)indy); Population domSet = pop.getDominatingSet((AbstractEAIndividual)indy);
if (domSet.size() > 0) { if (domSet.size() > 0) {
xb = getRandomGenotype(domSet); xbIndy = getRandomIndy(domSet);
} else { } else {
return result; // just return a zero vector. this will happen automatically if domSet contains only the individual itself return result; // just return a zero vector. this will happen automatically if domSet contains only the individual itself
} }
} else { } else {
xb = getBestGenotype(pop); xbIndy = getBestIndy(pop);
} }
double[] xb = getGenotype(xbIndy);
if (parents != null) parents.add(xbIndy); // given indy argument is already listed
for (int i = 0; i < x1.length; i++) { for (int i = 0; i < x1.length; i++) {
result[i] = xb[i] - x1[i]; result[i] = xb[i] - x1[i];
} }
@ -190,23 +210,29 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
* @return AbstractEAIndividual * @return AbstractEAIndividual
*/ */
public AbstractEAIndividual generateNewIndividual(Population pop) { public AbstractEAIndividual generateNewIndividual(Population pop) {
int firstParentIndex;
AbstractEAIndividual indy; AbstractEAIndividual indy;
InterfaceESIndividual endy; InterfaceESIndividual esIndy;
if (doLogParents) parents = new Vector<AbstractEAIndividual>();
else parents = null;
try { try {
indy = (AbstractEAIndividual)(pop.getEAIndividual(RNG.randomInt(0, pop.size()-1))).getClone(); // select one random indy as starting individual. its a parent in any case.
endy = (InterfaceESIndividual)indy; firstParentIndex = RNG.randomInt(0, pop.size()-1);
indy = (AbstractEAIndividual)(pop.getEAIndividual(firstParentIndex)).getClone();
esIndy = (InterfaceESIndividual)indy;
} catch (java.lang.ClassCastException e) { } catch (java.lang.ClassCastException e) {
System.err.println("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); System.err.println("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
return (AbstractEAIndividual)((AbstractEAIndividual)pop.get(RNG.randomInt(0, pop.size()-1))).getClone(); return (AbstractEAIndividual)((AbstractEAIndividual)pop.get(RNG.randomInt(0, pop.size()-1))).getClone();
} }
double[] nX, vX, oX; double[] nX, vX, oX;
oX = endy.getDGenotype(); oX = esIndy.getDGenotype();
vX = endy.getDGenotype(); vX = esIndy.getDGenotype();
nX = new double[oX.length]; nX = new double[oX.length];
switch (this.m_DEType.getSelectedTag().getID()) { switch (this.m_DEType.getSelectedTag().getID()) {
case 0 : { case 0 : {
// this is DE1 or DE/rand/1 // this is DE1 or DE/rand/1
double[] delta = this.fetchDeltaRandom(pop); double[] delta = this.fetchDeltaRandom(pop);
if (parents != null) parents.add(pop.getEAIndividual(firstParentIndex)); // Add wherever oX is used directly
for (int i = 0; i < oX.length; i++) { for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.m_F*delta[i]; vX[i] = oX[i] + this.m_F*delta[i];
} }
@ -215,7 +241,8 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
case 1 : { case 1 : {
// this is DE2 or DE/current-to-best/1 // this is DE2 or DE/current-to-best/1
double[] rndDelta = this.fetchDeltaRandom(pop); double[] rndDelta = this.fetchDeltaRandom(pop);
double[] bestDelta = this.fetchDeltaBest(pop, endy); double[] bestDelta = this.fetchDeltaBest(pop, esIndy);
if (parents != null) parents.add(pop.getEAIndividual(firstParentIndex)); // Add wherever oX is used directly
for (int i = 0; i < oX.length; i++) { for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.m_Lambda * bestDelta[i] + this.m_F * rndDelta[i]; vX[i] = oX[i] + this.m_Lambda * bestDelta[i] + this.m_F * rndDelta[i];
} }
@ -223,8 +250,10 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
} }
case 2: { case 2: {
// DE/best/2 // DE/best/2
oX = getBestGenotype(pop); AbstractEAIndividual bestIndy = getBestIndy(pop);
double[] delta1 = this.fetchDeltaRandom(pop); oX = getGenotype(bestIndy);
if (parents != null) parents.add(bestIndy); // Add best instead of preselected
double[] delta1 = this.fetchDeltaRandom(pop);
double[] delta2 = this.fetchDeltaRandom(pop); double[] delta2 = this.fetchDeltaRandom(pop);
for (int i = 0; i < oX.length; i++) { for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.m_F * (delta1[i] + delta2[i]); vX[i] = oX[i] + this.m_F * (delta1[i] + delta2[i]);
@ -233,29 +262,35 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
} }
case 3 : { case 3 : {
// this is trigonometric mutation // this is trigonometric mutation
if (parents != null) parents.add(pop.getEAIndividual(firstParentIndex)); // Add wherever oX is used directly
if (RNG.flipCoin(this.m_Mt)) { if (RNG.flipCoin(this.m_Mt)) {
double[] xj, xk, xl; xj = oX; double[] xk, xl;
double p, pj, pk, pl; double p, pj, pk, pl;
InterfaceESIndividual indy1 = null, indy2 = null; InterfaceESIndividual indy1 = null, indy2 = null;
try { try {
// and i got indy! // and i got indy!
indy1 = (InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1)); indy1 = (InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1));
indy2 = (InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1)); indy2 = (InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1));
if (parents != null) {
parents.add((AbstractEAIndividual)indy1);
parents.add((AbstractEAIndividual)indy2);
}
} catch (java.lang.ClassCastException e) { } catch (java.lang.ClassCastException e) {
EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
} }
xk = indy1.getDGenotype(); xk = indy1.getDGenotype();
xl = indy2.getDGenotype(); xl = indy2.getDGenotype();
p = Math.abs(((AbstractEAIndividual)endy).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy1).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy2).getFitness(0)); p = Math.abs(((AbstractEAIndividual)esIndy).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy1).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy2).getFitness(0));
pj = Math.abs(((AbstractEAIndividual)endy).getFitness(0))/p; pj = Math.abs(((AbstractEAIndividual)esIndy).getFitness(0))/p;
pk = Math.abs(((AbstractEAIndividual)indy1).getFitness(0))/p; pk = Math.abs(((AbstractEAIndividual)indy1).getFitness(0))/p;
pl = Math.abs(((AbstractEAIndividual)indy2).getFitness(0))/p; pl = Math.abs(((AbstractEAIndividual)indy2).getFitness(0))/p;
for (int i = 0; i < oX.length; i++) { for (int i = 0; i < oX.length; i++) {
vX[i] = (xj[i] + xk[i] + xl[i])/3.0 + ((pk-pj)*(xj[i]-xk[i])) + ((pl-pk)*(xk[i]-xl[i])) + ((pj-pl)*(xl[i]-xj[i])); vX[i] = (oX[i] + xk[i] + xl[i])/3.0 + ((pk-pj)*(oX[i]-xk[i])) + ((pl-pk)*(xk[i]-xl[i])) + ((pj-pl)*(xl[i]-oX[i]));
} }
} else { } else {
// this is DE1 // this is DE1
double[] delta = this.fetchDeltaRandom(pop); double[] delta = this.fetchDeltaRandom(pop);
if (parents != null) parents.add(pop.getEAIndividual(firstParentIndex)); // Add wherever oX is used directly
for (int i = 0; i < oX.length; i++) { for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.m_F*delta[i]; vX[i] = oX[i] + this.m_F*delta[i];
} }
@ -273,35 +308,34 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
} }
} }
// setting the new genotype and fitness // setting the new genotype and fitness
endy.SetDGenotype(nX); esIndy.SetDGenotype(nX);
indy.SetAge(0); indy.SetAge(0);
double[] fit = new double[1]; double[] fit = new double[1];
fit[0] = 0; fit[0] = 0;
indy.SetFitness(fit); indy.SetFitness(fit);
if (parents != null) indy.setParents(parents);
return indy; return indy;
} }
private double[] getBestGenotype(Population pop) { private AbstractEAIndividual getBestIndy(Population pop) {
double[] xb; double[] xb;
try { return (AbstractEAIndividual)pop.getBestIndividual();
xb = ((InterfaceESIndividual)pop.getBestIndividual()).getDGenotype();
} catch (java.lang.ClassCastException e) {
System.err.println("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
return new double[1];
}
return xb;
} }
private double[] getRandomGenotype(Population pop) { private AbstractEAIndividual getRandomIndy(Population pop) {
double[] x1; double[] x1;
int randIndex = RNG.randomInt(0, pop.size()-1);
return pop.getEAIndividual(randIndex);
}
private double[] getGenotype(AbstractEAIndividual indy) {
try { try {
x1 = ((InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1))).getDGenotype(); return ((InterfaceESIndividual)indy).getDGenotype();
} catch (java.lang.ClassCastException e) { } catch (java.lang.ClassCastException e) {
System.err.println("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
return new double[1]; return null;
} }
return x1;
} }
public void optimize() { public void optimize() {

View File

@ -1,5 +1,6 @@
package eva2.server.go.strategies; package eva2.server.go.strategies;
import eva2.gui.BeanInspector;
import eva2.server.go.InterfacePopulationChangedEventListener; import eva2.server.go.InterfacePopulationChangedEventListener;
import eva2.server.go.individuals.AbstractEAIndividual; import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.operators.mutation.MutateESSuccessRule; import eva2.server.go.operators.mutation.MutateESSuccessRule;
@ -54,7 +55,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
setMu(mu); setMu(mu);
setLambda(lambda); setLambda(lambda);
setPlusStrategy(usePlus); setPlusStrategy(usePlus);
this.m_Population.setPopulationSize(this.m_Lambda); this.checkPopulationConstraints();
} }
public EvolutionStrategies(EvolutionStrategies a) { public EvolutionStrategies(EvolutionStrategies a) {
@ -76,7 +77,6 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
public void init() { public void init() {
// @todo In case of CBN-ES i need to read the population size!? // @todo In case of CBN-ES i need to read the population size!?
// @todo but how!? I guess this will never do...
// int orgPopSize = this.m_Population.getPopulationSize(); // int orgPopSize = this.m_Population.getPopulationSize();
// if (this.m_InitialPopulationSize > orgPopSize) { // if (this.m_InitialPopulationSize > orgPopSize) {
// this.m_Population.setPopulationSize(this.m_InitialPopulationSize); // this.m_Population.setPopulationSize(this.m_InitialPopulationSize);
@ -86,15 +86,6 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
this.evaluatePopulation(this.m_Population); this.evaluatePopulation(this.m_Population);
// this.m_Population.setPopulationSize(orgPopSize); // this.m_Population.setPopulationSize(orgPopSize);
this.firePropertyChangedEvent("NextGenerationPerformed"); this.firePropertyChangedEvent("NextGenerationPerformed");
// int myu = this.m_Population.getPopulationSize();
// int initPopSize = 0;
// if (this.m_UsePlusStrategy) initPopSize = myu + (this.m_LambdaRatio * myu);
// else initPopSize = (this.m_LambdaRatio * myu);
// // Init with initPopSize individuals
// this.m_Population.setPopulationSize(initPopSize);
// this.m_Problem.initPopulation(this.m_Population);
// this.evaluatePopulation(this.m_Population);
// this.m_Population.setPopulationSize(myu);
} }
@ -365,8 +356,9 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
return "("+getMu()+(getPlusStrategy() ? "+" : ",")+getLambda()+")-ES"; return "("+getMu()+(getPlusStrategy() ? "+" : ",")+getLambda()+")-ES";
} }
/** Assuming that all optimizer will store thier data in a population /**
* we will allow acess to this population to query to current state * Assuming that all optimizer will store their data in a population
* we will allow access to this population to query to current state
* of the optimizer. * of the optimizer.
* @return The population of current solutions to a given problem. * @return The population of current solutions to a given problem.
*/ */

View File

@ -17,6 +17,7 @@ import eva2.server.go.problems.F1Problem;
import eva2.server.go.problems.Interface2DBorderProblem; import eva2.server.go.problems.Interface2DBorderProblem;
import eva2.server.go.problems.InterfaceOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem;
import wsi.ra.math.RNG; import wsi.ra.math.RNG;
import eva2.tools.EVAERROR;
import eva2.tools.SelectedTag; import eva2.tools.SelectedTag;
import wsi.ra.chart2d.DPoint; import wsi.ra.chart2d.DPoint;
@ -444,6 +445,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
protected void resetIndividual(AbstractEAIndividual indy) { protected void resetIndividual(AbstractEAIndividual indy) {
if (indy instanceof InterfaceESIndividual) { if (indy instanceof InterfaceESIndividual) {
indy.setParents(null);
InterfaceESIndividual endy = (InterfaceESIndividual) indy; InterfaceESIndividual endy = (InterfaceESIndividual) indy;
endy.defaultInit(); endy.defaultInit();
indy.SetData(partTypeKey, defaultType); // turn into default type indy.SetData(partTypeKey, defaultType); // turn into default type
@ -472,7 +474,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
default: System.err.println("particle type " + type + " unknown!"); break; default: System.err.println("particle type " + type + " unknown!"); break;
} }
} else { } else {
System.err.println("Could not perform PSO update, because individual is not instance of InterfaceESIndividual!"); EVAERROR.errorMsgOnce("Could not perform PSO update, because individual is not instance of InterfaceESIndividual!");
} }
} }

View File

@ -16,6 +16,7 @@ import eva2.server.stat.InterfaceStatistics;
import eva2.server.stat.InterfaceTextListener; import eva2.server.stat.InterfaceTextListener;
import eva2.server.stat.StatisticsWithGUI; import eva2.server.stat.StatisticsWithGUI;
import eva2.tools.EVAERROR; import eva2.tools.EVAERROR;
import eva2.tools.EVAHELP;
import wsi.ra.jproxy.RemoteStateListener; import wsi.ra.jproxy.RemoteStateListener;
/** /**
@ -179,6 +180,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
goParams.getOptimizer().addPopulationChangedEventListener(this); goParams.getOptimizer().addPopulationChangedEventListener(this);
runCounter = 0; runCounter = 0;
String popLog = null; //"populationLog.txt";
while (isOptRunning() && (runCounter<m_Statistics.getStatisticsParameter().getMultiRuns())) { while (isOptRunning() && (runCounter<m_Statistics.getStatisticsParameter().getMultiRuns())) {
m_Statistics.startOptPerformed(getInfoString(),runCounter, goParams); m_Statistics.startOptPerformed(getInfoString(),runCounter, goParams);
@ -190,12 +192,12 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
//m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation()); //m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(getStatusPercent(goParams.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()), null); if (m_ListenerModule!=null) m_ListenerModule.updateProgress(getStatusPercent(goParams.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()), null);
if (popLog != null) EVAHELP.clearLog(popLog);
do { // main loop do { // main loop
this.goParams.getOptimizer().optimize(); this.goParams.getOptimizer().optimize();
// registerPopulationStateChanged *SHOULD* be fired by the optimizer or resp. the population // registerPopulationStateChanged *SHOULD* be fired by the optimizer or resp. the population
// as we are event listener // as we are event listener
//System.out.println(this.goParams.getOptimizer().getPopulation().getIndyList()); if (popLog != null) EVAHELP.logString(this.goParams.getOptimizer().getPopulation().getIndyList(), popLog);
} while (isOptRunning() && !this.goParams.getTerminator().isTerminated(this.goParams.getOptimizer().getPopulation())); } while (isOptRunning() && !this.goParams.getTerminator().isTerminated(this.goParams.getOptimizer().getPopulation()));
runCounter++; runCounter++;
@ -206,7 +208,16 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
if (isOptRunning()) { if (isOptRunning()) {
resultPop = performPostProcessing(); resultPop = performPostProcessing();
} else resultPop = goParams.getOptimizer().getAllSolutions(); } else resultPop = goParams.getOptimizer().getAllSolutions();
/**
if (isOptRunning()) {
resultPop = performPostProcessing();
//System.out.println("calling getall after PP returned " + (resultPop == null ? "null" : resultPop.size()));
}
if (resultPop == null) {
resultPop = goParams.getOptimizer().getAllSolutions();
//System.out.println("calling getall returned " + resultPop.size());
}
**/
} }
setOptRunning(false); // normal finish setOptRunning(false); // normal finish
if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode
@ -328,12 +339,15 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
// if textwindow was closed, check if it should be reopened for pp // if textwindow was closed, check if it should be reopened for pp
if (m_Statistics instanceof StatisticsWithGUI) ((StatisticsWithGUI)m_Statistics).maybeShowProxyPrinter(); if (m_Statistics instanceof StatisticsWithGUI) ((StatisticsWithGUI)m_Statistics).maybeShowProxyPrinter();
} }
Population resultPop = goParams.getOptimizer().getAllSolutions(); Population resultPop = (Population)(goParams.getOptimizer().getAllSolutions()).clone();
if (resultPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) { if (resultPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) {
// System.err.println("bad case in Processor::performNewPostProcessing "); // System.err.println("bad case in Processor::performNewPostProcessing ");
resultPop.SetFunctionCalls(goParams.getOptimizer().getPopulation().getFunctionCalls()); resultPop.SetFunctionCalls(goParams.getOptimizer().getPopulation().getFunctionCalls());
} }
if (!resultPop.contains(m_Statistics.getBestSolution())) resultPop.add(m_Statistics.getBestSolution()); // this is a minor cheat but guarantees that the best solution ever found is contained in the final results if (!resultPop.contains(m_Statistics.getBestSolution())) {
resultPop.add(m_Statistics.getBestSolution()); // this is a minor cheat but guarantees that the best solution ever found is contained in the final results
resultPop.setPopulationSize(resultPop.size());
}
resultPop = PostProcess.postProcess(ppp, resultPop, (AbstractOptimizationProblem)goParams.getProblem(), listener); resultPop = PostProcess.postProcess(ppp, resultPop, (AbstractOptimizationProblem)goParams.getProblem(), listener);
return resultPop; return resultPop;
} else return null; } else return null;

View File

@ -12,19 +12,21 @@ package eva2.tools;
/*==========================================================================* /*==========================================================================*
* IMPORTS * IMPORTS
*==========================================================================*/ *==========================================================================*/
import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import eva2.client.EvAClient;
import wsi.ra.tool.BasicResourceLoader; import wsi.ra.tool.BasicResourceLoader;
import eva2.client.EvAClient;
/** /**
@ -108,7 +110,7 @@ public class EVAHELP {
* *
*/ */
public static long getTimeStamp() { public static long getTimeStamp() {
return System.currentTimeMillis() -m_TimeStamp; return System.currentTimeMillis() - m_TimeStamp;
} }
/** /**
* *
@ -126,15 +128,18 @@ public class EVAHELP {
* *
*/ */
public static String getSystemPropertyString() { public static String getSystemPropertyString() {
String ret = ""; StringBuffer sBuf = new StringBuffer();
Properties prop = System.getProperties(); Properties prop = System.getProperties();
Enumeration list = prop.propertyNames(); Enumeration<?> list = prop.propertyNames();
while (list.hasMoreElements()) { while (list.hasMoreElements()) {
Object o = list.nextElement(); Object o = list.nextElement();
//System.out.println("o="+o.toString()); //System.out.println("o="+o.toString());
ret = ret + o.toString() + " = " +System.getProperty(o.toString()) +"\n"; sBuf.append(o.toString());
sBuf.append(" = ");
sBuf.append(System.getProperty(o.toString()));
sBuf.append("\n");
} }
return ret; return sBuf.toString();
} }
/** /**
* *
@ -159,4 +164,33 @@ public class EVAHELP {
freeM = (long)(freeM /1024); freeM = (long)(freeM /1024);
//System.out.println("after gc:Available memory : "+freeM+" bytes"); //System.out.println("after gc:Available memory : "+freeM+" bytes");
} }
/**
* Log a String to a log-file indicated by the file name.
* If the file exists, the String is appended.
*
* @param msg
* @param fileName
*/
public static void logString(String msg, String fileName) {
File f = new File(fileName);
try {
BufferedWriter bW = new BufferedWriter(new PrintWriter(new FileOutputStream(f, f.exists())));
bW.write(msg);
bW.close();
} catch (Exception ex) {
System.err.println("couldnt log to destination " + fileName + ": " + ex.getMessage());
}
}
/**
* Deletes the given file in the current directory. If the file does not exist,
* nothing happens.
*
* @param fileName
*/
public static void clearLog(String fileName) {
File f = new File(fileName);
if (f.exists()) f.delete();
}
} }

View File

@ -266,7 +266,7 @@ public class BasicResourceLoader implements ResourceLoader
*/ */
public static void fillLine(double[][] dest, int lineCnt, String[] entries, int[] cols) { public static void fillLine(double[][] dest, int lineCnt, String[] entries, int[] cols) {
if (((cols == null) && (dest[lineCnt].length != entries.length)) || (cols != null && (dest[lineCnt].length != cols.length))) { if (((cols == null) && (dest[lineCnt].length != entries.length)) || (cols != null && (dest[lineCnt].length != cols.length))) {
System.err.println("error, array dimensions dont match! (SIFTComparisonMatrix"); System.err.println("error, array dimensions dont match! (BasicResourceLoader)");
} }
if (cols == null) { if (cols == null) {
for (int i=0; i<entries.length; i++) { for (int i=0; i<entries.length; i++) {