How to include an nonlinear equality constraint when using surrogateopt
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Réponses (2)
Matt J
le 27 Mai 2021
Modifié(e) : Matt J
le 27 Mai 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 commentaires
Matt J
le 29 Mai 2021
Modifié(e) : Matt J
le 29 Mai 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 commentaires
Voir également
Catégories
En savoir plus sur Surrogate Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!