Without any loss of functionality, JE2Base can now also be compiled with Java 1.5.
This commit is contained in:
		@@ -6,190 +6,225 @@ import eva2.server.go.populations.Population;
 | 
			
		||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
 | 
			
		||||
import eva2.tools.math.Jama.Matrix;
 | 
			
		||||
 | 
			
		||||
public class MutateESCovarianceMatrixAdaptionPlus extends MutateESCovarianceMatrixAdaption implements InterfaceMutationGenerational 
 | 
			
		||||
{
 | 
			
		||||
public class MutateESCovarianceMatrixAdaptionPlus extends
 | 
			
		||||
		MutateESCovarianceMatrixAdaption implements
 | 
			
		||||
		InterfaceMutationGenerational {
 | 
			
		||||
	protected double m_psuccess;
 | 
			
		||||
	protected double m_cp;
 | 
			
		||||
	protected double m_psuccesstarget=0.44;
 | 
			
		||||
	protected double m_psuccesstarget = 0.44;
 | 
			
		||||
	protected double m_stepd;
 | 
			
		||||
	protected double m_pthresh;
 | 
			
		||||
	protected int m_lambda=1;
 | 
			
		||||
	protected int m_lambda = 1;
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	public MutateESCovarianceMatrixAdaptionPlus() {
 | 
			
		||||
		super();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	public MutateESCovarianceMatrixAdaptionPlus(MutateESCovarianceMatrixAdaptionPlus mutator) {
 | 
			
		||||
 | 
			
		||||
	public MutateESCovarianceMatrixAdaptionPlus(
 | 
			
		||||
			MutateESCovarianceMatrixAdaptionPlus mutator) {
 | 
			
		||||
		super(mutator);
 | 
			
		||||
		m_psuccess=mutator.m_psuccess;
 | 
			
		||||
		m_cp=mutator.m_cp;
 | 
			
		||||
		m_psuccesstarget=mutator.m_psuccesstarget;
 | 
			
		||||
		m_lambda=mutator.m_lambda;
 | 
			
		||||
		m_pthresh=mutator.m_pthresh;
 | 
			
		||||
		m_stepd=mutator.m_stepd;
 | 
			
		||||
		m_psuccess = mutator.m_psuccess;
 | 
			
		||||
		m_cp = mutator.m_cp;
 | 
			
		||||
		m_psuccesstarget = mutator.m_psuccesstarget;
 | 
			
		||||
		m_lambda = mutator.m_lambda;
 | 
			
		||||
		m_pthresh = mutator.m_pthresh;
 | 
			
		||||
		m_stepd = mutator.m_stepd;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/** This method will enable you to clone a given mutation operator
 | 
			
		||||
	/**
 | 
			
		||||
	 * This method will enable you to clone a given mutation operator
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @return The clone
 | 
			
		||||
	 */
 | 
			
		||||
	 public Object clone() {
 | 
			
		||||
	public Object clone() {
 | 
			
		||||
		return new MutateESCovarianceMatrixAdaptionPlus(this);
 | 
			
		||||
	 }
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * This method allows you to init the mutation operator
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param individual
 | 
			
		||||
	 *            The individual that will be mutated.
 | 
			
		||||
	 * @param opt
 | 
			
		||||
	 *            The optimization problem.
 | 
			
		||||
	 */
 | 
			
		||||
	public void init(AbstractEAIndividual individual,
 | 
			
		||||
			InterfaceOptimizationProblem opt) {
 | 
			
		||||
 | 
			
		||||
	 /** This method allows you to init the mutation operator
 | 
			
		||||
	  * @param individual        The individual that will be mutated.
 | 
			
		||||
	  * @param opt               The optimization problem.
 | 
			
		||||
	  */
 | 
			
		||||
	 public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
 | 
			
		||||
		 
 | 
			
		||||
		 if (!(individual instanceof InterfaceESIndividual)) return;
 | 
			
		||||
		 super.init(individual,opt);
 | 
			
		||||
		 m_psuccesstarget=1.0/(5+Math.sqrt(m_lambda)/2);
 | 
			
		||||
		 m_psuccess=m_psuccesstarget;
 | 
			
		||||
		 m_stepd=1.0+m_D/(2.0*m_lambda);
 | 
			
		||||
		 m_cp=m_psuccesstarget*m_lambda/(2+m_psuccesstarget*m_lambda);
 | 
			
		||||
		 m_c=2.0/(2.0+m_D);
 | 
			
		||||
		 this.cov            = 2.0/(6.0+Math.pow(m_D, 2)); //ATTN: differs from the standard CMA-ES
 | 
			
		||||
		 m_pthresh=0.44;
 | 
			
		||||
		if (!(individual instanceof InterfaceESIndividual))
 | 
			
		||||
			return;
 | 
			
		||||
		super.init(individual, opt);
 | 
			
		||||
		m_psuccesstarget = 1.0 / (5 + Math.sqrt(m_lambda) / 2);
 | 
			
		||||
		m_psuccess = m_psuccesstarget;
 | 
			
		||||
		m_stepd = 1.0 + m_D / (2.0 * m_lambda);
 | 
			
		||||
		m_cp = m_psuccesstarget * m_lambda / (2 + m_psuccesstarget * m_lambda);
 | 
			
		||||
		m_c = 2.0 / (2.0 + m_D);
 | 
			
		||||
		this.cov = 2.0 / (6.0 + Math.pow(m_D, 2)); // ATTN: differs from the
 | 
			
		||||
													// standard CMA-ES
 | 
			
		||||
		m_pthresh = 0.44;
 | 
			
		||||
 | 
			
		||||
	 }
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected void adaptStrategyGen(AbstractEAIndividual child,
 | 
			
		||||
			AbstractEAIndividual parent) {
 | 
			
		||||
		if (child.getFitness(0) <= parent.getFitness(0)) {
 | 
			
		||||
			// updatecov
 | 
			
		||||
			updateCovariance(child, parent);
 | 
			
		||||
			// updateCovariance();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	 protected void adaptStrategyGen(AbstractEAIndividual child,AbstractEAIndividual parent) {
 | 
			
		||||
		 if(child.getFitness(0)<=parent.getFitness(0)){
 | 
			
		||||
			 //updatecov
 | 
			
		||||
			 updateCovariance(child, parent);
 | 
			
		||||
			 //updateCovariance();
 | 
			
		||||
		 }
 | 
			
		||||
 | 
			
		||||
	 }
 | 
			
		||||
	 
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param parent
 | 
			
		||||
	 * @param child
 | 
			
		||||
	 */
 | 
			
		||||
	public void updateCovariance(AbstractEAIndividual child,AbstractEAIndividual parent) {
 | 
			
		||||
		double[] step=new double[m_D]; 
 | 
			
		||||
		for(int i=0;i<m_D;i++){
 | 
			
		||||
			 step[i]=((InterfaceESIndividual)parent).getDGenotype()[i]-((InterfaceESIndividual)child).getDGenotype()[i];			 
 | 
			
		||||
		 }
 | 
			
		||||
		updateCovariance(step);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void updateCovariance() {
 | 
			
		||||
		double[] step=new double[m_D]; 
 | 
			
		||||
		for(int i=0;i<m_D;i++){
 | 
			
		||||
			 step[i]=Bz[i];
 | 
			
		||||
	public void updateCovariance(AbstractEAIndividual child,
 | 
			
		||||
			AbstractEAIndividual parent) {
 | 
			
		||||
		double[] step = new double[m_D];
 | 
			
		||||
		for (int i = 0; i < m_D; i++) {
 | 
			
		||||
			step[i] = ((InterfaceESIndividual) parent).getDGenotype()[i]
 | 
			
		||||
					- ((InterfaceESIndividual) child).getDGenotype()[i];
 | 
			
		||||
		}
 | 
			
		||||
		updateCovariance(step);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void updateCovariance() {
 | 
			
		||||
		double[] step = new double[m_D];
 | 
			
		||||
		for (int i = 0; i < m_D; i++) {
 | 
			
		||||
			step[i] = Bz[i];
 | 
			
		||||
		}
 | 
			
		||||
		updateCovariance(step);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param step
 | 
			
		||||
	 * 
 | 
			
		||||
	 */
 | 
			
		||||
	public void updateCovariance(double[] step) {
 | 
			
		||||
		for(int i=0;i<m_D;i++){
 | 
			
		||||
			 if(m_psuccess<m_pthresh){
 | 
			
		||||
				 m_PathS[i]=(1.0-m_c)*m_PathS[i]+Math.sqrt(m_c*(2.0-m_c))*(step[i])/m_SigmaGlobal;
 | 
			
		||||
			 }else{
 | 
			
		||||
				 m_PathS[i]=(1.0-m_c)*m_PathS[i];
 | 
			
		||||
			 }
 | 
			
		||||
		for (int i = 0; i < m_D; i++) {
 | 
			
		||||
			if (m_psuccess < m_pthresh) {
 | 
			
		||||
				m_PathS[i] = (1.0 - m_c) * m_PathS[i]
 | 
			
		||||
						+ Math.sqrt(m_c * (2.0 - m_c)) * (step[i])
 | 
			
		||||
						/ m_SigmaGlobal;
 | 
			
		||||
			} else {
 | 
			
		||||
				m_PathS[i] = (1.0 - m_c) * m_PathS[i];
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		 }
 | 
			
		||||
		 if(m_psuccess<m_pthresh){
 | 
			
		||||
			 m_C=m_C.multi((1.0-cov));
 | 
			
		||||
			 m_C.plusEquals(Matrix.outer(m_PathS, m_PathS).multi(cov));
 | 
			
		||||
		 }else{
 | 
			
		||||
			 m_C=m_C.multi((1.0-cov)).plus(
 | 
			
		||||
					 (Matrix.outer(m_PathS, m_PathS).plus(
 | 
			
		||||
							 m_C.multi(m_c*(2.0-m_c))
 | 
			
		||||
					 ).multi(cov))
 | 
			
		||||
			 );
 | 
			
		||||
		 }
 | 
			
		||||
		}
 | 
			
		||||
		if (m_psuccess < m_pthresh) {
 | 
			
		||||
			m_C = m_C.multi((1.0 - cov));
 | 
			
		||||
			m_C.plusEquals(Matrix.outer(m_PathS, m_PathS).multi(cov));
 | 
			
		||||
		} else {
 | 
			
		||||
			m_C = m_C.multi((1.0 - cov)).plus(
 | 
			
		||||
					(Matrix.outer(m_PathS, m_PathS).plus(
 | 
			
		||||
							m_C.multi(m_c * (2.0 - m_c))).multi(cov)));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	 protected void adaptStrategy() {
 | 
			
		||||
	 }
 | 
			
		||||
 | 
			
		||||
	 public int getM_lambda() {
 | 
			
		||||
		 return m_lambda;
 | 
			
		||||
	 }
 | 
			
		||||
	protected void adaptStrategy() {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	 public void setM_lambda(int mLambda) {
 | 
			
		||||
		 m_lambda = mLambda;
 | 
			
		||||
	 }
 | 
			
		||||
	public int getM_lambda() {
 | 
			
		||||
		return m_lambda;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setM_lambda(int mLambda) {
 | 
			
		||||
		m_lambda = mLambda;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	 @Override
 | 
			
		||||
	 public void crossoverOnStrategyParameters(AbstractEAIndividual indy1,
 | 
			
		||||
			 Population partners) {
 | 
			
		||||
		 // ATTN: Crossover is not defined for this 
 | 
			
		||||
		 
 | 
			
		||||
	 }
 | 
			
		||||
	 
 | 
			
		||||
	 @Override
 | 
			
		||||
	 public void adaptAfterSelection(Population oldPop, Population selectedPop) {
 | 
			
		||||
		 // TODO Auto-generated method stub
 | 
			
		||||
	@Override
 | 
			
		||||
	public void crossoverOnStrategyParameters(AbstractEAIndividual indy1,
 | 
			
		||||
			Population partners) {
 | 
			
		||||
		// ATTN: Crossover is not defined for this
 | 
			
		||||
 | 
			
		||||
	 }
 | 
			
		||||
	 
 | 
			
		||||
	 @Override
 | 
			
		||||
	 public void adaptGenerational(Population selectedPop, Population parentPop, Population newPop, boolean updateSelected) {
 | 
			
		||||
		 double rate = 0.;
 | 
			
		||||
		 for (int i = 0; i < parentPop.size(); i++) {
 | 
			
		||||
			 // calculate success rate
 | 
			
		||||
			 //            System.out.println("new fit / old fit: " + BeanInspector.toString(newPop.getEAIndividual(i).getFitness()) + " , " + BeanInspector.toString(parentPop.getEAIndividual(i).getFitness()));
 | 
			
		||||
			 if (newPop.getEAIndividual(i).getFitness(0) < parentPop.getEAIndividual(i).getFitness(0)) rate++;
 | 
			
		||||
		 }
 | 
			
		||||
		 rate = rate / parentPop.size(); 
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		 if (updateSelected) for (int i = 0; i < selectedPop.size(); i++) { // applied to the old population as well in case of plus strategy
 | 
			
		||||
			 MutateESCovarianceMatrixAdaptionPlus mutator =  (MutateESCovarianceMatrixAdaptionPlus)((AbstractEAIndividual)selectedPop.get(i)).getMutationOperator();
 | 
			
		||||
			 updateMutator(rate, mutator);
 | 
			
		||||
			 if(selectedPop.getEAIndividual(i).getFitness(0)<=parentPop.getEAIndividual(0).getFitness(0)){
 | 
			
		||||
				 mutator.adaptStrategyGen(selectedPop.getEAIndividual(i),parentPop.getEAIndividual(0));
 | 
			
		||||
			 }
 | 
			
		||||
			 //            System.out.println("old pop step size " + mutator.getSigma()+ " (" + mutator+ ")");
 | 
			
		||||
		 }
 | 
			
		||||
		 for (int i = 0; i < newPop.size(); i++) {
 | 
			
		||||
			 MutateESCovarianceMatrixAdaptionPlus mutator =  (MutateESCovarianceMatrixAdaptionPlus)((AbstractEAIndividual)newPop.get(i)).getMutationOperator();
 | 
			
		||||
			 updateMutator(rate, mutator);
 | 
			
		||||
			 if(newPop.getEAIndividual(i).getFitness(0)<=parentPop.getEAIndividual(0).getFitness(0)){
 | 
			
		||||
				 mutator.adaptStrategyGen(newPop.getEAIndividual(i),parentPop.getEAIndividual(0));
 | 
			
		||||
			 }
 | 
			
		||||
			 //            System.out.println("new pop step size " + mutator.getSigma()+ " (" + mutator+ ")");
 | 
			
		||||
		 }
 | 
			
		||||
	 }
 | 
			
		||||
	// @Override
 | 
			
		||||
	public void adaptAfterSelection(Population oldPop, Population selectedPop) {
 | 
			
		||||
		// TODO Auto-generated method stub
 | 
			
		||||
 | 
			
		||||
	 private void updateMutator(double rate, MutateESCovarianceMatrixAdaptionPlus mutator) {
 | 
			
		||||
		 mutator.updateStepSize(rate);
 | 
			
		||||
	 }
 | 
			
		||||
	 public double getM_psuccess() {
 | 
			
		||||
		 return m_psuccess;
 | 
			
		||||
	 }
 | 
			
		||||
	 public void updateStepSize(double psuccess) {
 | 
			
		||||
		 this.m_psuccess=(1-m_cp)*m_psuccess+m_cp*psuccess;
 | 
			
		||||
		 m_SigmaGlobal=m_SigmaGlobal*Math.exp(1/m_stepd*(m_psuccess-m_psuccesstarget)/(1-m_psuccesstarget));
 | 
			
		||||
	 }
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	 public String getName() {
 | 
			
		||||
		 return "CMA mutation for plus Strategies";
 | 
			
		||||
	 }
 | 
			
		||||
	 /** This method returns a global info string
 | 
			
		||||
	  * @return description
 | 
			
		||||
	  */
 | 
			
		||||
	 public static String globalInfo() {
 | 
			
		||||
		 return "This is the CMA mutation according to Igel,Hansen,Roth 2007";
 | 
			
		||||
	 }
 | 
			
		||||
	 
 | 
			
		||||
	 @Override
 | 
			
		||||
	 public String getStringRepresentation() {
 | 
			
		||||
		 // TODO Auto-generated method stub
 | 
			
		||||
		 return "CMA-plus mutation";
 | 
			
		||||
	 }
 | 
			
		||||
	// @Override
 | 
			
		||||
	public void adaptGenerational(Population selectedPop, Population parentPop,
 | 
			
		||||
			Population newPop, boolean updateSelected) {
 | 
			
		||||
		double rate = 0.;
 | 
			
		||||
		for (int i = 0; i < parentPop.size(); i++) {
 | 
			
		||||
			// calculate success rate
 | 
			
		||||
			// System.out.println("new fit / old fit: " +
 | 
			
		||||
			// BeanInspector.toString(newPop.getEAIndividual(i).getFitness()) +
 | 
			
		||||
			// " , " +
 | 
			
		||||
			// BeanInspector.toString(parentPop.getEAIndividual(i).getFitness()));
 | 
			
		||||
			if (newPop.getEAIndividual(i).getFitness(0) < parentPop
 | 
			
		||||
					.getEAIndividual(i).getFitness(0))
 | 
			
		||||
				rate++;
 | 
			
		||||
		}
 | 
			
		||||
		rate = rate / parentPop.size();
 | 
			
		||||
 | 
			
		||||
		if (updateSelected)
 | 
			
		||||
			for (int i = 0; i < selectedPop.size(); i++) { // applied to the old
 | 
			
		||||
															// population as
 | 
			
		||||
															// well in case of
 | 
			
		||||
															// plus strategy
 | 
			
		||||
				MutateESCovarianceMatrixAdaptionPlus mutator = (MutateESCovarianceMatrixAdaptionPlus) ((AbstractEAIndividual) selectedPop
 | 
			
		||||
						.get(i)).getMutationOperator();
 | 
			
		||||
				updateMutator(rate, mutator);
 | 
			
		||||
				if (selectedPop.getEAIndividual(i).getFitness(0) <= parentPop
 | 
			
		||||
						.getEAIndividual(0).getFitness(0)) {
 | 
			
		||||
					mutator.adaptStrategyGen(selectedPop.getEAIndividual(i),
 | 
			
		||||
							parentPop.getEAIndividual(0));
 | 
			
		||||
				}
 | 
			
		||||
				// System.out.println("old pop step size " + mutator.getSigma()+
 | 
			
		||||
				// " (" + mutator+ ")");
 | 
			
		||||
			}
 | 
			
		||||
		for (int i = 0; i < newPop.size(); i++) {
 | 
			
		||||
			MutateESCovarianceMatrixAdaptionPlus mutator = (MutateESCovarianceMatrixAdaptionPlus) ((AbstractEAIndividual) newPop
 | 
			
		||||
					.get(i)).getMutationOperator();
 | 
			
		||||
			updateMutator(rate, mutator);
 | 
			
		||||
			if (newPop.getEAIndividual(i).getFitness(0) <= parentPop
 | 
			
		||||
					.getEAIndividual(0).getFitness(0)) {
 | 
			
		||||
				mutator.adaptStrategyGen(newPop.getEAIndividual(i), parentPop
 | 
			
		||||
						.getEAIndividual(0));
 | 
			
		||||
			}
 | 
			
		||||
			// System.out.println("new pop step size " + mutator.getSigma()+
 | 
			
		||||
			// " (" + mutator+ ")");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void updateMutator(double rate,
 | 
			
		||||
			MutateESCovarianceMatrixAdaptionPlus mutator) {
 | 
			
		||||
		mutator.updateStepSize(rate);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public double getM_psuccess() {
 | 
			
		||||
		return m_psuccess;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void updateStepSize(double psuccess) {
 | 
			
		||||
		this.m_psuccess = (1 - m_cp) * m_psuccess + m_cp * psuccess;
 | 
			
		||||
		m_SigmaGlobal = m_SigmaGlobal
 | 
			
		||||
				* Math.exp(1 / m_stepd * (m_psuccess - m_psuccesstarget)
 | 
			
		||||
						/ (1 - m_psuccesstarget));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getName() {
 | 
			
		||||
		return "CMA mutation for plus Strategies";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * This method returns a global info string
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @return description
 | 
			
		||||
	 */
 | 
			
		||||
	public static String globalInfo() {
 | 
			
		||||
		return "This is the CMA mutation according to Igel,Hansen,Roth 2007";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String getStringRepresentation() {
 | 
			
		||||
		// TODO Auto-generated method stub
 | 
			
		||||
		return "CMA-plus mutation";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -26,44 +26,39 @@ import eva2.server.go.populations.SolutionSet;
 | 
			
		||||
import eva2.server.go.problems.AbstractOptimizationProblem;
 | 
			
		||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import eva2.tools.math.Mathematics;
 | 
			
		||||
import eva2.tools.math.RNG;
 | 
			
		||||
import eva2.tools.math.Jama.EigenvalueDecomposition;
 | 
			
		||||
import eva2.tools.math.Jama.Matrix;
 | 
			
		||||
 | 
			
		||||
public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable
 | 
			
		||||
{
 | 
			
		||||
public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
 | 
			
		||||
 | 
			
		||||
	class CounterClass{
 | 
			
		||||
	class CounterClass {
 | 
			
		||||
		public CounterClass(int i) {
 | 
			
		||||
			value=i;
 | 
			
		||||
			value = i;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public int value;
 | 
			
		||||
		public boolean seen=false;
 | 
			
		||||
		public boolean seen = false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	private String m_Identifier = "NelderMeadSimplex";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	private Population m_Population;
 | 
			
		||||
	private AbstractOptimizationProblem m_Problem;
 | 
			
		||||
 | 
			
		||||
	transient private InterfacePopulationChangedEventListener m_Listener;
 | 
			
		||||
 | 
			
		||||
	private int m_lambda = 1;
 | 
			
		||||
	private int m_lambdamo=1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	private int m_lambdamo = 1;
 | 
			
		||||
 | 
			
		||||
	public MultiObjectiveCMAES() {
 | 
			
		||||
		m_Population=new Population(m_lambdamo);
 | 
			
		||||
		m_Population = new Population(m_lambdamo);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public MultiObjectiveCMAES(MultiObjectiveCMAES a) {
 | 
			
		||||
		m_Problem = (AbstractOptimizationProblem)a.m_Problem.clone();
 | 
			
		||||
		setPopulation((Population)a.m_Population.clone());
 | 
			
		||||
		m_Problem = (AbstractOptimizationProblem) a.m_Problem.clone();
 | 
			
		||||
		setPopulation((Population) a.m_Population.clone());
 | 
			
		||||
		m_lambda = a.m_lambda;
 | 
			
		||||
		m_Identifier = a.m_Identifier;
 | 
			
		||||
	}
 | 
			
		||||
@@ -72,161 +67,182 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable
 | 
			
		||||
		return new MultiObjectiveCMAES(this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public void SetIdentifier(String name) {
 | 
			
		||||
		m_Identifier=name;
 | 
			
		||||
		m_Identifier = name;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public void SetProblem(InterfaceOptimizationProblem problem) {
 | 
			
		||||
		m_Problem = (AbstractOptimizationProblem)problem;
 | 
			
		||||
		m_Problem = (AbstractOptimizationProblem) problem;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/** This method allows you to add the LectureGUI as listener to the Optimizer
 | 
			
		||||
	/**
 | 
			
		||||
	 * This method allows you to add the LectureGUI as listener to the Optimizer
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param ea
 | 
			
		||||
	 */
 | 
			
		||||
	public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
 | 
			
		||||
	public void addPopulationChangedEventListener(
 | 
			
		||||
			InterfacePopulationChangedEventListener ea) {
 | 
			
		||||
		this.m_Listener = ea;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public void freeWilly() {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public InterfaceSolutionSet getAllSolutions() {
 | 
			
		||||
		Population pop = getPopulation();
 | 
			
		||||
		return new SolutionSet(pop, pop);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public String getIdentifier() {
 | 
			
		||||
 | 
			
		||||
		return m_Identifier;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public String getName() {
 | 
			
		||||
		return "(1+"+m_lambda+") MO-CMA-ES";
 | 
			
		||||
		return "(1+" + m_lambda + ") MO-CMA-ES";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public Population getPopulation() {
 | 
			
		||||
		return m_Population;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public InterfaceOptimizationProblem getProblem() {
 | 
			
		||||
		return m_Problem;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public String getStringRepresentation() {
 | 
			
		||||
		StringBuilder strB = new StringBuilder(200);
 | 
			
		||||
		strB.append("(1+"+m_lambda+") MO-CMA-ES:\nOptimization Problem: ");
 | 
			
		||||
		strB.append("(1+" + m_lambda + ") MO-CMA-ES:\nOptimization Problem: ");
 | 
			
		||||
		strB.append(this.m_Problem.getStringRepresentationForProblem(this));
 | 
			
		||||
		strB.append("\n");
 | 
			
		||||
		strB.append(this.m_Population.getStringRepresentation());
 | 
			
		||||
		return strB.toString();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public void init() {
 | 
			
		||||
		//initByPopulation(m_Population, true);
 | 
			
		||||
		// initByPopulation(m_Population, true);
 | 
			
		||||
		this.m_Population.setTargetSize(m_lambdamo);
 | 
			
		||||
		this.m_Problem.initPopulation(this.m_Population);
 | 
			
		||||
		//	        children = new Population(m_Population.size());
 | 
			
		||||
		// children = new Population(m_Population.size());
 | 
			
		||||
		this.evaluatePopulation(this.m_Population);
 | 
			
		||||
		this.firePropertyChangedEvent(Population.nextGenerationPerformed);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public void initByPopulation(Population pop, boolean reset) {
 | 
			
		||||
		setPopulation(pop);
 | 
			
		||||
		if (reset) {
 | 
			
		||||
			m_Problem.initPopulation(m_Population);
 | 
			
		||||
			m_Problem.evaluate(m_Population);
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/** This method will evaluate the current population using the
 | 
			
		||||
	 * given problem.
 | 
			
		||||
	 * @param population The population that is to be evaluated
 | 
			
		||||
	/**
 | 
			
		||||
	 * This method will evaluate the current population using the given problem.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param population
 | 
			
		||||
	 *            The population that is to be evaluated
 | 
			
		||||
	 */
 | 
			
		||||
	private void evaluatePopulation(Population population) {
 | 
			
		||||
		this.m_Problem.evaluate(population);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public void optimize() {
 | 
			
		||||
 | 
			
		||||
		HashMap<Long, CounterClass> SuccessCounterMap=new HashMap<Long, CounterClass>();
 | 
			
		||||
		HashMap<Long, CounterClass> SuccessCounterMap = new HashMap<Long, CounterClass>();
 | 
			
		||||
 | 
			
		||||
		//Eltern markieren und f<>r die Z<>hlung vorbereiten
 | 
			
		||||
		for(int j=0;j<m_lambdamo&&j<m_Population.size();j++){
 | 
			
		||||
			m_Population.getEAIndividual(j).putData("Parent",m_Population.getEAIndividual(j) );
 | 
			
		||||
			SuccessCounterMap.put(m_Population.getEAIndividual(j).getIndyID(),new CounterClass(0));
 | 
			
		||||
		// Eltern markieren und f<>r die Z<>hlung vorbereiten
 | 
			
		||||
		for (int j = 0; j < m_lambdamo && j < m_Population.size(); j++) {
 | 
			
		||||
			m_Population.getEAIndividual(j).putData("Parent",
 | 
			
		||||
					m_Population.getEAIndividual(j));
 | 
			
		||||
			SuccessCounterMap.put(m_Population.getEAIndividual(j).getIndyID(),
 | 
			
		||||
					new CounterClass(0));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Kinder erzeugen
 | 
			
		||||
		Population children=new Population(m_lambdamo*m_lambda);
 | 
			
		||||
		// Kinder erzeugen
 | 
			
		||||
		Population children = new Population(m_lambdamo * m_lambda);
 | 
			
		||||
		children.setGenerationTo(m_Population.getGeneration());
 | 
			
		||||
 | 
			
		||||
		for(int j=0;j<children.getTargetSize();j++){
 | 
			
		||||
			AbstractEAIndividual parent=m_Population.getEAIndividual(j%m_lambdamo); 
 | 
			
		||||
			AbstractEAIndividual indy=(AbstractEAIndividual)parent.clone();
 | 
			
		||||
		for (int j = 0; j < children.getTargetSize(); j++) {
 | 
			
		||||
			AbstractEAIndividual parent = m_Population.getEAIndividual(j
 | 
			
		||||
					% m_lambdamo);
 | 
			
		||||
			AbstractEAIndividual indy = (AbstractEAIndividual) parent.clone();
 | 
			
		||||
			indy.mutate();
 | 
			
		||||
			indy.putData("Parent", parent);
 | 
			
		||||
			children.add(indy);
 | 
			
		||||
		}
 | 
			
		||||
		evaluatePopulation(children);
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
		m_Population.addPopulation(children);
 | 
			
		||||
		//Ranking
 | 
			
		||||
		ArchivingNSGAII dummyArchive=new ArchivingNSGAIISMeasure();
 | 
			
		||||
		Population []store=dummyArchive.getNonDomiatedSortedFronts(m_Population);
 | 
			
		||||
		store=dummyArchive.getNonDomiatedSortedFronts(m_Population);
 | 
			
		||||
		// Ranking
 | 
			
		||||
		ArchivingNSGAII dummyArchive = new ArchivingNSGAIISMeasure();
 | 
			
		||||
		Population[] store = dummyArchive
 | 
			
		||||
				.getNonDomiatedSortedFronts(m_Population);
 | 
			
		||||
		store = dummyArchive.getNonDomiatedSortedFronts(m_Population);
 | 
			
		||||
		dummyArchive.calculateCrowdingDistance(store);
 | 
			
		||||
 | 
			
		||||
		//Vergleichen und den Successcounter hochz<68>hlen wenn wir besser als unser Elter sind
 | 
			
		||||
		for(int j=0;j<m_Population.size();j++){
 | 
			
		||||
			AbstractEAIndividual parent= (AbstractEAIndividual) m_Population.getEAIndividual(j).getData("Parent");
 | 
			
		||||
			if(m_Population.getEAIndividual(j)!=parent){ //Eltern nicht mit sich selber vergleichen
 | 
			
		||||
				int parentParetoLevel=((Integer) parent.getData("ParetoLevel")).intValue();
 | 
			
		||||
				double parentSMeasure=((Double) parent.getData("HyperCube")).doubleValue();
 | 
			
		||||
				int childParetoLevel=((Integer) m_Population.getEAIndividual(j).getData("ParetoLevel")).intValue();
 | 
			
		||||
				double childSMeasure=((Double) m_Population.getEAIndividual(j).getData("HyperCube")).doubleValue();
 | 
			
		||||
				if( childParetoLevel<parentParetoLevel||((childParetoLevel==parentParetoLevel)&&childSMeasure>parentSMeasure )      ){
 | 
			
		||||
					SuccessCounterMap.get(parent.getIndyID()).value++;		
 | 
			
		||||
		// Vergleichen und den Successcounter hochz<68>hlen wenn wir besser als
 | 
			
		||||
		// unser Elter sind
 | 
			
		||||
		for (int j = 0; j < m_Population.size(); j++) {
 | 
			
		||||
			AbstractEAIndividual parent = (AbstractEAIndividual) m_Population
 | 
			
		||||
					.getEAIndividual(j).getData("Parent");
 | 
			
		||||
			if (m_Population.getEAIndividual(j) != parent) { // Eltern nicht mit
 | 
			
		||||
																// sich selber
 | 
			
		||||
																// vergleichen
 | 
			
		||||
				int parentParetoLevel = ((Integer) parent
 | 
			
		||||
						.getData("ParetoLevel")).intValue();
 | 
			
		||||
				double parentSMeasure = ((Double) parent.getData("HyperCube"))
 | 
			
		||||
						.doubleValue();
 | 
			
		||||
				int childParetoLevel = ((Integer) m_Population.getEAIndividual(
 | 
			
		||||
						j).getData("ParetoLevel")).intValue();
 | 
			
		||||
				double childSMeasure = ((Double) m_Population
 | 
			
		||||
						.getEAIndividual(j).getData("HyperCube")).doubleValue();
 | 
			
		||||
				if (childParetoLevel < parentParetoLevel
 | 
			
		||||
						|| ((childParetoLevel == parentParetoLevel) && childSMeasure > parentSMeasure)) {
 | 
			
		||||
					SuccessCounterMap.get(parent.getIndyID()).value++;
 | 
			
		||||
				}
 | 
			
		||||
			}else{ //Debug
 | 
			
		||||
			} else { // Debug
 | 
			
		||||
 | 
			
		||||
				SuccessCounterMap.get(parent.getIndyID()).seen=true;	
 | 
			
		||||
				SuccessCounterMap.get(parent.getIndyID()).seen = true;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		//Selection
 | 
			
		||||
		// Selection
 | 
			
		||||
		m_Population.clear();
 | 
			
		||||
		for(int i=0;i<store.length;i++){
 | 
			
		||||
			if(m_Population.size()+store[i].size()<=m_lambdamo){ //Die Front passt noch komplett
 | 
			
		||||
		for (int i = 0; i < store.length; i++) {
 | 
			
		||||
			if (m_Population.size() + store[i].size() <= m_lambdamo) { // Die
 | 
			
		||||
																		// Front
 | 
			
		||||
																		// passt
 | 
			
		||||
																		// noch
 | 
			
		||||
																		// komplett
 | 
			
		||||
				m_Population.addPopulation(store[i]);
 | 
			
		||||
 | 
			
		||||
			}else{ //die besten aus der aktuellen Front heraussuchen bis voll
 | 
			
		||||
				while(store[i].size()>0&&m_Population.size()<m_lambdamo){
 | 
			
		||||
					AbstractEAIndividual indy=store[i].getEAIndividual(0);
 | 
			
		||||
					double bestMeasure=((Double) indy.getData("HyperCube")).doubleValue(); //TODO mal noch effizient machen (sortieren und die besten n herausholen)
 | 
			
		||||
					for(int j=1;j<store[i].size();j++ ){
 | 
			
		||||
						if(bestMeasure<((Double) store[i].getEAIndividual(j).getData("HyperCube")).doubleValue()){
 | 
			
		||||
							bestMeasure=((Double) store[i].getEAIndividual(j).getData("HyperCube")).doubleValue();
 | 
			
		||||
							indy=store[i].getEAIndividual(j);
 | 
			
		||||
			} else { // die besten aus der aktuellen Front heraussuchen bis voll
 | 
			
		||||
				while (store[i].size() > 0 && m_Population.size() < m_lambdamo) {
 | 
			
		||||
					AbstractEAIndividual indy = store[i].getEAIndividual(0);
 | 
			
		||||
					double bestMeasure = ((Double) indy.getData("HyperCube"))
 | 
			
		||||
							.doubleValue(); // TODO mal noch effizient machen
 | 
			
		||||
											// (sortieren und die besten n
 | 
			
		||||
											// herausholen)
 | 
			
		||||
					for (int j = 1; j < store[i].size(); j++) {
 | 
			
		||||
						if (bestMeasure < ((Double) store[i].getEAIndividual(j)
 | 
			
		||||
								.getData("HyperCube")).doubleValue()) {
 | 
			
		||||
							bestMeasure = ((Double) store[i].getEAIndividual(j)
 | 
			
		||||
									.getData("HyperCube")).doubleValue();
 | 
			
		||||
							indy = store[i].getEAIndividual(j);
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					m_Population.add(indy);
 | 
			
		||||
@@ -236,51 +252,67 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Strategieparemeter updaten
 | 
			
		||||
		for(int j=0;j<m_Population.size();j++){
 | 
			
		||||
		// Strategieparemeter updaten
 | 
			
		||||
		for (int j = 0; j < m_Population.size(); j++) {
 | 
			
		||||
 | 
			
		||||
			AbstractEAIndividual indy=m_Population.getEAIndividual(j);
 | 
			
		||||
			if(indy.getMutationOperator() instanceof MutateESCovarianceMatrixAdaptionPlus ){ //Das geht nur wenn wir auch die richtige Mutation haben
 | 
			
		||||
				AbstractEAIndividual parent=(AbstractEAIndividual)indy.getData("Parent");
 | 
			
		||||
				MutateESCovarianceMatrixAdaptionPlus muta=(MutateESCovarianceMatrixAdaptionPlus) indy.getMutationOperator();
 | 
			
		||||
				double rate=((double) SuccessCounterMap.get(parent.getIndyID()).value)/((double) m_lambda);
 | 
			
		||||
			AbstractEAIndividual indy = m_Population.getEAIndividual(j);
 | 
			
		||||
			if (indy.getMutationOperator() instanceof MutateESCovarianceMatrixAdaptionPlus) { // Das
 | 
			
		||||
																								// geht
 | 
			
		||||
																								// nur
 | 
			
		||||
																								// wenn
 | 
			
		||||
																								// wir
 | 
			
		||||
																								// auch
 | 
			
		||||
																								// die
 | 
			
		||||
																								// richtige
 | 
			
		||||
																								// Mutation
 | 
			
		||||
																								// haben
 | 
			
		||||
				AbstractEAIndividual parent = (AbstractEAIndividual) indy
 | 
			
		||||
						.getData("Parent");
 | 
			
		||||
				MutateESCovarianceMatrixAdaptionPlus muta = (MutateESCovarianceMatrixAdaptionPlus) indy
 | 
			
		||||
						.getMutationOperator();
 | 
			
		||||
				double rate = ((double) SuccessCounterMap.get(parent
 | 
			
		||||
						.getIndyID()).value)
 | 
			
		||||
						/ ((double) m_lambda);
 | 
			
		||||
 | 
			
		||||
				if(indy!=parent){
 | 
			
		||||
				if (indy != parent) {
 | 
			
		||||
					muta.updateCovariance();
 | 
			
		||||
				}
 | 
			
		||||
				muta.updateStepSize(rate);			
 | 
			
		||||
				muta.updateStepSize(rate);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for(int j=0;j<children.size();j++){
 | 
			
		||||
		for (int j = 0; j < children.size(); j++) {
 | 
			
		||||
			children.getEAIndividual(j).putData("Parent", null);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
		m_Population.incrFunctionCallsBy(children.size());
 | 
			
		||||
		m_Population.incrGeneration();
 | 
			
		||||
		this.firePropertyChangedEvent(Population.nextGenerationPerformed);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public boolean removePopulationChangedEventListener(
 | 
			
		||||
			InterfacePopulationChangedEventListener ea) {
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	// @Override
 | 
			
		||||
	public void setPopulation(Population pop) {
 | 
			
		||||
		m_Population = pop;
 | 
			
		||||
		m_Population.setNotifyEvalInterval(1);
 | 
			
		||||
		m_lambdamo=m_Population.getTargetSize();
 | 
			
		||||
		m_lambdamo = m_Population.getTargetSize();
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/** Something has changed
 | 
			
		||||
	/**
 | 
			
		||||
	 * Something has changed
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param name
 | 
			
		||||
	 */
 | 
			
		||||
	protected void firePropertyChangedEvent (String name) {
 | 
			
		||||
		if (this.m_Listener != null) this.m_Listener.registerPopulationStateChanged(this, name);
 | 
			
		||||
	protected void firePropertyChangedEvent(String name) {
 | 
			
		||||
		if (this.m_Listener != null)
 | 
			
		||||
			this.m_Listener.registerPopulationStateChanged(this, name);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public int getLambda() {
 | 
			
		||||
@@ -291,13 +323,10 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable
 | 
			
		||||
		m_lambda = mLambda;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/*public int getLambdaMo() {
 | 
			
		||||
		return m_lambdamo;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setLambdaMo(int mLambda) {
 | 
			
		||||
		m_lambdamo = mLambda;
 | 
			
		||||
	}*/
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
	 * public int getLambdaMo() { return m_lambdamo; }
 | 
			
		||||
	 * 
 | 
			
		||||
	 * public void setLambdaMo(int mLambda) { m_lambdamo = mLambda; }
 | 
			
		||||
	 */
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user