Use of GA with infeasible points and constraints

4 views (last 30 days)
Daniel McDonald
Daniel McDonald on 28 Nov 2021
Commented: Daniel McDonald on 1 Dec 2021
Hello, I'm using the code below to find the minimum risk from a given number of points with infeasible solutions. The following function I believe should be subetting the matrix of points to only the feasible points then using GA to constrain the solution to the desired number of points. Eventually I'd like to further constraint the solution based on the distance each point is from the current point but that's a problem for another day.
% Objective function - Solving for P
function y = DistObj(x)
Pfailgrid = readmatrix('PfailColumn.xlsx'); %1x200
P = x(1); %Solving for this; %1x200
P2 = ones(size(P));
subset = (P<1);
P2(subset)=1-Pfailgrid(subset);
y = prod(P2);
end
%Import excel matrices
Dist = readmatrix('Distance.xlsx'); %Not used currently
Pfailgrid = readmatrix('PfailColumn.xlsx');
Points = readmatrix('Points0Column.xlsx');
%Call objective function
f = @(x)DistObj(x);
%Call x0 to feed GA initial points
x0 = Points.';
%upper and lower bounds
lb = readmatrix('lb.xlsx');
ub = readmatrix('ub.xlsx');
%Set constraints - where A*x<b or Aeq*x=beq
A = []; %-min(Dist*(1-Pfailgrid)); %200x1
b = []; %0;
Aeq = ones(1,200); %max(Dist*(1-Pfailgrid)); %Aeq = repelem(1,200);
beq = 105; %50; %beq = 250; need to figure out sum of matrix
%Set options
opts = optimoptions('ga','InitialPopulationMatrix',x0, ...
'MaxStallGenerations',50,'MaxGenerations',1000,'PlotFcn',@gaplotbestf);
rng(1,'twister'); %for reproducibility
intcon = (1:200); %make output values integers
%Run ga to find surface points with minimum risk
PointsNew = ga(f,200,A,b,Aeq,beq,lb,ub,[],intcon,opts);
PointsNew;
Pfailnew = PointsNew*Pfailgrid; %Should minimize Pfailnew with PointsNew
I'm also trying to constraint GA to only use integers limited by 0 and 1, basically making it binary (trying to say: use this point, not that point). The equality contstraint is what determines the number of points used.
The problem I'm running into is that PointsNew is returning infeasible points and Pfailnew is returning numbers greater than 1, neither of which should be possible. I'm kind of stuck with what the issue currently is so any help would be appreciated.
  4 Comments
Daniel McDonald
Daniel McDonald on 1 Dec 2021
Alan, thanks I'll give that a try. I may need to think about how this problem is structured to make it a bit simpler and I think your idea may be the right way to do that, I'll give it a try.
Thanks,
Dan

Sign in to comment.

Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by