在JavaScript中为*生成启发式查找表
我的数组中存储了一些stage在JavaScript中为*生成启发式查找表,javascript,algorithm,lookup,a-star,heuristics,Javascript,Algorithm,Lookup,A Star,Heuristics,我的数组中存储了一些stage class Stage{ constructor(id){ this.id = id; } } 这些阶段与其他阶段相连。他们甚至可能与自己有关 class Activity{ constructor(fromId, toId){ this.fromId = fromId; this.toId = toId; } } 所以我得到了一些测试数据 const stages = [
class Stage{
constructor(id){
this.id = id;
}
}
这些阶段与其他阶段相连。他们甚至可能与自己有关
class Activity{
constructor(fromId, toId){
this.fromId = fromId;
this.toId = toId;
}
}
所以我得到了一些测试数据
const stages = [
new Stage(1),
new Stage(2),
new Stage(3),
new Stage(4),
new Stage(5),
new Stage(6),
new Stage(7),
new Stage(8)
];
const activities = [
new Activity(1, 2),
new Activity(2, 3),
new Activity(2, 4),
new Activity(2, 7),
new Activity(3, 5),
new Activity(4, 6),
new Activity(5, 2),
new Activity(7, 3),
new Activity(7, 4),
];
我想为我的A*算法生成这个查找表。我想从中得到启发
当我想设置当前执行的节点的启发式时
getHeuristic(neighbourId, targetId){
// Look Up Table
return 0;
}
其中neighbourId表示当前邻居,目标id是要到达的最后一个单元格
重要提示:
我的算法总是从id 1开始。所以我总是试图得到从id 1到x的路径。也许这对查找表很重要
有可能计算一个吗?是什么让你认为这是一个合理的启发?通常,启发式是由一些“真实世界”条件产生的。例如,在传输网络中,启发式类似于“最接近目标节点”。如果对“阶段”和“活动”一无所知,就不会有合理的启发。嗯,没有比这更多的信息了。。。