主题:大家来看看这个算法是否有问题
首先在这里向各位拜个早年:祝各位心想事成,万事胜意,牛年越来越牛。
这个简单算法是我从《人工智能原理与应用》一书摘录下来的。我越看越觉得不对劲。请各位高手评价一下:
关于三数码的问题(B为空白,其他数字可以移动到空白处)
初始状态:1 3 目标状态:B 3
2 B 1 2
其中的有如下操作:{BL(空格左移),BR(空格右移),BU(空格上移),BD(空格下移)}
原来的算法如下:
algorithm for solving state-space problems
begin
1. state := inital-state;
exiting-state := state;
2. while state <> final-state do
begin
(1) Apply operations from the set{BL,BR,BU,BD} to each state so as to generate new-states
(2) if new-states intersect exiting-states <> null
then do
begin
state := new-states - exiting-states;
exiting-states := exiting-states union state;
end;
end while;
end.
我觉得state出现了问题,应为如果if的条件new-states intersect exiting-states == null
则state还是初始状态,new states还没赋值给state
改进如下:
algorithm for solving state-space problems
begin
1. state := inital-state;
exiting-state := state;
2. while state <> final-state do
begin
(1) Apply operations from the set{BL,BR,BU,BD} to each state so as to generate new-states;
(2) [color=FF0000]if new-states intersect exiting-states <> null
then do
begin
state := new-states - exiting-states;
end
else
begin
state := new-states;
end
(3)exiting-states := exiting-states union state;[/color]
end while;
end.
不知道是不是这样,还望高手们指点迷津,谢谢。[em2]
这个简单算法是我从《人工智能原理与应用》一书摘录下来的。我越看越觉得不对劲。请各位高手评价一下:
关于三数码的问题(B为空白,其他数字可以移动到空白处)
初始状态:1 3 目标状态:B 3
2 B 1 2
其中的有如下操作:{BL(空格左移),BR(空格右移),BU(空格上移),BD(空格下移)}
原来的算法如下:
algorithm for solving state-space problems
begin
1. state := inital-state;
exiting-state := state;
2. while state <> final-state do
begin
(1) Apply operations from the set{BL,BR,BU,BD} to each state so as to generate new-states
(2) if new-states intersect exiting-states <> null
then do
begin
state := new-states - exiting-states;
exiting-states := exiting-states union state;
end;
end while;
end.
我觉得state出现了问题,应为如果if的条件new-states intersect exiting-states == null
则state还是初始状态,new states还没赋值给state
改进如下:
algorithm for solving state-space problems
begin
1. state := inital-state;
exiting-state := state;
2. while state <> final-state do
begin
(1) Apply operations from the set{BL,BR,BU,BD} to each state so as to generate new-states;
(2) [color=FF0000]if new-states intersect exiting-states <> null
then do
begin
state := new-states - exiting-states;
end
else
begin
state := new-states;
end
(3)exiting-states := exiting-states union state;[/color]
end while;
end.
不知道是不是这样,还望高手们指点迷津,谢谢。[em2]