Use of GA with infeasible points and constraints

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Alan Weiss
Alan Weiss il 30 Nov 2021
Sorry, I really don't understand what you are trying to do. But I did look at your Pfailcolumn.xlsx file. Did you simply want to strip out the non-1 values? You could try this:
Pfailgrid = readmatrix('PfailColumn.xlsx');
subset = Pfailgrid < 1;
P = Pfailgrid(subset);
If you look at the resulting P vector, it has 131 entries, all the non-1 values of Pfailgrid. What you do with the values afterward I don't understand, but maybe you can use this as a first step. I believe that there is no need to run this code inside a function that you call repeatedly; you can simply store the value of P and use it wherever you need.
Alan Weiss
MATLAB mathematical toolbox documentation
Daniel McDonald
Daniel McDonald il 1 Dic 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

Accedi per commentare.

Risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by