Problem with simple Genetic Algorithm Optimisation
Mostra commenti meno recenti
I am trying to teach myself Matlab and specifically with regards to genetic algorithm optimisation.
My simple engineering problem is a cantilevered beam under bending stress, with a force of 1000N applied at the end and a length of 500mm. The allowable stress of the material is 400MPa. My variables are the width and depth of the beam. I want to optimise the width and depth so that the beam has the least cross sectional area possible whilst still having a maximum stress of under 400MPa. I want to set an upper limit of the depth of 10mm and the width of 200mm, the lower limits are one.
So, I believe my fitness function should be f(x) = width * length, with my constraints being stress < 400.
I have written the following functions in order to try and solve this problem:
Main File
ObjFcn = @fitness;
nvars = 2;
LB = [1 1];
UB = [200 10];
Const = @constraints;
[x,fval] = ga(ObjFcn,nvars,[],[],[],[],LB,UB,Const);
Parameters
function p = parameters()
% Define Inputs
p.Force = 1000.0;
p.Length = 500.0;
p.Allow = 400.0;
end
Variables
function v = variables(x)
v.b = x(1);
v.d = x(2);
end
Calculations
function s = calculations(p,v)
s.Moment = p.Force * p.Length;
s.Ixx = (v.b * v.d^3) / 12;
s.y = v.d / 2;
s.Stress = (s.Moment * s.y) / s.Ixx;
end
Fitness
function fitness = fitness(x)
p = parameters();
v = variables(x);
s = calculations(p,v);
fitness = v.b * v.d;
end
Constraints
function [c, ceq] = constraints(x)
p = parameters();
v = variables(x);
s = calculations(p,v);
c = s.Stress - p.Allow;
ceq = [];
end
With this code, when I run the main file I don't get any errors - but when the optimisation is complete it returns values of x as [200 10]. However when doing the calculations by hand, it is obvious that the only answer is [75 10]. I am completely new to Matlab so please if you notice anything wrong with the way I've tried to code things please let me know. Also, if someone could enlighten me on how I can return the final values of things at the end of the calculation (in this example, the calculated stress), then I would be greatful.
I understand that this is a very basic problem, and maybe other optimisers other than GA would be better, but I want to learn GA because my ultimate goal is to optimise a large problem with many variables and constraints.
Many thanks
Risposte (1)
Sulaymon Eshkabilov
il 12 Mag 2019
0 voti
Hi,
In your MAIN file, you have set UB = [200 10]; that need to be fixed at UB = [75, 10].
Good luck.
Categorie
Scopri di più su Genetic Algorithm in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!