How to include an nonlinear equality constraint when using surrogateopt

조회 수: 10 (최근 30일)
Dennea MacCallum
Dennea MacCallum 2021년 5월 27일
편집: Matt J 2021년 5월 29일
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
Matt J
Matt J 2021년 5월 27일
편집: Matt J 2021년 5월 28일
The problem you've shown isn't really a fitting application of surrogateopt. There are only 2500 feasible solutions. You could easily loop through them all to find the minimum.

댓글을 달려면 로그인하십시오.

답변 (2개)

Matt J
Matt J 2021년 5월 27일
편집: Matt J 2021년 5월 27일
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.

Matt J
Matt J 2021년 5월 29일
편집: Matt J 2021년 5월 29일
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

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by