【发布时间】:2016-05-19 14:06:45
【问题描述】:
我正在制作统一成本搜索的程序,但是在我的代码中,当我将节点放入优先级队列时,节点会覆盖......我不知道是什么问题。
例如,如果节点 A 已经存在于值为 10 的队列中,并且如果我再次将节点 A 放入值为 20,那么前一个节点 A 的值也会改变。
有人可以帮忙吗?
while(!queue.isEmpty())
{
Node temp=queue.remove();
System.out.println(temp.city_name+" "+temp.getPath_cost());
path.add(temp);
if(temp==destination)
{
break;
}
System.out.println(temp.link.length);
for(int i=0; i<temp.link.length; i++){
a=temp.link[i].cost;
b=temp.link[i].getParent().getPath_cost();
temp.link[i].getNode().setPath_cost(a+b);
System.out.print(temp.link[i].getNode().city_name+": ");
System.out.println(temp.link[i].getNode().getPath_cost());
queue.add(temp.link[i].getNode());
}
}
【问题讨论】:
标签: java netbeans artificial-intelligence