如何在另一个遗传算法程序中使用一个遗传算法程序的输出

发布于 2025-01-13 05:35:36 字数 1768 浏览 1 评论 0原文

假设我们有方程

t = 122.14-0.84.*x(1)-0.42.*x(2)+0.34.*x(3)-0.09.*x(4)+363.77.*x( 5);

它有 5 个变量,并且有一些下限和上限。我执行遗传算法并得到最佳值作为答案。现在我得到这 5 个变量的值。我想在另一个方程中使用它们 -

s = - 463.21-3.05x(1) + 5.21x(2)+0.54x(3) +0.11x(4)-6541.17x(5) + 41.67 x(6)。

它有 6 个变量(变量 x(1) 到 x(5) 相同),x(6) 未知,并且有一些下限和上限。在这里,我希望将先前方程的输出作为第二个方程中 x(1) 到 x(5) 变量的输入,并且 x(6) 将被视为具有一定边界的未知变量。

PS:-因为每当我运行遗传算法时,第一个方程的输出都会改变,我希望您在代码中提供帮助,其中第一个方程中的 x(1) 到 x(5) 变量的输出将自动分配在我的第二个方程中。现在,我希望你明白了。感谢您对问题感兴趣。

                    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;
            if any(mask)
                state.StopFlag = 'range statisfied';
                state.Score = state.Score(mask);
                state.Population = state.Population(mask,:);
                state.Best(end) = state.Score(end);
            end
        case 'done'
    end
end

这是我对第一个方程的 GA 调用函数:-

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))

我想要的只是使用第一个方程的数据(输出)来查找给出了适应度函数的第二个方程的答案 这里变量 x(1) 到 x(5) 变量与第一个方程相同。只是添加了一个新变量 x(6)。

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);
lower and upper bound of x(6)-
lb=1.50
ub=9.0

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 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.

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.

                    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;
            if any(mask)
                state.StopFlag = 'range statisfied';
                state.Score = state.Score(mask);
                state.Population = state.Population(mask,:);
                state.Best(end) = state.Score(end);
            end
        case 'done'
    end
end

this is my calling function of GA for 1st equation:-

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 for finding the answer of 2nd equation whose fitness function is given
hereand variable x(1) to x(5) variable are same from 1st equation. just a new variable x(6) is added.

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);
lower and upper bound of x(6)-
lb=1.50
ub=9.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文