How to generate the objconstr for multivariate surrogate optimization with nonlinear constraints?

Hello,
I am trying to use the surrogate optimization function in matlab to obtain the global minima of a problem with an objective function and several nonlinear constraints. My problem has been computed using symbolic variables, but I am not able to find the correct syntax of putting these symbolic cost functinos and nonlinear constraints into "matlabFunction" to obtain the function handle to use with surrogateopt.
***** Code example ********
symbolic_objective_function %computed from several operations
symbolic_nonlinear_constraints %computed after several operations
%% Is the below line of code the correct way to compute the objconstr for use in surrogateopt?
objconstr=matlabFunction([symbolic_objective_function], [symbolic_nonlinear_constraints],'vars',{x})

 Accepted Answer

Try this:
obj = matlabFunction(symbolic_objective_function,'vars',{x});
constr = matlabFunction(symbolic_nonlinear_constraints,'vars',{x});
objconstr = @(x)struct('Fval',obj(x),'Ineq',constr(x));
Alan Weiss
MATLAB mathematical toolbox documentation

4 Comments

Thank you for your resonse, Alan.
I tried your suggestion in the following format but received the error as highlighted. I am unsure what it means.
Code:
[func, constraint]=some_function(inputs a,b,c,d)
syms computations here
f=objective function output of syms computations
inequality_constraint=constraint output of syms computation
equality_constraint=constraint output of syms computation
func=matlabFunction(f,'vars',{symvar(f)});
constraint=matlabFunction(inequality_constraint,equality_constraint,'vars',{symvar(cons)});
%% note: symvar(f)=symvar(cons)=[x]
end
for the above code, i obtain
% func= @(in1).....
% constraint=@(in1)deal(zeros(0,0)).....
func and cons are passed to another function inside which the optimisation is formulated as follows
options=optimoptions(....)
lb=...
ub=...
objconstr = @(in1)struct('Fval',func(in1),'Ineq',constraint(in1));
[xfinal,fval] = surrogateopt(objconstr,lb,ub,options);
********************************************************************************************************************
**Running the above code results in the following error.
***************************************** ERROR BEGIN ********************************
Error using deal (line 37)
The number of outputs should match the number of inputs.
Error in symengine>@(in1)deal(zeros(0,0),[in1(:,1).*4.890738003669028e-1+(in1(:,1).*.................(very long expression that i have deleted for brevity)
objconstr_0 = @(in1)struct('Fval',func_0(in1),'Ineq',constraint_0(in1));
temp = feval(objconstr,x);
expensive = struct('model', @(x) expensiveModel(x,objfun), ...
out = feval(expensiveModel,Xin);
self.combinedModel = @(trial) conditionalModelEvaluator(trial, output, ...
self.pendingTrials(end).output = self.combinedModel(nextTrial);
self.evaluateLocal(nextTrial);
self.modelMgr.evaluate(nextTrial);
controller = controller.optimize();
Error in thetasol (line 37)
[xfinal_0,fval_0] = surrogateopt(objconstr_0,lb,ub,options);
*************************** END ERROR **************************************************************
Thank you for any advice you may be able to provide
The problem as I understand it is that you have nonlinear equality constraints as well as nonlinear inequality constraints. Your constraint function should be for nonlinear inequality constraints only. It should not have a deal statement. It should accept the in1 argument and return a scalar or vector. Check that your nonlinear inequality constraint accepts one argument and returns one argument.
Alan Weiss
MATLAB mathematical toolbox documentation
Hi Alan Weiss,
How a nonlinear equality constraint can be fed to the Matlab Sover such as Surrogate?
As shown in the surrogateopt reference page, the solver does not accept nonlinear equality constraints. This example shows a potential workaround by using two inequality constraints to form an approximate equality constraint. However, this technique does not always work.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!