Code covered by the BSD License

London Kings Cross Western Concourse Genetic Algorithm

Dean Kayton (view profile)

13 Mar 2013 (Updated )

A simple genetic algorithm is applied to a model of the London Kings Cross Western Concourse.

[Qcell,Vcell,Rcell]=MSA(D,popSize)
```function [Qcell,Vcell,Rcell]=MSA(D,popSize)
warning('off','all');
Qcell=cell(popSize,1);
Vcell=cell(popSize,1);
Rcell=cell(popSize,1);
for popNo=1:popSize
m=D{popNo,1}.m;n=D{popNo,1}.n;Ni=zeros(12,12,m);S=zeros(6*n);Pf=S(:,1);Q=zeros(12,m);Qfi=Q;Ei=Q;
for i=1:m
H=D{popNo,1}.Con(:,i);C=D{popNo,1}.Coord(:,H(2))-D{popNo,1}.Coord(:,H(1));e=[6*H(1)-5:6*H(1),6*H(2)-5:6*H(2)];c=D{popNo,1}.be(i);
[a,b,L]=cart2sph(C(1),C(3),C(2));ca=cos(a);sa=sin(a);cb=cos(b);sb=sin(b);cc=cos(c);sc=sin(c);
r=[1 0 0;0 cc sc;0 -sc cc]*[cb sb 0;-sb cb 0;0 0 1]*[ca 0 sa;0 1 0;-sa 0 ca];T=kron(eye(4),r);
co=2*L*[6/L 3 2*L L];x=D{popNo,1}.A(i)*L^2;y=D{popNo,1}.Iy(i)*co;z=D{popNo,1}.Iz(i)*co;g=D{popNo,1}.G(i)*D{popNo,1}.J(i)*L^2/D{popNo,1}.E(i);
K1=diag([x,z(1),y(1)]);K2=[0 0 0;0 0 z(2);0 -y(2) 0];K3=diag([g,y(3),z(3)]);K4=diag([-g,y(4),z(4)]);
K=D{popNo,1}.E(i)/L^3*[K1 K2 -K1 K2;K2' K3 -K2' K4;-K1 -K2 K1 -K2;K2' K4 -K2' K3];
w=D{popNo,1}.w(:,i)';Qf=-L^2/12*[6*w/L 0 -w(3) w(2) 6*w/L 0 w(3) -w(2)]';Qfs=K*T*D{popNo,1}.St(e)';
A=diag([0 -0.5 -0.5]);B(2,3)=1.5/L;B(3,2)=-1.5/L;W=diag([1,0,0]);Z=zeros(3);M=eye(12);p=4:6;q=10:12;
switch 2*H(3)+H(4)
case 0;B=2*B/3;M(:,[p,q])=[-B -B;W Z;B B;Z W];case 1;M(:,p)=[-B;W;B;A];case 2;M(:,q)=[-B;A;B;W];
end
K=M*K;Ni(:,:,i)=K*T;S(e,e)=S(e,e)+T'*Ni(:,:,i);Qfi(:,i)=M*Qf;Pf(e)=Pf(e)+T'*M*(Qf+Qfs);Ei(:,i)=e;
end