Having problems creating inequality constraints for genetic algorithm
Show older comments
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
Answers (2)
Alan Weiss
on 12 Jul 2017
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 Comments
Luis Manito
on 12 Jul 2017
Alan Weiss
on 12 Jul 2017
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
Luis Manito
on 12 Jul 2017
Edited: Luis Manito
on 12 Jul 2017
Luis Manito
on 13 Jul 2017
ASIF
on 8 Nov 2023
0 votes
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;
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!