GA does not solve problems with integer and equality constraints

13 次查看(过去 30 天)
When I test this code which is shown below. I got an error of " GA does not solve problems with integer and equality constraints."
what should I change to solve this problem.
[ploss,v]=power_flow1()
ncap=4;
min=0.1;
max=1;
for i=1:2*ncap
k=mod(i,2);
if k==0
lb(i,1)=min;
ub(i,1)=max;
else
lb(i,1)=2;
ub(i,1)=33;
end
end
Vmin=0.95;
Vmax=1.05
options = gaoptimset;
options = gaoptimset('PopulationSize', 50,'Generations', 500,'StallGenLimit',100,'TimeLimit', 500,'StallTimeLimit', 50,'PlotFcn',@gaplotbestf);
constraints = @(capplcsz_opt) constraint_GA(capplcsz_opt, Vmax, Vmin);
[capplcsz_opt,fval,exitflag]=ga(@power_flow_cap,2*ncap,[],[],[],[],lb,ub,constraints,[1 3 5 7],options);
capplcsz_opt([1 3 5 7])
[ Ploss,Busvoltage]=power_flow_cap(capplcsz_opt)

采纳的回答

Torsten
Torsten 2024-3-3
编辑:Torsten 2024-3-4
Your code from above works for me. Test it.
Because you only have inequality constraints, you must set h = [] instead of h = zeros(60,1) in function "constraint_ga".
  7 个评论
Torsten
Torsten 2024-3-4
编辑:Torsten 2024-3-4
You want to have V=abs(Busvoltage) within Vmin and Vmax, and this is the case (see the code below).
[g,h]=constraint_GA(capplcsz_opt, Vmin, Vmax)
idx = find(g>0)
gives idx = [].
I don't know how you see that there is no improvement for fval.

请先登录,再进行评论。

更多回答(2 个)

John D'Errico
John D'Errico 2024-3-3
编辑:John D'Errico 2024-3-3
The coupling of equality constraints with integer constraints makes a significant problem. For example, suppose I wanted to solve a problem where x and y were constrained to be integer, together with a rather simple equality constraint? Thus just require that
x^2 - 13*y^2 = 1
This is in fact known as a Pell equation. When you multiply y^2 there by 13, there are not too many integer solutions. The first integer solution does not arise until arise until you get to (x,y) == (649,180). And if we change the constraint to
x^2 - 109*y^2 = 1
the smallest positive integer solution apparently lives at (158070671986249,15140424455100).
Worse, if the factor applied to y is the square of an integer, then no solutions will ever exist. Should GA be able to know these facts about Pell equations?
So why am I pointing out Pell equations? Because they are a simple class of equation form where the solutions are not trivial to identify, AND the solutions often lie few and far between. Should GA know the necessary number theory to be able to recognize a Pell equation for what it is, then to solve a Pell equation as part of the constraints? OF COURSE NOT!
Even simpler, suppose the constraints were purely linear? Even there, things get tricky. Solving a system of linear Diophantine equations just to identify potential feasible solutions again requires an understanding of number theory, though much simpler in that case.
Maybe you think that GA should be able to look at sets of infeasible parameter values, and from that, know how to find a feasible solution? NOPE. Again, look at the Pell equation example. Given the constraint
x^2 - 109*y^2 = 1
and some set of sample values for x and y that fail to satisfy the constraint, can you simply identify a pair that does satisfy the constraint? Again, unless you understand Pell equations well enough to know how to solve for a general solution to that equation, nothing will easily help you.
I can give a huge variety of examples. Um, how about this simple constraint on the integer x:
isprime(x*2^x + 1) == true
that is, require that x is an integer, AND that x*2^x+1 is a prime number. This family of numbers are known as the Cullen numbers.
They are rather rarely prime. Sequence A005849 in the OEIS (Online Encyclopedia of Integer Sequences) lists the complete known set of values for x, such that a prime number arises is:
{1, 141, 4713, 5795, 6611, 18496, 32292, 32469, 59656, 90825, 262419, 361275, 481899, 1354828, 6328548, 6679881}
The point being, GA would need to be an expert in number theory to handle these problems. It is not so. The combination of equality constraints with integer variables simply makes the problem too complex.
So, to try to answer your actual question as to what should you change to resolve it, you could just try leaving the variables to be non-integer, only rounding them inside the objective function. GA might survive the discontinuities introduced in the objective function. Or, you might just test all possible sets of integer variables, taking the best option. That would completely avoid any optimizer.

Walter Roberson
Walter Roberson 2024-3-3
What you have to do is not declare [1 3 5 7] as being integer valued, and instead declare your own MutationFcn and CrossoverFcn and InitialPopulation, with those functions being defined in such a way that they "just happen" to always make [1 3 5 7] integers
ga() cannot handle the combination of integer valued variables together with nonlinear constraints, so you have to declare all the variables to be continuous but arrange the MutationFcn and CrossOverFcn to enforce integer values for the appropriate variables.
  5 个评论
Walter Roberson
Walter Roberson 2024-3-4
g(1)=V(1)-Vmax ;
g(12)= V(2)-Vmax;
g(3) = V(3)-Vmax;
You output to g(12) there instead of to g(2). You later output to g(12) without having outout to g(2)
g(1) =Vmin-V(1);
You overwrite what you have written to g(1) and the rest.
You could simply code
g = [V(:) - Vmax; Vmin - V(:)];
Khlifi Wahid
Khlifi Wahid 2024-3-6
Actually, the problem of limiting the values ​​between vmax and vmin has been solved but I did not find an optimal faval value and exitflag=-5, I want to minimize it less than 0.0203 can i change something to do it

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by