Mixed-Integer Surrogate Optimization
This example shows how to solve an optimization problem that involves integer variables. Beginning in R2019b,surrogateopt
accepts integer constraints. In this example, find the pointx
that minimizes themultirosenbrock
function over integer-valued arguments ranging from –3 to 6 in ten dimensions. Themultirosenbrock
function is a poorly scaled function that is difficult to optimize. Its minimum value is 0, which is attained at the point[1,1,...,1]
. Code for themultirosenbrock
function appears at theend of this example.
rng(1,'twister')% For reproducibilitynvar = 10;% Any even numberlb = -3*ones(1,nvar); ub = 6*ones(1,nvar); fun = @multirosenbrock; intcon = 1:nvar;% All integer variables[sol,fval] = surrogateopt(fun,lb,ub,intcon)
surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
sol =1×101 1 1 1 1 1 1 1 1 1
fval = 0
In this case,surrogateopt
finds the solution.
Helper Function
这段代码创造es themultirosenbrock
helper 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.% Copyright 2014 by The MathWorks, Inc.N = size(x,2);% assumes x is a row vector or 2-D matrixifmod(N,2)% if N is odderror('Input rows must have an even number of elements')endodds = 1:2:N-1; evens = 2:2:N; F = zeros(size(x)); F(:,odds) = 1-x(:,odds); F(:,evens) = 10*(x(:,evens)-x(:,odds).^2); F = sum(F.^2,2);end