algorithmTemplates

Algorithm templates

Most of metaheuristic families are characterized by a common behaviour which is shared by all the algorithms belonging to the family. This behaviour can be expressed as a template that can be instatiated to implement a particular algorithm. From a software engineering point of view, an algorithm whose behavior falls in a basic template would only require to implement some specific methods for the new technique; the common behavior would not be needed to be programmed, therefore resulting in less code replication. This inversion of control if a characteristic of software frameworks, as is the case of jMetal.
大多数元启发式家族具有一个共同的行为特征,该行为由属于该家族的所有算法共享。这种行为可以表示为一个模板,该模板可以用来实现特定的算法。从软件工程的角度来看,行为属于基本模板的算法只需要实现新技术的一些特定方法;通用行为不需要编程,因此代码复制更少。这种控制反转是[软件框架]的一个特征(https://en.wikipedia.org/wiki/Software_framework)例如,jMetal。

The Evolutionary Algorithm Template

Many papers about evolutionary algorithms (EAs) include a pseudo-code to describe them similar to this one:
许多关于进化算法 (EA) 的论文都包含一个伪代码来描述它们,类似于这个:

P(0) ← GenerateInitialSolutions() 
t ← 0
Evaluate(P(0))
while not StoppingCriterion() do
  P'(t) ← selection(P(t))
  P''(t) ← Variation(P'(t)) 
  Evaluate(P''(t))
  P (t + 1) ← Update(P (t), P''(t)) 
  t←t+1
end while

To mimic this pseudo-code, jMetal 5 incorporates a template in the form of an abstract class named AbstractEvolutionaryAlgorithm, which contains the following code:
为了模仿这个伪代码,jMetal 5 以抽象类的形式合并了一个模板,名为 [Abstract Evolutionary Algorithm](https://github.com/jMetal/jMetal/blob/jmetal-5.0/jmetal-core/
src/main/java/org/uma/jmetal/algorithm/impl/Abstract Evolutionary Algorithm.java),其中包含以下代码:

package org.uma.jmetal.algorithm.impl;

/**
 * Created by Antonio J. Nebro on 26/10/14.
 * @param <S> Solution
 * @param <R> Result
 */
public abstract class AbstractEvolutionaryAlgorithm<S extends Solution<?>, R>  implements Algorithm<R>{
  private List<S> population;
  public List<S> getPopulation() {
    return population;
  }
  public void setPopulation(List<S> population) {
    this.population = population;
  }

  protected abstract void initProgress();
  protected abstract void updateProgress();
  protected abstract boolean isStoppingConditionReached();
  protected abstract List<S> createInitialPopulation();
  protected abstract List<S> evaluatePopulation(List<S> population);
  protected abstract List<S> selection(List<S> population);
  protected abstract List<S> reproduction(List<S> population);
  protected abstract List<S> replacement(List<S> population, List<S> offspringPopulation);
  @Override public abstract R getResult();

  @Override public void run() {
    List<S> offspringPopulation;
    List<S> matingPopulation;

    population = createInitialPopulation();
    population = evaluatePopulation(population);
    initProgress();
    while (!isStoppingConditionReached()) {
      matingPopulation = selection(population);
      offspringPopulation = reproduction(matingPopulation);
      offspringPopulation = evaluatePopulation(offspringPopulation);
      population = replacement(population, offspringPopulation);
      updateProgress();
    }
  }
}  

The generics in the class declaration indicate that an algorithm works with subclasses of the Solution interface (e.g., DoubleSolution, BinarySolution, and so on) and returns a result (typically, a single solution in the case of single-objective metaheuristics and a list of solutions in the case of multi-objective techniques). We can observe as the population is implemented a list of solutions.
类声明中的泛型表明算法与 Solution 接口的子类(例如,Double SolutionBinary Solution 等)一起使用并返回结果(通常,在
单目标元启发式算法和多目标技术情况下的解决方案列表)。
我们可以观察到人口实施的解决方案列表。
To develop an EA, all the abstract the methods used in the run() method must be implemented. We describe those methods next:

  • createInitialPopulation(): This method fills the population with a set of tentative solutions. The typical strategy consists in generating randomly initialized solutions, but any other approach can be applied.
  • evaluatePopulation(population): All the solutions in the population argument are evaluated and a population, which can be the same one passed as a parameter or a new one, is returned as a result.
  • initProgress(): The progress of an EA is usually measured by counting iterations or function evaluations. This method initializes the progess counter.
  • isStoppingConditionReached(): the stopping condition establishes when the algorithm finishes its execution.
  • selection(population): the selection method chooses a number of solutions from the population to become the mating pool.
  • reproduction(matingPopulation): the solutions in the mating pool are manipulated somehow, by modifying them or by using them to create new ones, yielding to new solutions that constitute the offspring population.
  • replacement(population, offspringPopulation): the population for the next generation is built from individuals of the current and the offspring populations.
  • updateProgress(): the counter of the progress of the algorithm (evaluations, iterations, or whatever) is updated.
Genetic algorithms

If we are interested in implementing a genetic algorithm, a subfamily of EAs characterized by applying a selection operator and by using a crossover and a mutation operator for the reproduction step, a subclass of AbstractEvolutionaryAlgorithm called AbstractGeneticAlgorithm is provided:
如果我们有兴趣实现遗传算法,EA 的一个子家族,其特点是应用选择算子,并在复制步骤中使用交叉和变异算子,“抽象进化算法”的子类称为 [抽象遗传算法](https
😕/github.com/jMetal/jMetal/blob/jmetal-5.0/jmetal-core/src/main/java/org/uma/jmetal/algorithm/impl/Abstract Genetic Algorithm.java)提供:

package org.uma.jmetal.algorithm.impl;

/**
 * Created by ajnebro on 26/10/14.
 */
public abstract class AbstractGeneticAlgorithm<S extends Solution<?>, Result> extends AbstractEvolutionaryAlgorithm<S, Result> {
  protected SelectionOperator<List<S>, S> selectionOperator ;
  protected CrossoverOperator<S> crossoverOperator ;
  protected MutationOperator<S> mutationOperator ;
}

Popular metaheuristics such as NSGA-II, SPEA2, PESA2, MOCell or SMS-EMOA are based on this template.

Evolution strategies

Another subfamily of EAs are evolution strategies, which are based on applying only mutation in the reproduction step. The corresponding abstract class for EAs is AbstractEvolutionStragegy:
EA 的另一个亚科是进化策略,它基于仅在繁殖步骤中应用突变。
EA 对应的抽象类是 [Abstract Evolution Stratagegy](https://github.com/jMetal/jMetal/blob/jmetal-5.0/jmetal-core/src/main/java/org/uma/jmetal/algorithm
/impl/Abstract Evolution Strategy.java):

package org.uma.jmetal.algorithm.impl;

/**
 * Created by ajnebro on 26/10/14.
 */
public abstract class AbstractEvolutionStrategy<S extends Solution<?>, Result> extends AbstractEvolutionaryAlgorithm<S, Result> {
  protected MutationOperator<S> mutationOperator ;
}

The PAES algorithm is based on this template

TO BE COMPLETED

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值