## Question about an effect of ConstraintTolerance on multiple constraints for GA optimization

### Yohei Shibata (view profile)

on 6 Mar 2019
Latest activity Edited by Yohei Shibata

on 8 Mar 2019

### Alan Weiss (view profile)

Hi, I'm doing the optimization using GA with multiple constraint functions and have difficulty in understanding an effect of ConstrainTorelance.
For example, I have three constraint functions as follows:
Fcn1 > 10
Fcn > 8
Fcn > -7
One of the result was that Fcn1 = 9.8592, Fcn2 = 9.6328 and Fcn3 = -3.0568 showing that only Fcn2 and Fcn3 meet the constraints.
I thought that the reason is related to ConstraintTolerance, and it was set to 1.0000e-03 in the program.
But I don't understand how Fcn1 = 9.8592 was possible in the process of GA not meeting the constraint.

Alan Weiss

### Alan Weiss (view profile)

on 6 Mar 2019
Can you please show us the following two items:
1. How did you write your constraint function? Give us a simplified form of the code if it is too long.
2. What are the results of iterative display? In particular, what is the infeasibility of the initial population?
Alan Weiss
MATLAB mathematical toolbox documentation
Yohei Shibata

### Yohei Shibata (view profile)

on 7 Mar 2019
The constraint function is written as follow:
rng('default')
ObjectiveFunction = @(x)GA_DL(x);
ConstraintFunction = @(x)GA_UL(x);
nvars = 5;
options = optimoptions(@ga, 'MaxGenerations', 1000, 'MutationFcn', @mutationadaptfeasible, 'PlotFcn', {@gaplotbestf}, 'Display', 'iter', 'UseParallel', true,...
'MaxStallGenerations', 50);
LB = [1 1 1 1 1];
UB = [34 68 35 27 16];
intCon=1:5;
[x, fval] = ga(ObjectiveFunction, nvars, [], [], [], [], LB, UB, ConstraintFunction, intCon, options);
Below is the simplified form of the code for constraint function, which includes three constraint function in it. Each constraint function(constraint1~constraint3) outputs the value corresponding to the input parameters.
This program is system simulation of wireless communication and the output value is communication quality (SNR and SINR).
function [value, y] = GA_UL(x)
RR = 50;
seed = 1;
param_idx1 = 2:2:68;
param_idx2 = 2:2:136;
param_idx3 = 22:2:90;
param_idx4 = 2:2:54;
param_idx5 = 0:2:30;
theta_3dB_in = param_idx1(x(1));
theta_3dB_center_in = param_idx2(x(2));
theta_tilt_in = param_idx3(x(3));
phi_3dB_in = param_idx4(x(4));
rotation = param_idx5(x(5));
offset1 = 10;
value(1) = -(-offset1 + constraint1(theta_3dB_in, theta_3dB_center_in, theta_tilt_in, phi_3dB_in, RR, rotation, 6, seed));
offset2 = -7;
value(2) = -(-offset2 + constraint2(theta_3dB_in, theta_3dB_center_in, theta_tilt_in, phi_3dB_in, RR, rotation, 6, seed));
offset3 = 8;
value(3) = -(-offset3 + constraint3(theta_3dB_in, theta_3dB_center_in, theta_tilt_in, phi_3dB_in, RR, rotation, 6, seed));
y = [];
The below is the result of iterative display.
Best Mean Stall
Generation Func-count Penalty Penalty Generations
1 100 -1.515 0.3326 0
2 150 -2.409 -0.5318 0
3 200 -2.411 -0.5966 0
4 250 -2.515 -1.086 0
5 300 -2.712 -1.28 0
6 350 -2.712 -1.431 1
7 400 -2.838 -1.474 0
8 450 -2.838 -1.636 1
9 500 -2.838 -1.484 2
10 550 -2.838 -1.589 3
11 600 -2.838 -1.938 4
12 650 -2.844 -1.98 0
13 700 -2.846 -2.153 0
14 750 -2.846 -2.16 1
15 800 -2.853 -2.411 0
16 850 -2.942 -2.24 0
17 900 -2.942 -2.305 1
18 950 -2.942 -2.314 2
19 1000 -2.942 -2.074 3
20 1050 -2.942 -2.241 4
:
:
90 4550 -3.142 -2.393 36
91 4600 -3.142 -2.596 37
92 4650 -3.142 -2.302 38
93 4700 -3.142 -2.284 39
94 4750 -3.142 -2.596 40
95 4800 -3.142 -2.659 41
96 4850 -3.142 -2.529 42
97 4900 -3.142 -2.504 43
98 4950 -3.142 -2.462 44
99 5000 -3.142 -2.641 45
100 5050 -3.142 -2.945 46
101 5100 -3.142 -2.956 47
102 5150 -3.142 -2.885 48
103 5200 -3.142 -2.967 49
104 5250 -3.142 -2.837 50
Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance
but constraints are not satisfied.
Initial Infeasibility of the function of constraint1 is below and only 18 out of 50 meets the constraint.
I would really appreciate if you could give me advice and I hope these information make sense to you.
Thank you.
13.0188
12.4900
9.4365
8.1227
9.6496
4.6333
3.6377
4.0980
13.3708
-2.2779
11.4355
8.4155
3.7612
7.2794
3.5207
10.0874
4.1379
15.1323
9.5178
3.7487
11.6370
5.8767
12.7986
9.7754
3.6463
16.9440
2.0295
6.7475
12.7627
11.6821
6.3310
12.6349
5.3666
1.2121
9.2971
6.9982
7.9015
12.4994
2.9812
5.9609
11.8591
4.0646
16.8535
5.4142
9.3272
5.0578
10.2907
4.5779
12.5986
16.8379

### Alan Weiss (view profile)

on 7 Mar 2019

Thank you for the clear explanation. You have a difficult nonlinear problem with all integer variables. The solver is struggling to find any feasible point. Until it finds one feasible point, it does not matter that it satisfies a few constraints, the solver attempts to find something feasible and does not attempt to keep some constraints feasible when not all are feasible. See Integer ga algorithm.
I'm afraid that the best advice I can give you is to increase the size of the population considerably in an attempt to find a feasible point. This will slow the optimization even further, but until you find a feasible point, the solver is not doing anything productive. Also, there is no point in specifying a mutation function, as the integer ga algorithm overrides your choice anyway.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Yohei Shibata

### Yohei Shibata (view profile)

on 8 Mar 2019
Thank you so much for the insightful advice!
First, I did not understand that the solver was struggling to find an answer to meet the constraints. So I will first try to increase the size of the population.
Also thanks for pointing out that there's no need for specifying the mutation function. I will also refer to the link about Integer ga algorithm.
I really appreciate you taking time to answer my question.