Main Content

Mixed-Integer Surrogate Optimization, Problem-Based

This example shows how to solve an optimization problem that involves integer variables. In this example, find the pointxthat minimizes themultirosenbrock函数超过整数值的参数,范围从–3到6个维度。这multirosenbrockfunction is a poorly scaled function that is difficult to optimize. Its minimum value is 0, which is attained at the point[1,1,...,1]. The code for themultirosenbrockfunction appears at theend of this example.

Create a 10-D row vector variablex带有边界–3的类型整数的。指定标量边界时,界限适用于所有变量组件。

x = optimvar("x",1,10,"LowerBound",-3,"UpperBound",6,“类型”,“整数”);

To usemultirosenbrockas the objective function, convert the function to an optimization expression usingFCN2OPTIMEXPR.

fun = fcn2optimexpr(@multirosenbrock,x);

Create an optimization problem with the objective functionmultirosenbrock.

prob = optimproblem("Objective",fun);

Set the maximum number of function evaluations to 200.

opts = optimoptions("surrogateopt","MaxFunctionEvaluations",200);

解决这个问题。

rng(1,'twister')% For reproducibility[sol,fval] = solve(prob,“求解器”,"surrogateopt","Options",opts)
Solving problem using surrogateopt.

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: 0 contains an object of type line. This object represents Best function value.

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
sol =struct with fields:x: [1 1 1 1 1 1 1 1 1 1]
fval = 0

In this case,surrogateoptreaches the correct solution.

Mixed-Integer Problem

Suppose that only the first six variables are integer-valued. To reformulate the problem, create a 6-D integer variablexintand a 4-D continuous variablexcont.

xint = optimvar("xint",1,6,"LowerBound",-3,"UpperBound",6,“类型”,“整数”); xcont = optimvar("xcont",1,4,"LowerBound",-3,"UpperBound",6);

Convertmultirosenbrockto an optimization expression using the input[xint xcont].

fun2 = fcn2optimexpr (@multirosenbrock [xint xcont]);

Create and solve the problem.

prob2 = optimproblem("Objective",fun2); rng(1,'twister')% For reproducibility[sol2,fval2] = solve(prob2,“求解器”,"surrogateopt","Options",opts)
Solving problem using surrogateopt.

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: 0.973612 contains an object of type line. This object represents Best function value.

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
sol2 =struct with fields:XCONT:[1.2133 1.4719 1.1857 1.5003] XINT:[1 1 1 1 1 1 1]
FVAL2 = 0.9736

This time the integer variables reach the correct solution, and the continuous variables are near the solution, but are not completely accurate.

Helper Function

This code creates themultirosenbrockhelper function.

functionF = multirosenbrock(x)% This function is a multidimensional generalization of Rosenbrock's% function. It operates in a vectorized manner, assuming that x is a matrix% whose rows are the individuals.Mathworks,Inc。2014年版权所有%N = size(x,2);% assumes x is a row vector or 2-D matrixifmod(N,2)% if N is odd错误('Input rows must have an even number of elements')end赔率= 1:2:n-1;evens = 2:2:n;f =零(size(x));f(:,ordds)= 1-x(:,ordds);f(::,evens)= 10*(x(:,evens)-x(:,ordds)。^2);f = sum(f。^2,2);end

See Also

|

相关话题