diff --git a/src/eva2/OptimizerFactory.java b/src/eva2/OptimizerFactory.java index 7f56fe29..8470dba6 100644 --- a/src/eva2/OptimizerFactory.java +++ b/src/eva2/OptimizerFactory.java @@ -158,7 +158,6 @@ public class OptimizerFactory { es.setLambda(50); es.setPlusStrategy(false); - // TODO improve this by adding getEAIndividual to AbstractEAIndividual? AbstractEAIndividual indyTemplate = problem.getIndividualTemplate(); if ((indyTemplate != null) && (indyTemplate instanceof InterfaceESIndividual)) { diff --git a/src/eva2/client/EvAClient.java b/src/eva2/client/EvAClient.java index c0d5de24..0d1adfd0 100644 --- a/src/eva2/client/EvAClient.java +++ b/src/eva2/client/EvAClient.java @@ -83,6 +83,7 @@ public class EvAClient implements RemoteStateListener, Serializable { public static boolean TRACE = false; private static String m_ProductName = "EvA 2"; + private static String m_ProductLongName = "Evolutionary Algorithms Workbench 2"; // private int PREFERRED_WIDTH = 680; // private int PREFERRED_HEIGHT = 550; public JEFrame m_Frame; @@ -654,9 +655,12 @@ public class EvAClient implements RemoteStateListener, Serializable { private void showAboutDialog() { JOptionPane.showMessageDialog (m_Frame, - m_ProductName + - "\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 " + - EvAServer.Version + " \n http://www.ra.cs.uni-tuebingen.de/software/EvA2", infoTitle, 1); + m_ProductName + " - " + m_ProductLongName + + "\n University of Tuebingen\n Computer Architecture\n " + + "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() { diff --git a/src/eva2/server/EvAServer.java b/src/eva2/server/EvAServer.java index 2270fa05..d040f2a6 100644 --- a/src/eva2/server/EvAServer.java +++ b/src/eva2/server/EvAServer.java @@ -29,8 +29,8 @@ import java.net.InetAddress; * */ public class EvAServer { - /* Version string of the server application. */ - public static final String Version = new String ("2.00"); + /* Main version string of the EvA2 application. Change for minor releases, please.*/ + public static final String Version = new String ("2.02"); public static boolean TRACE = false; /* MainAdapterImp object. This is need for the first connection between the server and the client program. */ diff --git a/src/eva2/server/go/individuals/AbstractEAIndividual.java b/src/eva2/server/go/individuals/AbstractEAIndividual.java index b6ab73c1..78222638 100644 --- a/src/eva2/server/go/individuals/AbstractEAIndividual.java +++ b/src/eva2/server/go/individuals/AbstractEAIndividual.java @@ -3,7 +3,6 @@ package eva2.server.go.individuals; import java.util.ArrayList; import java.util.BitSet; -import java.util.LinkedList; import java.util.List; import wsi.ra.math.RNG; @@ -42,8 +41,11 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. private long m_ID = 0; private static long m_IDcounter = 0; - private int logParentLen = 10; - private LinkedList heritage = null; +// private int logParentLen = 10; + 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]; private double m_ConstraintViolation = 0; @@ -114,7 +116,12 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. m_ConstraintViolation = individual.m_ConstraintViolation; m_AreaConst4ParallelViolated = individual.m_AreaConst4ParallelViolated; m_Marked = individual.m_Marked; - if (individual.heritage != null) heritage = new LinkedList(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 0) { + if (logParents) { for (int i = 0; i < result.length; i++) { result[i].setParents(this, partners); } @@ -271,7 +278,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. for (int i = 0; i < partners.size(); i++) { result[i+1] = (AbstractEAIndividual) ((AbstractEAIndividual)partners.get(i)).clone(); } - if (logParentLen > 0) { + if (logParents) { result[0].setParent(this); for (int i = 0; i < partners.size(); i++) { result[i+1].setParent(partners.getEAIndividual(i)); @@ -284,59 +291,101 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. return result; } - /** - * 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 - * set it to 0 to deactivate heritage logging. - * - * @param logPs - */ - public void setLogHeritagetLen(int logLen) { - logParentLen = logLen; - } +// /** +// * 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 +// * set it to 0 to deactivate heritage logging. +// * +// * @param logPs +// */ +// public void setLogHeritagetLen(int logLen) { +// logParentLen = logLen; +// } /** * Add an ancestor generation with multiple parents. * * @param parents */ - private void setParents(AbstractEAIndividual parent, Population parents) { - if (heritage == null) heritage = new LinkedList(); - Long[] parentIDs = new Long[1+parents.size()]; + protected void setParents(AbstractEAIndividual parent, Population parents) { + int parentCnt = (parents == null) ? 1 : (1+parents.size()); + parentIDs = new Long[parentCnt]; + parentTree = new AbstractEAIndividual[parentCnt]; parentIDs[0] = parent.getIndyID(); - for (int i=0; i 0)) { + for (int i=0; i logParentLen) heritage.remove(0); + /** + * Add an ancestor list with multiple parents. + * + * @param parents + */ + public void setParents(List 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 0) && (parentTree != null)) { + sb.append("[ "); + for (int i=0; i logParentLen) heritage.remove(0); +// } + /** * Add an ancestor generation with only one parent. * * @param parent */ protected void setParent(AbstractEAIndividual parent) { - if (heritage == null) heritage = new LinkedList(); - Long[] parentID = new Long[1]; - parentID[0] = parent.getIndyID(); - addHeritage(parentID); + setParents(parent, null); } - public List getHeritageList() { - return heritage; + public Long[] getParentIDs() { + return parentIDs; } - /** - * 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 - */ - public Long[] getHeritage() { - if (heritage != null) return heritage.getLast(); - else return null; - } +// /** +// * 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 +// */ +// public Long[] getHeritage() { +// if (heritage != null) return heritage.getLast(); +// else return null; +// } /** This method will allow you to get the current age of an individual * Zero means it has not even been evaluated. @@ -757,7 +806,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. sb.append(", ID: "); sb.append(individual.getIndyID()); sb.append(", parents: "); - sb.append(BeanInspector.toString(individual.getHeritage())); + sb.append(BeanInspector.toString(individual.getParentIDs())); return sb.toString(); } diff --git a/src/eva2/server/go/populations/Population.java b/src/eva2/server/go/populations/Population.java index 76fa86d7..cfdf8ebe 100644 --- a/src/eva2/server/go/populations/Population.java +++ b/src/eva2/server/go/populations/Population.java @@ -581,13 +581,13 @@ public class Population extends ArrayList implements PopulationInterface, Clonea return idList; } - public Long[][] getParentalIDList() { - Long[][] idList = new Long[size()][]; - for (int i=0; i0)) { solSet = new double[pop.size()][]; for (int i=0; i newSpecies = new ArrayList(); @@ -589,7 +608,10 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis if (TRACE) System.out.println("Population size: " + this.m_Population.size()); // if (TRACE) { // 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"); } @@ -615,16 +637,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis spec.clear(); 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. * @param source The source of the event. diff --git a/src/eva2/server/go/strategies/DifferentialEvolution.java b/src/eva2/server/go/strategies/DifferentialEvolution.java index 8488738b..a2f9d470 100644 --- a/src/eva2/server/go/strategies/DifferentialEvolution.java +++ b/src/eva2/server/go/strategies/DifferentialEvolution.java @@ -1,5 +1,8 @@ package eva2.server.go.strategies; +import java.util.Vector; + +import wsi.ra.math.RNG; import eva2.server.go.InterfacePopulationChangedEventListener; import eva2.server.go.individuals.AbstractEAIndividual; 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.F1Problem; import eva2.server.go.problems.InterfaceOptimizationProblem; -import wsi.ra.math.RNG; import eva2.tools.EVAERROR; +import eva2.tools.Pair; import eva2.tools.SelectedTag; -import eva2.tools.Tag; /** 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 @@ -34,6 +36,9 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial private double m_Lambda = 0.6; private double m_Mt = 0.05; private int maximumAge = -1; + // to log the parents of a newly created indy. + private boolean doLogParents = false; // TODO deactivate for better performance + private Vector parents = null; private String m_Identifier = ""; 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 should make sure that the delta is not zero. + * This method returns a difference vector between two random individuals from the population. + * This method should make sure that delta is not zero. * * @param pop The population to choose from * @return The delta vector @@ -111,12 +116,17 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial boolean isEmpty; int iterations = 0; - x1 = getRandomGenotype(pop); + AbstractEAIndividual x1Indy = getRandomIndy(pop); + x1 = getGenotype(x1Indy); + + if (parents != null) parents.add(x1Indy); result = new double[x1.length]; isEmpty = true; + AbstractEAIndividual x2Indy = null; while (isEmpty && (iterations < pop.size())) { - x2 = getRandomGenotype(pop); + x2Indy = getRandomIndy(pop); + x2 = getGenotype(x2Indy); for (int i = 0; i < x1.length; i++) { result[i] = x1[i] - x2[i]; @@ -124,13 +134,18 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial } 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++) { if (RNG.flipCoin(1/(double)x1.length)) result[i] = 0.01*RNG.gaussianDouble(0.1); else result[i] = 0; isEmpty = (isEmpty && (result[i]==0)); } + // single parent! dont add another one } return result; @@ -144,21 +159,26 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial * @return the delta vector */ private double[] fetchDeltaBest(Population pop, InterfaceESIndividual indy) { - double[] x1, xb, result; + double[] x1, result; + AbstractEAIndividual xbIndy; + x1 = indy.getDGenotype(); result = new double[x1.length]; if (m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) { // implements MODE for the multi-objective case: a dominating individual is selected for difference building Population domSet = pop.getDominatingSet((AbstractEAIndividual)indy); if (domSet.size() > 0) { - xb = getRandomGenotype(domSet); + xbIndy = getRandomIndy(domSet); } else { return result; // just return a zero vector. this will happen automatically if domSet contains only the individual itself } } 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++) { result[i] = xb[i] - x1[i]; } @@ -190,23 +210,29 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial * @return AbstractEAIndividual */ public AbstractEAIndividual generateNewIndividual(Population pop) { + int firstParentIndex; AbstractEAIndividual indy; - InterfaceESIndividual endy; + InterfaceESIndividual esIndy; + if (doLogParents) parents = new Vector(); + else parents = null; try { - indy = (AbstractEAIndividual)(pop.getEAIndividual(RNG.randomInt(0, pop.size()-1))).getClone(); - endy = (InterfaceESIndividual)indy; + // select one random indy as starting individual. its a parent in any case. + firstParentIndex = RNG.randomInt(0, pop.size()-1); + indy = (AbstractEAIndividual)(pop.getEAIndividual(firstParentIndex)).getClone(); + esIndy = (InterfaceESIndividual)indy; } catch (java.lang.ClassCastException e) { System.err.println("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); return (AbstractEAIndividual)((AbstractEAIndividual)pop.get(RNG.randomInt(0, pop.size()-1))).getClone(); } double[] nX, vX, oX; - oX = endy.getDGenotype(); - vX = endy.getDGenotype(); + oX = esIndy.getDGenotype(); + vX = esIndy.getDGenotype(); nX = new double[oX.length]; switch (this.m_DEType.getSelectedTag().getID()) { case 0 : { // this is DE1 or DE/rand/1 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++) { vX[i] = oX[i] + this.m_F*delta[i]; } @@ -215,7 +241,8 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial case 1 : { // this is DE2 or DE/current-to-best/1 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++) { 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: { // DE/best/2 - oX = getBestGenotype(pop); - double[] delta1 = this.fetchDeltaRandom(pop); + AbstractEAIndividual bestIndy = getBestIndy(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); for (int i = 0; i < oX.length; 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 : { // this is trigonometric mutation + if (parents != null) parents.add(pop.getEAIndividual(firstParentIndex)); // Add wherever oX is used directly if (RNG.flipCoin(this.m_Mt)) { - double[] xj, xk, xl; xj = oX; + double[] xk, xl; double p, pj, pk, pl; InterfaceESIndividual indy1 = null, indy2 = null; try { // and i got indy! indy1 = (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) { EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); } xk = indy1.getDGenotype(); xl = indy2.getDGenotype(); - p = Math.abs(((AbstractEAIndividual)endy).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy1).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy2).getFitness(0)); - pj = Math.abs(((AbstractEAIndividual)endy).getFitness(0))/p; + p = Math.abs(((AbstractEAIndividual)esIndy).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy1).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy2).getFitness(0)); + pj = Math.abs(((AbstractEAIndividual)esIndy).getFitness(0))/p; pk = Math.abs(((AbstractEAIndividual)indy1).getFitness(0))/p; pl = Math.abs(((AbstractEAIndividual)indy2).getFitness(0))/p; 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 { // this is DE1 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++) { 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 - endy.SetDGenotype(nX); + esIndy.SetDGenotype(nX); indy.SetAge(0); double[] fit = new double[1]; fit[0] = 0; indy.SetFitness(fit); + if (parents != null) indy.setParents(parents); return indy; } - private double[] getBestGenotype(Population pop) { + private AbstractEAIndividual getBestIndy(Population pop) { double[] xb; - try { - 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; + return (AbstractEAIndividual)pop.getBestIndividual(); } - private double[] getRandomGenotype(Population pop) { + private AbstractEAIndividual getRandomIndy(Population pop) { double[] x1; + int randIndex = RNG.randomInt(0, pop.size()-1); + return pop.getEAIndividual(randIndex); + } + + private double[] getGenotype(AbstractEAIndividual indy) { try { - x1 = ((InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1))).getDGenotype(); + return ((InterfaceESIndividual)indy).getDGenotype(); } catch (java.lang.ClassCastException e) { - System.err.println("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); - return new double[1]; - } - return x1; + EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); + return null; + } } public void optimize() { diff --git a/src/eva2/server/go/strategies/EvolutionStrategies.java b/src/eva2/server/go/strategies/EvolutionStrategies.java index 150be548..56e9ee11 100644 --- a/src/eva2/server/go/strategies/EvolutionStrategies.java +++ b/src/eva2/server/go/strategies/EvolutionStrategies.java @@ -1,5 +1,6 @@ package eva2.server.go.strategies; +import eva2.gui.BeanInspector; import eva2.server.go.InterfacePopulationChangedEventListener; import eva2.server.go.individuals.AbstractEAIndividual; import eva2.server.go.operators.mutation.MutateESSuccessRule; @@ -54,7 +55,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ setMu(mu); setLambda(lambda); setPlusStrategy(usePlus); - this.m_Population.setPopulationSize(this.m_Lambda); + this.checkPopulationConstraints(); } public EvolutionStrategies(EvolutionStrategies a) { @@ -76,7 +77,6 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ public void init() { // @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(); // if (this.m_InitialPopulationSize > orgPopSize) { // 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.m_Population.setPopulationSize(orgPopSize); 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"; } - /** 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. * @return The population of current solutions to a given problem. */ diff --git a/src/eva2/server/go/strategies/ParticleSwarmOptimization.java b/src/eva2/server/go/strategies/ParticleSwarmOptimization.java index 273be786..d3281170 100644 --- a/src/eva2/server/go/strategies/ParticleSwarmOptimization.java +++ b/src/eva2/server/go/strategies/ParticleSwarmOptimization.java @@ -17,6 +17,7 @@ import eva2.server.go.problems.F1Problem; import eva2.server.go.problems.Interface2DBorderProblem; import eva2.server.go.problems.InterfaceOptimizationProblem; import wsi.ra.math.RNG; +import eva2.tools.EVAERROR; import eva2.tools.SelectedTag; import wsi.ra.chart2d.DPoint; @@ -444,6 +445,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se protected void resetIndividual(AbstractEAIndividual indy) { if (indy instanceof InterfaceESIndividual) { + indy.setParents(null); InterfaceESIndividual endy = (InterfaceESIndividual) indy; endy.defaultInit(); 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; } } 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!"); } } diff --git a/src/eva2/server/modules/Processor.java b/src/eva2/server/modules/Processor.java index a0e2550e..8c9195b7 100644 --- a/src/eva2/server/modules/Processor.java +++ b/src/eva2/server/modules/Processor.java @@ -16,6 +16,7 @@ import eva2.server.stat.InterfaceStatistics; import eva2.server.stat.InterfaceTextListener; import eva2.server.stat.StatisticsWithGUI; import eva2.tools.EVAERROR; +import eva2.tools.EVAHELP; import wsi.ra.jproxy.RemoteStateListener; /** @@ -179,6 +180,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo goParams.getOptimizer().addPopulationChangedEventListener(this); runCounter = 0; + String popLog = null; //"populationLog.txt"; while (isOptRunning() && (runCounter list = prop.propertyNames(); while (list.hasMoreElements()) { Object o = list.nextElement(); //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); //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(); + } } \ No newline at end of file diff --git a/src/wsi/ra/tool/BasicResourceLoader.java b/src/wsi/ra/tool/BasicResourceLoader.java index f0d0decc..de2baa22 100644 --- a/src/wsi/ra/tool/BasicResourceLoader.java +++ b/src/wsi/ra/tool/BasicResourceLoader.java @@ -266,7 +266,7 @@ public class BasicResourceLoader implements ResourceLoader */ 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))) { - System.err.println("error, array dimensions dont match! (SIFTComparisonMatrix"); + System.err.println("error, array dimensions dont match! (BasicResourceLoader)"); } if (cols == null) { for (int i=0; i