MATLAB Answers

Nonlinear inequality in GA optimization with integer constraints

3 views (last 30 days)
Yro
Yro on 18 Oct 2020
Edited: Matt J on 20 Oct 2020
Hi, I am using GA optimization tool. The problem I am solving contains integer constraints (IntCon), but I need to set a non-linear inequality to the objective function. I am calculating the value of the function (k-eff) for patterns obtained from the genetic algorithm, but I need an inequality for the power, which must be kept below a certain value (power <= 1.3). What I consulted is that the inequalities [c, ceq] are set in the following way c(x) <= 0, so c(x) -1.3 <= 0. On the other hand for the problem with IntCon the ceq = [ ].
Thanks in advance.

  2 Comments

Alan Weiss
Alan Weiss on 20 Oct 2020
And what is the question? You stated some correct restrictions on c and ceq. But I don't understand what you want from us.
Alan Weiss
MATLAB mathematical toolbox documentation
Yro
Yro on 20 Oct 2020
Hi, thanks for your reply. My question is when defining the constraints because my constraint is:
0.8 <= POWER <= 1.3
Would it be okay to define c as follows?:
function [c, ceq] = POWER_CONSTRAINT(~)
ceq = [];
POWER = load('POWER_PEAK.txt') ;
MIN = 0.8 ;
MAX = 1.3 ;
c = [MIN - POWER ; POWER - MAX] ; % 0.8 <= P <= 1.3
Thanks in advance.

Sign in to comment.

Answers (1)

Matt J
Matt J on 20 Oct 2020
Edited: Matt J on 20 Oct 2020
In the code you have shown for POWER_CONSTRAINT(~), it does not make sense that POWER does not depend on the input, but rather on some independent .txt file. The point of the nonlinear constraint function is that it lets ga() query the feasibility of an input x. If the text file is supposed to have some dependence on x, then there should be code within POWER_CONSTRAINT(x) that regenerates POWER_PEAK.txt for the input x.
If the issue is that POWER_PEAK.txt is a heavy computation and you are trying to avoid repeating a computation that may have been already done elsewhere in your code, then read here:

  2 Comments

Yro
Yro on 20 Oct 2020
Briefly, the problem I am solving depends on x (patterns obtained using GA), with this value I run an external simualtion code for the objective function evaluation. I get as result the function and POWER values written to the text file separately in each iteration. The constraint I am giving is the POWER for each x pattern.
For:
x1 ==> function and POWER
x2 ==> function and POWER
x3 ==> function and POWER...
I am not clear how the algorithm handles the restrictions, the code runs well when introducing the POWER_CONSTRAINT function, the results are also logical. There is no way to check if you are using that function?. The code I am running is the following:
options = optimoptions(@ga,'Display', 'iter', ...
'OutputFcn',@GA_OUTPUT ,...
'PlotFcn', {@gaplotbestf, @PLOT_FUNCTION},...
'MaxGenerations', 30, ...
'PopulationSize', POPULATION_SIZE, ...
'FunctionTolerance',1e-6, ...
'CrossoverFraction', 0.95, ...
'EliteCount', 0.5*30) ;
start_time = tic ;
[x,fval,exitflag,output,population,scores] = ...
ga(@OBJECTIVE_FUNCTION,nvars,A,b,Aeq,beq,lb,ub,@POWER_CONSTRAINT,IntCon,options) ;
end_time = toc (start_time) ;
Matt J
Matt J on 20 Oct 2020
with this value I run an external simualtion code for the objective function evaluation.
You are assuming though that the x that is passed to your constraint function will be the same as the x that ga() most recently passed to the objective function. Because that assumption is not always valid, however, your constraint function will sometimes need to re-run the simulation for the x that it receives as input. The link I gave you discusses how to implement that efficiently.
There is no way to check if you are using that function?
We don't have to check because it can be seen in your code that you are not using it. The input to POWER_CONSTRAINT is completely ignored.

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!