Is there a way for genetic algorithm (optimization toolbox) to only output a positive objective function value?
Mostrar comentarios más antiguos
I would like genetic algorithm to give me the minimum positive value possible for my objective function.
Respuestas (2)
Walter Roberson
el 23 de En. de 2018
0 votos
No, there is not. However, you can adjust your objective function to return a large (but finite) value when it would otherwise have generated a negative result.
2 comentarios
Fahraz Ali
el 23 de En. de 2018
Walter Roberson
el 23 de En. de 2018
function cost = obj(....)
...
cost = ...
if cost < 0; cost = 1E10 - cost; end %high cost and gets higher the more negative you go
Alan Weiss
el 23 de En. de 2018
0 votos
Another approach (probably less efficient than Walter's suggestion) is to have a nonlinear inequality constraint function that is the negative of the objective function.
Alan Weiss
MATLAB mathematical toolbox documentation
7 comentarios
Hariharan Sridharan
el 30 de Abr. de 2020
I tried your solution sir. But it gave me an error message stating "incorrect use of = operator"
Walter Roberson
el 1 de Mayo de 2020
Hariharan Sridharan: please show your code.
Hariharan Sridharan
el 1 de Mayo de 2020
simpleMultiObjective
function y = simpleMultiObjective(x)
y(1)= 0.08648-(0.00616*x(1))-(0.01978*x(2))-(0.01648*x(3)) -(0.00001*x(1)*x(1)) +(0.01063*x(2)*x(2)) +(0.00878*x(3)*x(3)) +(0.00219*x(1)*x(2)) +(0.00153*x(1)*x(3)) +(0.00734*x(3)*x(2));
y(2)= 0.295-(0.0793*x(1))-(0.2757*x(2))-(0.2434*x(3)) -(0.0467*x(1)*x(1)) +(0.1094*x(2)*x(2)) +(0.1183*x(3)*x(3)) +(0.1142*x(1)*x(2)) +(0.0683*x(1)*x(3)) +(0.0817*x(3)*x(2));
y(3)= 0.78+(1.17*x(1))-(0.22*x(2))+(3.10*x(3)) -(0.101*x(1)*x(1)) +(2.02*x(2)*x(2)) -(0.020*x(3)*x(3)) +(0.58*x(1)*x(2)) -(1.610*x(1)*x(3)) -(1.30*x(3)*x(2));
Hariharan Sridharan
el 1 de Mayo de 2020
myConstraints:
function [c,ceq] = myConstraints(x)
c = [-0.08648+(0.00616*x(1))+(0.01978*x(2))+(0.01648*x(3)) +(0.00001*x(1)*x(1))-(0.01063*x(2)*x(2))-(0.00878*x(3)*x(3))-(0.00219*x(1)*x(2))-(0.00153*x(1)*x(3))-(0.00734*x(3)*x(2));-0.295+(0.0793*x(1))+(0.2757*x(2))+(0.2434*x(3))+(0.0467*x(1)*x(1))-(0.1094*x(2)*x(2))-(0.1183*x(3)*x(3))-(0.1142*x(1)*x(2))-(0.0683*x(1)*x(3))-(0.0817*x(3)*x(2));[-0.78-(1.17*x(1))+(0.22*x(2))-(3.10*x(3))+(0.101*x(1)*x(1))-(2.02*x(2)*x(2))+(0.020*x(3)*x(3))-(0.58*x(1)*x(2))+(1.610*x(1)*x(3))+(1.30*x(3)*x(2))];
ceq = [ ]
end
Hariharan Sridharan
el 1 de Mayo de 2020
I tried this sir. I am a complete beginner and there are possibilities of silly mistakes too. Please bear with it and thanks for helping sir. I have also attacheda screenshot of the erroe message.
Alan Weiss
el 1 de Mayo de 2020
Editada: Alan Weiss
el 1 de Mayo de 2020
You made several typos in your nonlinear constraint function. Try this:
function [c,ceq] = simpleConstraints(x)
ceq = [];
c = -simpleMultiObjective(x);
end
That said, I think that you would do better to use paretosearch instead.
opts = optimoptions('paretosearch','PlotFcn',"psplotparetof");
[x2,fv2] = paretosearch(@simpleMultiObjective,nvar,[],[],[],[],[],[],@simpleConstraints,opts);
Alan Weiss
MATLAB mathematical toolbox documentation
Hariharan Sridharan
el 1 de Mayo de 2020
thank you sir, I'll try it out!
Categorías
Más información sobre Genetic Algorithm en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!