Constraints in Genetic Algorithm - Not Just Input Constraints

Is it possible to specify constraints that are not just reliant on the input variable? I.e. a constrain that may be a function of the output or an intermediate variable.
NOTE: The output of this system is calculated from a "black box" (it's a PSS SINCAL simulation).
At this stage I've been using a workaround - making the result of the fitness function a very high value when the output is not within the constraints. Looking for a more elegant solution.
Thank you
Elvis

3 Comments

First of all, what do you mean by the input variable? The GA parameters or the initial population of solutions?
By input variable I mean the current generation in the genetic algorithm. e.g. A * x <= b ... I am calling x the input variable.
Hello Elvis,
I think I am having the same problem as you.
I already have non-linear constraints in my problem.
Now I want to add one more constraint. To add this constraint, I need to read the outputs (which is calculated by a black box, an external .exe) and get the value "Output_h" and then the constraint is "Output_h<=LIMIT".
I think now I have two options:
  1. Modify the objective function value. Just as you did, in my objective function subroutine (which reads the input.txt, call and run the black box, read the outputs, calculate the objective function), I will check the value "Output_h" to see whether it is satisfying the above constraint. If not, I will add a much larger value to the initial objective function value.
  2. Add one more non-linear constraint. In my non-linear constraint subroutine, I will call and run the black box, read the outputs, and get the value "Output_h" and then add the constraint "Output_h - LIMIT <= 0".
What do you think? Which way you would recommend?
I have some concerns:
  1. For the first option, based on my understanding, GA will learn from the previous generation (probably learn from the objective function value) and generate the next generation. But here, I modify the initial objective function value. I am wondering how GA will learn from this and try to get a better solution gradually. Actually, physically, even I don't know how to generate a better solution since the value "Output_h" is an implicit function of the input variables (I am optimizing more than 10 variables).
  2. For the second option, it seems that in my non-linear constraint subroutine, I will have a lot of codes the same as my objective function subroutine, including reading the input.txt, calling and running the black box, reading the outputs. For me, it seems that for each GA population/case, the black box will be called twice (in both non-linear constraint and objective function subroutines)? Do you think it is wasting of time? Do I have a better way to do this? In addition, every run of the black box will take around 60s, which is the reason why I am trying to find a more efficient way to add this constraint.
Thanks!
Min

Sign in to comment.

 Accepted Answer

Nonlinear constraint functions allow you to express any constraint at all, as long as MATLAB can calculate what you need to decide if a point is feasible.
For nonlinear inequality constraints, the mechanism assumes that the constraint is of the form
c(x) <= 0
where c(x) is a smooth function. So, for example, if you want to constrain x to be within the circle
norm(x) <= 5
you would write the constraint
c(x) = norm(x) - 5;
This way, when norm(x) is a bit greater than 5, the solver knows it is infeasible, but also knows that it is close to being feasible.
What I am saying is, don't just set the objective value to an arbitrary high value when the nonlinear constraint is not met, but use a nonlinear constraint function, and set it to a positive value when the constraint is not met, but one that goes smoothly to negative as the constraint becomes satisfied.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

7 Comments

Thank you for the response Alan.
My main concern with this is how long it takes to do each iteration of the particular function I'm trying to optimize (it's a script that runs 48 separate SINCAL simulations with the result being the bus voltages of each simulation - taking approximately 40 seconds). I need the solutions to have say between 95% and 105% of the rated voltage at each bus.
Is there any way to put a constraint on this result/output without having to re-run the script (taking twice as long per generation to check the constraints)?
Cheers Elvis
This technique is now in the documentation.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Perfect, nested functions will save me having to compute twice. Thank you for the prompt help.
Hi,
How can I put a constraint on y (output) instead of x (input) of gamultiobj? I have several outputs and they are indirectly calculated from x within the fitness function. I put boundaries on x, but I want to optimize the solution for y1, y2, y3, y4. For example, find the optimal x values for y1<10, y2<1, y3<1, y4<100.
Thanks
Alan Weiss
MATLAB mathematical toolbox documentation
Thanks. I figured I can use x to calculate y, and define nonlinear constraints c(1) as a function of y (doesn't have to be x).

Sign in to comment.

More Answers (1)

I have the following functions
L=sqrt((x(1)^2)+(x(2)^2)+(x(3)^2))+sqrt((x(4)^2)+(x(5)^2)+(x(6)^2));
H=x(7);
alpha=atand((x(1)-x(8))/x(2));
beta=atand(x(3)/x(2));
how to find the optimal values of x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8) such that output having constraints as 170<L<190,20<H<30,1<alpha<2,2<beta<4

Categories

Asked:

on 7 Jun 2013

Commented:

on 19 May 2019

Community Treasure Hunt

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

Start Hunting!