Is there a way for genetic algorithm (optimization toolbox) to only output a positive objective function value?

I would like genetic algorithm to give me the minimum positive value possible for my objective function.

Answers (2)

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

Thank you Walter. Can you explain how this can be done?
function cost = obj(....)
...
cost = ...
if cost < 0; cost = 1E10 - cost; end %high cost and gets higher the more negative you go

Sign in to comment.

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

I tried your solution sir. But it gave me an error message stating "incorrect use of = operator"
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));
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
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.
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

Sign in to comment.

Asked:

on 23 Jan 2018

Community Treasure Hunt

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

Start Hunting!