主要内容

Performing a Multiobjective Optimization Using the Genetic Algorithm

此示例显示了如何使用多目标遗传算法函数执行多目标优化gamultiobjin Global Optimization Toolbox.

Simple Multiobjective Optimization Problem

gamultiobjcan be used to solve multiobjective optimization problem in several variables. Here we want to minimize two objectives, each having one decision variable.

min F(x) = [objective1(x); objective2(x)] x
where, objective1(x) = (x+2)^2 - 10, and objective2(x) = (x-2)^2 + 20
% Plot two objective functions on the same axisx = -10:0.5:10;f1 =(x+2)。^2-10;f2 =(x-2)。^2 + 20;情节(x,f1);抓住;plot(x,f2,'r');grid;标题(“目标情节”'(x + 2)^2-10'''''''''(x -2)^2 + 20'''');

这two objectives have their minima atx = -2x = +2分别。但是,在一个多目标问题中,x = -2,x = 2,以及该范围内的任何解决方案-2 <= x <= 2同样最佳。对于这个多目标问题没有任何解决方案。多主体遗传算法的目的是在该范围内找到一组解决方案(理想情况下,具有良好的传播)。金宝搏官方网站一组解决方案也称为帕累金宝搏官方网站托阵线。帕累托前金宝搏官方网站沿上的所有解决方案都是最佳的。

Coding the Fitness Function

We create a MATLAB® file namedsimple_multiobjective.m:

函数y = simple_multiobjective(x)y(1)=(x+2)^2-10;y(2)=(x-2)^2 + 20;

这Genetic Algorithm solver assumes the fitness function will take one inputx, 在哪里x是一个行矢量,其元素与问题中的变量数量一样多。健身函数计算每个目标函数的值,并在单个向量输出中返回这些值y

Minimizing Usinggamultiobj

To use thegamultiobjfunction, we need to provide at least two input arguments, a fitness function, and the number of variables in the problem. The first two output arguments returned bygamultiobjareX, the points on Pareto front, andFVAL,在值处的目标函数值X。A third output argument,exitFlag,告诉你原因gamultiobj停了下来。第四个论点,OUTPUT, contains information about the performance of the solver.gamultiobj也可以返回第五个论点POPULATION, that contains the population whengamultiobj终止和第六个论点,SCORE, that contains the function values of all objectives forPOPULATION什么时候gamultiobj终止。

fitnessfunction = @simple_multiobjective;numberOfvariables = 1;[x,fval] = gamultiobj(fitnessfunction,numberOfvariables);
Optimization terminated: maximum number of generations exceeded.

X求解器返回的是一个矩阵,其中每一行是目标函数的帕累托正面上的点。这FVALis a matrix in which each row contains the value of the objective functions evaluated at the corresponding point inX

尺寸(x)大小(FVAL)
ans = 18 1 ans = 18 2

约束多目标优化问题

gamultiobjcan handle optimization problems with linear inequality, equality, and simple bound constraints. Here we want to add bound constraints on simple multiobjective problem solved previously.

min F(x) = [objective1(x); objective2(x)] x
subject to -1.5 <= x <= 0 (bound constraints)
where, objective1(x) = (x+2)^2 - 10, and objective2(x) = (x-2)^2 + 20

gamultiobjaccepts linear inequality constraints in the forma*x <= b和形式的线性平等约束Aeq*x = beq和bound constraints in the form磅<= x <= ub。我们通过AAeqas matrices andb,beq,, 和ubas vectors. Since we have no linear constraints in this example, we pass[]对于这些输入。

a = [];b = [];aeq = [];beq = [];lb = -1.5;ub = 0;x = gamultiobj(fitnessfunction,numberOfvariables,a,b,aeq,beq,lb,ub);
Optimization terminated: maximum number of generations exceeded.

所有解决金宝搏官方网站方案X(每一行)将满足在指定的公差内的所有线性和界限options.ConstraintTolerance。However, if you use your own crossover or mutation function, ensure that the new individuals are feasible with respect to linear and simple bound constraints.

Adding Visualization

gamultiobj可以通过选项参数接受一个或多个绘图函数。此功能可用于可视化求解器在运行时的性能。可以使用绘图功能使用optimoptions

Here we useoptimoptionsto select two plot functions. The first plot function isgaplotpareto, which plots the Pareto front (limited to any three objectives) at every generation. The second plot function isgaplotscorediversity, which plots the score diversity for each objective. The options are passed as the last argument to the solver.

options = optimoptions(@gamultiobj,'plotfcn',{@gaplotpareto,@gaplotscorediversity}); gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
Optimization terminated: maximum number of generations exceeded.

Vectorizing Your Fitness Function

再次考虑以前的健身功能:

Objective1(X)=(X + 2)^2-10,Objectig2(X)=(X -2)^2 + 20

By default, thegamultiobj求解器一次仅在一个点传递到健身函数。但是,如果将健身函数矢量化以接受一组点并返回一组功能值,则可以加快解决方案。

例如,如果求解器需要在一个呼叫此健身功能的一个呼叫中评估五个点,则它将用5 by-1的矩阵调用该功能,即5行和1列(请回想一下1是数字变量)。

Create a MATLAB file calledvectorized_multiobjective.m:

function scores = vectorized_multiobjective(pop) popSize = size(pop,1); % Population size numObj = 2; % Number of objectives % initialize scores scores = zeros(popSize, numObj); % Compute first objective scores(:,1) = (pop + 2).^2 - 10; % Compute second objective scores(:,2) = (pop - 2).^2 + 20;

此矢量化版本的健身功能采用矩阵pop用任意数量的积分,行pop, 和returns a matrix of size人口化-经过-numberOfObjectives

我们需要使用使用使用的选项来指定健身函数是使用使用的选项optimoptions。这options are passed in as the ninth argument.

FitnessFunction = @(x) vectorized_multiobjective(x); options = optimoptions(@gamultiobj,'UseVectorized',true); gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.

相关话题