거리 만 얻을 수있는 것처럼 내 솔루션에서 무차별 알고리즘 (TSP)으로 선택한 경로 (거리가 아님)를 얻는 방법이 있는지 궁금합니다.여행 세일즈맨 (TSP) 실제 경로를 얻는 것
저는 스톡홀름시에서 출발하여 스톡홀름에서 끝났습니다.
- 가장 짧은 경로는 city1 -> City2 -> City3 ----> ....... then ---> City1입니까?
내 메인 클래스의 일부 :
public void step(boolean[] wentTo, int currentCity, float distance)
{
int wentToCount = 0;
for (int i = 1; i <= cityCount; ++i)
{
if (wentTo[i - 1])
{
++wentToCount;
continue;
}
boolean[] copy = new boolean[cityCount];
System.arraycopy(wentTo, 0, copy, 0, cityCount);
copy[i - 1] = true;
float dist = distance + distances[distanceIndex(currentCity, i)];
step(copy, i, dist);
}
if (wentToCount == cityCount)
{
if (shortest > distance)
{
shortest = distance;
}
}
}
계산 과정에서 변수에 등록하는 것이 문제가되지 않습니까? 알고리즘이 나중에 anoter 경로를 결정하는 경우 재설정 중. –
@ OleV.V. 친절하게 코드로 보여 주시겠습니까? –