Having problems creating inequality constraints for genetic algorithm

Hi! I am having some problems with my GA, I use a fitness function that gives me the min cost of operation and creates values of power generated in each generator, in my case 6, to which i called Pg. My Pg will be a vector of 1x6 and for every value of Pg, i.e. Pg1,...,Pg6, I will have some prohibited operation zones: Pg1-> [210 240] [350 380]; Pg2-> [90 110] [140 160]; Pg3-> [150 170] [210 240]; Pg4-> [80 90] [110 120]; Pg5-> [90 110] [140 150]; Pg6-> [75 85] [100 105]; My problem is that every time I see people doing something with intervals it is usualy as boundaries, but I cant do it because I already have them as Pgmax for UB and Pgmin for LB. How can I create the constraints function in order to make these as prohibited zones for my Pg values? Thanks and Im sorry if I didnt explain something properly, I am still new to GA. EDIT: Im going to put some code in case I didnt explain myself properly.
%%My main
...
Pmin=[100 50 80 50 50 50 ];
Pmax=[500 200 300 150 200 120];
LB=Pmin;
UB=Pmax;
nvars=6;
[Pg,Fval] = ga(ObjFcn,nvars,[],[],[],[],LB,UB,ConsFcn,Options);
--------------
%%My fitness function
...
z=0;
for i=1:1:6
z=a(i)*(Pg(i)^2)+b(i)*Pg(i)+c(i)+abs(e(i)*sin(f(i)*(Pmin(i)-Pg(i))))+pen*
(Pdemand-Ploss-sum(Pg))^2+z;
end

Réponses (2)

You need to represent these nonconvex constraints either as nonlinear constraints OR reformulate your problem to have 2^6 different possibilities, and investigate all 2^6 = 64 possibilities.
1. For the nonlinear constraint approach, I will give you just one example, you generalize to the other constraints. For a 2-element real vector t with t(1) < t(2) define
function f = nomiddle(x,t)
f = (x-t(1))*(t(2)-x);
This f is positive when t(1) < x < t(2) and is negative otherwise. So it represents the constraint that x <= t(1) OR x >= t(2). So one of your constraints, that x is not in the region [240,350], could be
function [c,ceq] = cons1(x)
ceq = [];
c = nomiddle(x,[240,350]);
2. Set your bounds to allow only the regions that are OK, such as x(1) is in [210 240], x(2) is in [140 160], etc. Do that for each of the 2^6 possibilities.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

4 commentaires

Thanks! I noticed you made a mistake in interpreting my problem. Those intervals (i.e. Pg3-> [150 170] [210 240]) are actually the ones that my vector cannot be in, so I just changed "c = nomiddle(x,[240,350])" with the right intervals "c = nomiddle(x,[210 240])" for example.
Now my problem is that there are still ocasions in that these constraints are violated, I did it like this:
%values inside these intervals must not be used for Pg
c = nomiddle(Pg(1),[210,240]);
c = nomiddle(Pg(1),[350,380]);
c = nomiddle(Pg(2),[90,110]);
c = nomiddle(Pg(2),[140,160]);
I don't understand what you mean with your code. If you have nonlinear constraints, you need to define a separate coordinate for each constraint, you can't just overwrite each c value with a new c as you seem to be doing. See Nonlinear Constraints.
By the way, it is easy to write a similar function that takes a 4-element ordered vector and makes a nonlinear constraint, such as
function f = nomiddle2(x,t)
f = (x-t(1))*(t(2)-x)*(t(3)-x)*(t(4)-x);
If x is smaller than t(1), and t(1) < t(2) < t(3) < t(4), then f < 0, meaning that is a feasible point. The function changes sign every time x crosses a t value, so it does what we want: has the intervals from t(1) to t(2) be disallowed, and from t(3) to t(4) be disallowed as well.
Alan Weiss
MATLAB mathematical toolbox documentation
Ups sry I actually didnt implement it that way in my program, I did "c(1)=...; to c(6)=...;". Now in this new one you showed me I implemented it like this:
c(1) = nomiddle(Pg(1),[210,240,350,380]);
c(2) = nomiddle(Pg(2),[90,110,140,160]);
c(3) = nomiddle(Pg(3),[150,170,210,240]);
c(4) = nomiddle(Pg(4),[80,90,110,120]);
c(5) = nomiddle(Pg(5),[90,110,140,150]);
c(6) = nomiddle(Pg(6),[75,85,100,105]);
This way I should have no Pg values inside [t(1),t(2)] and inside [t(3),t(4)], however sometimes that doesnt happen and some intervals are violated. Perhaps it has something to do with my fitness function... Thanks for helping!
EDIT:
%One of my results for Pg values
(unfortunatly the values dont stay consistent for each run I do...)
Pg = [408.450 185.710 241.536 112.851 199.396 102.224]
you can see Pg(4) and Pg(6) violate the intervals [110,120] and [100,105] respectively.
nvm already figured the problem! Thank you!!

Connectez-vous pour commenter.

ASIF
ASIF le 8 Nov 2023
I am also facing the same problem to implement these Prohibited operation zone values as; Pg1-> [210 240] [350 380]; Pg2-> [90 110] [140 160]; Pg3-> [150 170] [210 240]; Pg4-> [80 90] [110 120]; Pg5-> [90 110] [140 150]; Pg6-> [75 85] [100 105]; for 6 generators using LSA. My problem is that i want to try this vector values with ramp limit coefficnets. kindly help me in this to implement POZ values in LSA Code;

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by