# how can i use the output of one genetic algorithm program in another GA programme.

2 views (last 30 days)
harsh Brar on 11 Mar 2022
Edited: harsh Brar on 14 Mar 2022
lets say we have the equation
t = 122.14-0.84.*x(1)-0.42.*x(2)+0.34.*x(3)-0.09.*x(4)+363.77.*x(5);
It have 5 variables and have some lower and upper bounds. i perform genetic algorithm and got optimum values as answers. now whatever value I got for these 5 variables. I want to use them in another equation which is
s = - 463.21-3.05x(1) + 5.21x(2)+0.54x(3) +0.11x(4)-6541.17x(5) + 41.67x(6).
It have 6 variables ( variable x(1) to x(5) are same ) and x(6) is unknown and have some lower and upper bounds . here, i want the output from my previous equation(i.e. equation1 ) as an input of x(1) to x(5) variable in 2nd equation and x(6) will be treated as unknown variables having some bounds ofc.
Inshort, i want to use the answer of 5 variable from 1st equation in 2nd equation.
ps:- Since whenever I run a genetic algorithm, the output of first equation is going to change, i want your help in the code in which the output of x(1) to x(5) variable from 1st equation will automatically get assigned in my 2nd equation. now, i hope you got it. thank you for taking interest in question.
this general coding for 1st equation
function t=strength(x)
t = 122.14-0.84.*x(1)-0.42.*x(2)+0.34.*x(3)-0.09.*x(4)+363.77.*x(5);
end
function [state,options,optchanged] = stop40_80(options,state,flag)
optchanged = false;
switch flag
case 'init'
case 'iter'
% Find the best objective function, and stop if it is right range
mask = state.Score >= 40 & state.Score <= 80;
state.StopFlag = 'range statisfied';
state.Best(end) = state.Score(end);
end
case 'done'
end
end
this is my calling function of GA for 1st equation:-
options = optimoptions('ga','MutationFcn', @mutationadaptfeasible, 'CrossoverFcn', {@crossoverintermediate, 0.7}, 'SelectionFcn', {@selectiontournament,3}, 'PlotFcn', {@gaplotselection, @gaplotbestf, @gaplotbestindiv, @gaplotrange}, 'FitnessLimit', -inf, 'MaxGenerations', 1e5);
A = []; b = []; Aeq = []; beq = []; lb = [29 160 30 0 0.040]; ub = [50 180 60 20 0.069]; nonlcon = [];
obj = @(x) (strength(x)-80).^2;
bestx = ga(obj, 5, A, b, Aeq, beq, lb, ub, nonlcon, options);
display(bestx)
display(strength(bestx))
All I want is use this data (output) from 1st equation( Basically output of variables x(1) to x(5)) for finding the answer of 2nd equation whose fitness function is
s= -463.21-3.05.*x(1)+5.21.*x(2)+0.54.*x(3)+0.11.*x(4)-6541.17.*x(5)+41.67.*x(6);
here variable x(1) to x(5) variable are same from 1st equation
lower and upper bound of x(6)-
lb=1.50
ub=9.0

### Categories

Find more on Genetic Algorithm in Help Center and File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by