24小时热门版块排行榜    

查看: 2433  |  回复: 7
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

free0121

木虫 (著名写手)

[求助] 关于全局最优法和遗传算法 已有2人参与

大家好,最近尝试了一下遗传算法,初始种群是系统随机抽取的,以致于每次算出来的结果都不太一样。本来想说通过遗传算法得到接近全局最优的解,结果这些解好像都是局部最优。于是尝试了一个全局最优的算法,先做了个小实验,但不成功。希望大侠们帮忙看看问题出在哪里了,不胜感激!
对于遗传算法很熟悉的朋友,也向大家请教一下在使用遗传算法时当注意什么问题,怎么使得到的解能比较接近全局最优。谢谢!

function main
    clear all
    close all
    clc

    A=[];b=[];
    Aeq=[];beq=[];
    lb=[0.2;0.1];
    ub=[4.0;1.6];
    x0=[2.5;1.0];
      
    opts1 = optimset('Algorithm','interior-point');
    opts2 = optimset('Algorithm','sqp');
    opts3 = optimset('Algorithm','trust-region-reflective');
    opts4 = optimset('Algorithm','active-set');
   
    problem1 = createOptimProblem('fmincon','objective',...
         @objfun,'x0',x0, 'Aineq', A, 'bineq', b, 'nonlcon', @mycon, 'options',opts1);
    problem2 = createOptimProblem('fmincon','objective',...
         @objfun,'x0',x0, 'Aineq', A, 'bineq', b, 'nonlcon', @mycon, 'options',opts2);
    problem3 = createOptimProblem('fmincon','objective',...
         @objfun,'x0',x0, 'Aineq', A, 'bineq', b, 'nonlcon', @mycon, 'options',opts3);
    problem4 = createOptimProblem('fmincon','objective',...
         @objfun,'x0',x0, 'Aineq', A, 'bineq', b, 'nonlcon', @mycon, 'options',opts4);
    gs = GlobalSearch;
    [x1,fval1] = run(gs,problem1);
    [x2,fval2] = run(gs,problem2);
    [x3,fval3] = run(gs,problem3);
    [x4,fval4] = run(gs,problem4);
end

% objective function
function f0=objfun(x)
f0=x(1)*sqrt(1.0+x(2)^2);
end

% constraint function
function [f,ceq]=mycon(x)
f=(0.124*(8.0/x(1)+1.0/(x(1)*x(2)))*sqrt(1.0+x(2)^2))-1.0;
ceq=[];
end

运行后得到

GlobalSearch stopped because it analyzed all the trial points.
1 out of 39 local solver runs converged with a positive local solver exit flag.
No solution found.

GlobalSearch did not find any solutions after 399 local solver runs.
Warning: The default trust-region-reflective algorithm does not solve problems
with the constraints you have specified. FMINCON will use the active-set
algorithm instead. For information on applicable algorithms, see Choosing the
Algorithm in the documentation.
> In fmincon at 486
  In C:\Program Files\MATLAB\R2011b\toolbox\globaloptim\globaloptim\private\globalsearchnlp.p>globalsearchnlp at 152
  In GlobalSearch>GlobalSearch.run at 330
  
GlobalSearch stopped with one or more of the local solver runs stopping prematurely.

15 out of 39 local solver runs exceeded the iteration limit (problem.options.MaxIter) or
the function evaluation limit (problem.options.MaxFunEvals).
None of the 39 local solver runs converged with a positive local solver exit flag.

GlobalSearch stopped with one or more of the local solver runs stopping prematurely.

13 out of 36 local solver runs exceeded the iteration limit (problem.options.MaxIter) or
the function evaluation limit (problem.options.MaxFunEvals).
None of the 36 local solver runs converged with a positive local solver exit flag.

这是为什么呢?
回复此楼

» 收录本帖的淘帖专辑推荐

计算机应用

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

free0121

木虫 (著名写手)

哦,自己發現問題所在了~~
2楼2014-01-20 21:46:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

free0121

木虫 (著名写手)

是的,所谓全局最优也无法找到最优解,但是它可以搜索到很多局部最优解,然后从这些局部最优解中找出最优的解。这个方法不适合计算量大的问题。3楼说的遗传算法要注意的问题确实是那样,弄不好得到的解会很糟糕。
6楼2014-02-04 03:42:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 free0121 的主题更新
信息提示
请填处理意见