Is there a way for genetic algorithm (optimization toolbox) to only output a positive objective function value?
Show older comments
I would like genetic algorithm to give me the minimum positive value possible for my objective function.
Answers (2)
Walter Roberson
on 23 Jan 2018
0 votes
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 Comments
Fahraz Ali
on 23 Jan 2018
Walter Roberson
on 23 Jan 2018
function cost = obj(....)
...
cost = ...
if cost < 0; cost = 1E10 - cost; end %high cost and gets higher the more negative you go
Alan Weiss
on 23 Jan 2018
0 votes
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 Comments
Hariharan Sridharan
on 30 Apr 2020
I tried your solution sir. But it gave me an error message stating "incorrect use of = operator"
Walter Roberson
on 1 May 2020
Hariharan Sridharan: please show your code.
Hariharan Sridharan
on 1 May 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
on 1 May 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
on 1 May 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
on 1 May 2020
Edited: Alan Weiss
on 1 May 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
on 1 May 2020
thank you sir, I'll try it out!
Categories
Find more on Genetic Algorithm 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!