Java 在TSP的这个代码中没有绑定?
我想知道我如何做边界,因为我生成了所有可能的解矩阵tsp,但没有边界。问题在于旅行推销员。有可能这样做吗Java 在TSP的这个代码中没有绑定?,java,branch-and-bound,Java,Branch And Bound,我想知道我如何做边界,因为我生成了所有可能的解矩阵tsp,但没有边界。问题在于旅行推销员。有可能这样做吗 public void bnb (int from, ArrayList followedRoute) { if (followedRoute.size() == distances.getMatrix().get(0).size()) { followedRoute.add(sourceCity); nodes++; // upd
public void bnb (int from, ArrayList followedRoute) {
if (followedRoute.size() == distances.getMatrix().get(0).size()) {
followedRoute.add(sourceCity);
nodes++;
// update the route's cost
routeCost += distances.getCost(from, sourceCity);
if (routeCost < optimumCost) {
optimumCost = routeCost;
optimumRoute = (ArrayList)followedRoute.clone();
result += followedRoute.toString() + "// Cost: "+ routeCost + "\n";
System.out.println(result);
}
routeCost -= distances.getCost(from, sourceCity);
}
else {
for (int to=0; to < distances.getMatrix().get(0).size(); to++){
if (!followedRoute.contains(to)) {
// update the route's cost
routeCost += distances.getCost(from, to);
if((routeCost < optimumCost) ) {
ArrayList increasedRoute = (ArrayList)followedRoute.clone();
increasedRoute.add(to);
nodes++;
bnb(to, increasedRoute);
}
routeCost -= distances.getCost(from, to);
}
}
}
}
public void bnb(int-from,ArrayList-followedroote){
if(followDurote.size()==distance.getMatrix().get(0.size()){
followedroote.add(sourceCity);
节点++;
//更新路线的成本
routeCost+=距离.getCost(从,源城市);
如果(路线成本<最佳成本){
最优成本=路线成本;
optimumRoute=(ArrayList)followDurote.clone();
结果+=followDurote.toString()+“//成本:“+routeCost+”\n”;
系统输出打印项次(结果);
}
routeCost-=距离.getCost(从,源城市);
}
否则{
for(int-to=0;to
我很抱歉将此添加为答案,我只想将其添加为一条评论,以供您参考另一个SE问题,但我没有足够的声誉添加评论
除了任何人之外,您可能无法为您提供计算边界的实现,但对于理论,请参考先前在SE上提出的类似问题。
上述问题的两个给定答案都提供了在分支和边界(BAB)上下文中对TSP进行全面解释的链接,包括如何计算BAB分支的下界。回想一下,您在BAB过程中的上界仅仅是当前最好的现有解决方案(当前最佳路径),正如前面在BAB树中或通过启发式发现的那样