├── README.md ├── RouletteWheelSelection.m ├── Manoj_CostFun.m ├── PermutationCrossover.m ├── PermutationMutate.m └── K_out_n_GA.m /README.md: -------------------------------------------------------------------------------- 1 | # Genetic-algorithms for optimising k-to-r out of n binary system's reliability model 2 | -------------------------------------------------------------------------------- /RouletteWheelSelection.m: -------------------------------------------------------------------------------- 1 | % Roulette Wheel Selection 2 | function i=RouletteWheelSelection(P) 3 | 4 | r=rand; 5 | 6 | C=cumsum(P); 7 | 8 | i=find(r<=C,1,'first'); 9 | 10 | end -------------------------------------------------------------------------------- /Manoj_CostFun.m: -------------------------------------------------------------------------------- 1 | function Z = Manoj_CostFun(P) 2 | 3 | L =[0.52 0.56 0.58 0.6 0.72 0.74 0.78 0.8 0.82 0.84 0.85 0.86 0.88 0.9 0.92]; 4 | t = 10; 5 | 6 | R = exp(-L*t); 7 | Rstar = 5e-7; 8 | C = [80000 82000 78000 75000 85000 64000 72000 69000 84000 87000 92000 85000 74000 95000 89000]; 9 | 10 | Cf = 332000; 11 | 12 | C_P = C(P); 13 | R_P = R(P); 14 | R1 = R_P(1); R2 = R_P(2); R3 = R_P(3); R4 = R_P(4); 15 | 16 | 17 | Rs = R1*R2+R1*R3+R1*R4+R2*R3+R2*R4+R3*R4-R1*R2*R3-R1*R3*R4-R2*R3*R4+R1*R2*R3*R4; 18 | 19 | if Rs>Rstar 20 | Z = vpa(sum(C_P)+(1-Rs)*Cf); 21 | else 22 | Z = 1e+20; 23 | 24 | end 25 | -------------------------------------------------------------------------------- /PermutationCrossover.m: -------------------------------------------------------------------------------- 1 | % Permutation Crossover 2 | 3 | function [y1, y2]=PermutationCrossover(x1,x2) 4 | 5 | nVar=numel(x1); 6 | 7 | c=randi([1 nVar-1]); 8 | 9 | x11=x1(1:c); 10 | x12=x1(c+1:end); 11 | 12 | x21=x2(1:c); 13 | x22=x2(c+1:end); 14 | 15 | r1=intersect(x11,x22); 16 | r2=intersect(x21,x12); 17 | % x11(ismember(x11,r1)) 18 | % x11(ismember(x11,r1))=r2 19 | % x21(ismember(x21,r2))=r1 20 | 21 | if numel(x11(ismember(x11,r1)))==r2 & numel(x21(ismember(x21,r2)))==r1 22 | x11(ismember(x11,r1))=r2; 23 | x21(ismember(x21,r2))=r1; 24 | y1=[x11 x22]; 25 | y2=[x21 x12]; 26 | else 27 | y1=x1; 28 | y2 = x2; 29 | end 30 | 31 | 32 | 33 | 34 | 35 | end -------------------------------------------------------------------------------- /PermutationMutate.m: -------------------------------------------------------------------------------- 1 | % Permutation Mutation 2 | 3 | function y=PermutationMutate(x) 4 | 5 | M=randi([1 3]); 6 | 7 | switch M 8 | case 1 9 | % Swap 10 | y=DoSwap(x); 11 | 12 | case 2 13 | % Reversion 14 | y=DoReversion(x); 15 | 16 | case 3 17 | % Insertion 18 | y=DoInsertion(x); 19 | 20 | end 21 | 22 | end 23 | 24 | function y=DoSwap(x) 25 | 26 | n=numel(x); 27 | 28 | i=randsample(n,2); 29 | i1=i(1); 30 | i2=i(2); 31 | 32 | y=x; 33 | y([i1 i2])=x([i2 i1]); 34 | 35 | end 36 | 37 | function y=DoReversion(x) 38 | 39 | n=numel(x); 40 | 41 | i=randsample(n,2); 42 | i1=min(i(1),i(2)); 43 | i2=max(i(1),i(2)); 44 | 45 | y=x; 46 | y(i1:i2)=x(i2:-1:i1); 47 | 48 | end 49 | 50 | function y=DoInsertion(x) 51 | 52 | n=numel(x); 53 | 54 | i=randsample(n,2); 55 | i1=i(1); 56 | i2=i(2); 57 | 58 | if i1