constrained minimization using pattern search, solver-凯发k8网页登录
this example shows how to minimize an objective function, subject to nonlinear inequality constraints and bounds, using pattern search. for a problem-based version of this example, see .
constrained minimization problem
for this problem, the objective function to minimize is a simple function of a 2-d variable x
.
simple_objective(x) = (4 - 2.1*x(1)^2 x(1)^4/3)*x(1)^2 x(1)*x(2) (-4 4*x(2)^2)*x(2)^2;
this function is known as "cam," as described in l.c.w. dixon and g.p. szego [1].
additionally, the problem has nonlinear constraints and bounds.
x(1)*x(2) x(1) - x(2) 1.5 <= 0 (nonlinear constraint) 10 - x(1)*x(2) <= 0 (nonlinear constraint) 0 <= x(1) <= 1 (bound) 0 <= x(2) <= 13 (bound)
code the objective function
create a matlab® file named simple_objective.m
containing the following code:
type simple_objective
function y = simple_objective(x) %simple_objective objective function for patternsearch solver % 凯发官网入口首页 copyright 2004 the mathworks, inc. x1 = x(1); x2 = x(2); y = (4-2.1.*x1.^2 x1.^4./3).*x1.^2 x1.*x2 (-4 4.*x2.^2).*x2.^2;
solvers such as patternsearch
accept a single input x
, where x
has as many elements as the number of variables in the problem. the objective function computes the scalar value of the objective function and returns it in its single output argument y
.
coding the constraint function
create a matlab file named simple_constraint.m
containing the following code:
type simple_constraint
function [c, ceq] = simple_constraint(x) %simple_constraint nonlinear inequality constraints. % 凯发官网入口首页 copyright 2005-2007 the mathworks, inc. c = [1.5 x(1)*x(2) x(1) - x(2); -x(1)*x(2) 10]; % no nonlinear equality constraints: ceq = [];
the constraint function computes the values of all the inequality and equality constraints and returns the vectors c
and ceq
, respectively. the value of c
represents nonlinear inequality constraints that the solver attempts to make less than or equal to zero. the value of ceq
represents nonlinear equality constraints that the solver attempts to make equal to zero. this example has no nonlinear equality constraints, so ceq = []
. for details, see .
minimize using patternsearch
specify the objective function as a function handle.
objectivefunction = @simple_objective;
specify the problem bounds.
lb = [0 0]; % lower bounds ub = [1 13]; % upper bounds
specify the nonlinear constraint function as a function handle.
constraintfunction = @simple_constraint;
specify an initial point for the solver.
x0 = [0.5 0.5]; % starting point
call the solver, requesting the optimal point x
and the function value at the optimal point fval
.
[x,fval] = patternsearch(objectivefunction,x0,[],[],[],[],lb,ub, ...
constraintfunction)
optimization finished: mesh size less than options.meshtolerance and constraint violation is less than options.constrainttolerance.
x = 1×2
0.8122 12.3122
fval = 9.1324e 04
add visualization
to observe the solver's progress, specify options that select two plot functions. the plot function psplotbestf
plots the best objective function value at every iteration, and the plot function psplotmaxconstr
plots the maximum constraint violation at every iteration. set these two plot functions in a cell array. also, display information about the solver's progress in the command window by setting the display
option to 'iter'
.
options = optimoptions(@patternsearch,'plotfcn',{@psplotbestf,@psplotmaxconstr}, ... 'display','iter');
run the solver, including the options
argument.
[x,fval] = patternsearch(objectivefunction,x0,[],[],[],[],lb,ub, ...
constraintfunction,options)
max iter func-count f(x) constraint meshsize method 0 1 0.373958 9.75 0.9086 1 18 113581 1.617e-10 0.001 increase penalty 2 147 92267 0 1e-05 increase penalty 3 373 91333.2 0 1e-07 increase penalty 4 638 91324 0 1e-09 increase penalty optimization finished: mesh size less than options.meshtolerance and constraint violation is less than options.constrainttolerance.
x = 1×2
0.8122 12.3122
fval = 9.1324e 04
nonlinear constraints cause patternsearch
to solve many subproblems at each iteration. as shown in both the plots and the iterative display, the solution process has few iterations. however, the func-count
column in the iterative display shows many function evaluations per iteration. both the plots and the iterative display show that the initial point is infeasible, and that the objective function is low at the initial point. during the solution process, the objective function value initially increases, then decreases to its final value.
references
[1] dixon, l. c. w., and g .p. szego (eds.). towards global optimisation 2. north-holland: elsevier science ltd., amsterdam, 1978.