I wonder if there is a way to get the path (not only the distance) chosen by brute force algorithm (TSP)in my solution like i get only the distance.
Notice that I started from City Stockholm and ended at Stockholm.
- The shortest path is city1 --> City2 --> City3 ----> .......then ---> City1 ?
A part of my main class:
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;
}
}
}