How to introduce constraints to my objective function (Genetic Algorithm)

3 次查看(过去 30 天)
Hello everyone,
I am trying to solve a optimization problem with constraints using genetic algorithm solver. I tried to write my constraints by looking over the documentation matlab provides but The results i am getting are not consistent with the results i expect. (My answer should be around 5k or 6k but the answer i am getting changes around 13k to 18k) I suspect that the solver does not recognizes my constraints. Here i will attach the file i am working on. If you can have a look and suggest a solution i will be very happy.
Thank you in advance.
Best,
Beyza.

采纳的回答

Alan Weiss
Alan Weiss 2022-3-25
You have at least two errors that keep the constraint function from working properly. First, this section needs a loop such as for i = 1:something:
function [c] = constraintFunction(x,yj,p, M , r, aii, Kj)
if ci(i,1) > 0
xij(i,j) = 1;
else
xij(i,j) = 0;
end
Second, you never included this constraint function in the constraints in your script. It is just hanging there, never called. Put it in as a nonlinear constraint. Click the "Nonlinear constrants" button and then include the function. And if you mean for some variables to be integers, put that in as constraints as well.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 个评论
Azime Beyza Ari
Azime Beyza Ari 2022-3-26
Thank you!
I knew i was doing something wrong (Or was not doing it). I did include my constraints to my code thanks to your advice. Now i have other errors but i will open an another question for it!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by