爬山算法matlab程序,爬山对焦算法Matlab版

概念

爬山算法是一种局部择优的方法,采用启发式方法,是对深度优先搜索的一种改进,它利用反馈信息帮助生成解的决策。 属于人工智能算法的一种。

算法优缺点

优点

避免遍历,通过启发选择部分节点,从而达到提高效率的目的。

缺点

因为不是全面搜索,所以结果可能不是最佳。

爬山算法一般存在以下问题:

1)、局部最大:某个节点比周围任何一个邻居都高,但是它却不是整个问题的最高点。

2)、高地:也称为平顶,搜索一旦到达高地,就无法确定搜索最佳方向,会产生随机走动,使得搜索效率降低。

3)、山脊:搜索可能会在山脊的两面来回震荡,前进步伐很小。

function result=findlocation(new_location,step,flag,new_method,is_reverse)

num=size(new_method,1);

tmp_init=new_location;

if step==0

result=new_location;

return ;

end

if is_reverse

num=0;

step=0-step;

end

if flag==0

for i=tmp_init:step:num

if new_method(i+step,1)-new_method(i,1)<=0

if i-step<=0

startnum=1;

else

startnum=i-step;

end

if new_method(startnum,1)-new_method(i,1)>0

is_reverse=1;

flag=1;

new_location=i-step;

step=floor(step/2);

if step==0

result=new_location;

return ;

end

result=findlocation(new_location,step,flag,new_method,is_reverse);

return;

else

flag=1;

new_location=i;

step=floor(step/2);

if step==0

result=new_location;

return ;

end

result=findlocation(new_location,step,flag,new_method,is_reverse);

return;

end

else

new_location=i+step;

end

end

end

if flag==1

for i=tmp_init:step:num

if new_method(i+step,1)-new_method(i,1)>0

new_location=i+step;

else

flag=0;

new_location=i;

step=floor(step/2);

if step==0

result=new_location;

return ;

end

result=findlocation(new_location,step,flag,new_method,is_reverse);

return;

end

end

end

clc

clear all

close all

global new_location

load('new_method.mat');

num=size(new_method,1);

% two step for climb

init_location=10;

new_location=init_location;

step=20;

flag=1;

is_reverse=0;

result=findlocation(new_location,step,flag,new_method,is_reverse);

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值