I am new to Java. I have just written a code to solve the travelling salesman problem. I have applied the nearest neighborhood search to find the solution. Suppose, my input city was as follows:
(60,200),(80,180),(140,180),(20,160),(180,200)
input is in (x,y) co ordinate format. I get the solution in the following format:
(60,200),(140,180),(80,180),(180,200),(20,160)
now I want to take each possible pair of edges and calculate the euclidean distance between them. I know how to calculate the euclidean distance but how I will choose each pair of edges. I know I have to use nested loops but getting confused of what to do next.
Suppose I have stored the solution in the following arraylist:
private ArrayList tour = new ArrayList<City>();
Now how I will select each pair of edges from this arraylist? I have tried in the following way but getting stuck.
int i,j;
for(i=0;i<tour.size();i++)
{
for(j=i+1;j<tour.size();j++)
{
}
}