您好我正在为TSP类似问题构建本地搜索启发式,并遇到了一些错误。我正在使用从使用构造性启发式(solConstr)获得的序列,当我运行代码时,存在一个常量"编译错误:for without next"和#34; End Sub"的亮点。任何人都可以帮我找到这个bug,非常感谢!
这是我的代码:
For b = 1 To Count
For pos = b + 1 To Count
changePosition = solConstr.Sequence(b)
For c = 1 To Count
If c >= 1 And c <= b - 1 Then
solTemp.Sequence(c) = solConstr.Sequence(c)
ElseIf c >= b And c <= pos - 1 Then
solTemp.Sequence(c) = solConstr.Sequence(c + 1)
ElseIf c >= pos + 1 And c <= Count Then
solTemp.Sequence(c) = solConstr.Sequence(c)
End If
solTemp.Sequence(pos) = changePosition
Call EvaluateSolution(shoppingInfo, solTemp)
currentCost = solTemp.Cost
MsgBox ("change" & b & "to" & pos & "will incur updated cost of" & currentCost)
If currentCost < newcost Then newcost = currentCost
For d = 1 To Count
solTemp.Sequence(d) = solLS.Sequence(d)
Next
Next
Next
Next
这是伪代码:
数据:n,c [ij],sol [i],sNew [i],i = 0 ,. 。 。 ,n - 1
结果:newCost
currentCost = ComputeCost(n,c [ij],sol [i],i = 0,...,n - 1);
对于k = 0到n - 1做
对于pos = 0到n - 1,pos 6 =我做
cost = EvaluateSol(n,c [ij],sol [i],i = 0,...,n - 1,k,pos);
如果成本&lt; currentCost然后
currentCost = cost;
更新sNew [i],i = 0 ,. 。 。 ,n - 1;
返回sNew;
端
端
端