Is it bad practice to have nonlinear constraints array change size depending on the input solution in a genetic algorithm?

In a nonlinear ga, the nonlin constraint function is evaluated with each solution, and the output is [c,ceq]. These arrays contain in each element a constraint that is checked with each solution.
The function is called as:
ConstraintFunction = @(x) Func_Nonlinear_Constraints(x,extra_parameters)
In my case, the amount of checks to make depends on the amount of ones in a given solution (e.g., x=[0 1 1 0 0 1 0 1]).
One way to implement this, is to have a fixed size for "c" that does not depend on the solution. Then, all the scalar values that result from each check is placed into the array. This results in the array containing both the actual constraints and a bunch of zeros.
Another way to implement this, would be to have the size of "c" to be the same as the number of checks to make.
If there are 4 checks, in the first case "c" would have size -for example- 10x1 (including the 4 checks and 6 zeros), while the second approach would be c=4x1.
In order to speed up the code in my particular problem, working with a "c" of changing size may be useful. However, I am concerned it might be an issue. At the same time, I reckon that the GA does not care about how many extra zeros (or satisfied constraints) exist, but rather only look at how many unsatisfied constraints there are as a result. If this is true, then the "c" of changing size should not be an issue.
Is this correct? Or would a "c" (and "ceq") of changing size be a problem for the algorithm? Is it bad practice?

 Réponse acceptée

When boundaries are found to be violated, the optimizers can attempt to locate the boundary by comparing the output of the constraints functions for successive calls, effectively using gradient search type methods. This is the reason why you should be returning difference expressions such as (expression minus limit) rather than just a 0 (constraint satisfied) or 1 (constraint failed)

3 commentaires

Thank you for your quick reply, Walter.
For every check, I indeed return an "expression minuts limit" that I put into "c". However, if "c" is initialized with a fixed length, there are extra zeros by the end of the array. From your answer, it seems those extra zeros would be counterproductive in providing the optimizer useful info.
On the other hand, if "c" has different length in each output, it seems it would also not help the optimizer when comparing successive outputs.
What is then a good way to work with "c", when the amount of constraints to be satisfied depend on the solution?
(In this example, for each 1 in the solution I do a check, whereas for each 0 I don't do anything. The checks, however, are related to each other, and thus are nonlinear operations.)
I am saying that you might get error messages if you do not always return the same size of results.
Extra zeros do not make any significant difference for the internal gradients (but no point using more than the maximum number of conditions you have.)

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2018b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by