How to include an nonlinear equality constraint when using surrogateopt
10 views (last 30 days)
Show older comments
I am creating a program that optimizes a mixed integer non linear objective function. I am not sure how to implement a nonlinear equality constraint using surrogateopt. I have gone through the live editor tool and through the documentation and am still not sure how to do this :(. Any help is much appreciated. Right now I have a inequality constraint as shown below but I want it to be an equality constraint.
clear;
clc;
nvar = 3;
deadline = 25;
upperBounds = [10,10,deadline];
lowerBounds = [1,1,1];
intcon = 1:nvar;
% Solve
[solution,objectiveValue] = surrogateopt(@objConstrFcn,lowerBounds,...
upperBounds,intcon);
disp(solution);
disp(objectiveValue);
function f = objConstrFcn(optimInput)
% variables
fill = optimInput(1);
cap = optimInput(2);
days = optimInput(3);
% objective function
f.Fval = days*(fill+cap);
% constraint
f.Ineq = days - optimwelders(fill,cap); % how do I make this an equality constraint?? so that days = optimwelders(fill,cap)
end
The function optimwelders:
function time = optimwelders(fill,cap)
time = ((fill+cap)/(cap*3))+4;
end
1 Comment
Answers (2)
Matt J
on 27 May 2021
Edited: Matt J
on 27 May 2021
Your nonlinear equality constraint is,
days= ((fill+cap)/(cap*3))+4;
In order for this to be satisfied, all terms on the right hand side must be integers, which means that fill must be an integer multiple of cap,
fill=k*cap
You can now rewrite the problem in terms of the variables k,cap, and days. Your objective becomes,
f.Fval=days*(k+1)*cap
and your nonlinear equality constraint reduces to a linear constraint, which surrogateopt can accept,
days=(k+1)/3+4
Your bounds on cap and days remain the same, but the bounds on fill become,
1<=k*cap<=10
but these are nonlinear inequalities, which surrogateopt can also accept.
0 Comments
Matt J
on 29 May 2021
Edited: Matt J
on 29 May 2021
Another solution might be to re-arrange your nonlinear equality constraint in the form,
3*cap*(days-4) - (fill+cap)=0
Although surrogateopt cannot handle this directly, the left hand side is always going to be integer-valued, so you can equivalently write it as two inequalities:
3*cap*(days-4) - (fill+cap) <= 0.5
3*cap*(days-4) - (fill+cap) >= -0.5
This leads to the following revision of your code:
function f = objConstrFcn(optimInput)
% variables
fill = optimInput(1);
cap = optimInput(2);
days = optimInput(3);
% objective function
f.Fval = days*(fill+cap);
% constraint
f.Ineq(1) = ( 3*cap*(days-4) - (fill+cap) - 0.5); %3*cap*(days-4) - (fill+cap) <= 0.5
f.Ineq(2) = -( 3*cap*(days-4) - (fill+cap) + 0.5); %3*cap*(days-4) - (fill+cap) >= -0.5
end
0 Comments
See Also
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!