欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

过河问题matlab建模,matlab三对夫妻过河问题 -凯发k8官方网

发布时间:2024/10/8 循环神经网络 0 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 过河问题matlab建模,matlab三对夫妻过河问题 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

function easy

%***********************初始化参数,堆栈**************************

table=[-1 -1 -1;-2 0 -1;0 -2 -1;0 -1 -1;-1 0 -1;-1 -1 -1;-2 0 -1;0 -2 -1;0 -1 -1;-1 0 -1];

op=[1 1 1 1 1 -1 -1 -1 -1 -1];

boat=[6:10;1:5];

vis=zeros(1,64);

path=zeros(1,64);

stack_depth=10000;

max_step=100;

init=[3,3,1];

space=zeros(stack_depth,3);

cnt=1;

push(init);

%***********************搜索节点,找到终点**************************

for step=1:max_step

father=pop();

if all(father(1:2)==0)

disp('找打解!!!')

break;

else visited(father)

end

sub=boat(father(3) 1,:);

for i=sub

son=father op(i)*table(i,:);

if  islegal(son)&&~havevisited(son)

push(son);

insertpath(son,father);

end

end

end

%***********************处理结果,找出路径**************************

p=path(1);

state(1:3)=expand(1);

for i=1:64

[a,b,c]=expand(p);

if all([a b c]==[3 3 1])

state=[state;[a b c]];

break;

else

state=[state;[a b c]];

p=path(p);

end

end

state=flipud(state);

change=[0 0 0;diff(state)];

gostr={'->','

for i=1:size(state,1)

go=gostr{mod(i,2) 1};

businessman=abs(change(i,1));

serv=abs(change(i,2));

disp(['第',num2str(i-1,'%-.2d'),'步:',num2str(businessman),'商人',num2str(serv),'仆人',go,' :左边(',num2str(state(i,1)),',',num2str(state(i,2)),')右边(',num2str(3-state(i,1)),',',num2str(3-state(i,2)),')'])

end

%***********************堆栈进栈、出栈操作**************************

function push(element)

space(cnt,:)=element;

cnt=cnt 1;

if cnt>stack_depth

error('栈溢出')

end

end

function element=pop()

if cnt<2

error('栈为空')

end

cnt=cnt-1;

element=space(cnt,:);

end

%***********************访问状态表**************************

function visited(node)

index=node(1)*16 node(2)*4 node(3) 1;

vis(index)=1;

end

function bool=havevisited(node)

index=node(1)*16 node(2)*4 node(3) 1;

bool=(vis(index)==1);

end

%**********************添加关系路径**************************

function insertpath(son,father)

index_father=father(1)*16 father(2)*4 father(3) 1;

index_son=son(1)*16 son(2)*4 son(3) 1;

path(index_son)=index_father;

end

end

%**********************判断节点是否合法**************************

function bool=islegal(states)

l=states(1:2);

r=[3,3]-states(1:2);

% if  (l(2)>l(1)&&l(1)>0)||(r(2)>r(1)&&r(1)>0)||any(l<0)||any(r<0)

if  all(diff([0,l])>0)||all(diff([0,r])>0)||any(l<0)||any(r<0)

bool=false;

else

bool=true;

end

end

%**********************展开得到状态**************************

function [a,b,c]=expand(p)

a=fix(p/16);

c=mod(p,4)-1;

b=(p-16*a-c-1)/4;

end

总结

以上是凯发k8官方网为你收集整理的过河问题matlab建模,matlab三对夫妻过河问题的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图