java,debugging,traveling-salesman,hamiltonian-cycle

The problem is that when you swap outgoing[i] and outgoing[j], you are creating two subtours -- two smaller cycles. For example, suppose numcities=6 and your starting tour is 0 1 2 3 4 5. Suppose your if statement is true for i=1, j=3. Your code sets outgoing[1] = 4 and...

algorithm,haskell,artificial-intelligence,traveling-salesman

After a lot of work I found an example where the best path determined by findBestMove at level 1 returns a worse path than when called with level set to 0: points = [(6,8),(9,7),(9,4),(4,10),(4,6),(7,10),(5,7),(2,4),(8,8),(6,5)] start: (1,10) level = 0: cost: 31 path: [(1,10),(4,10),(7,10),(5,7),(6,8),(8,8),(9,7),(9,4),(6,5),(4,6),(2,4)] level = 1: cost: 34 path: [(1,10),(2,4),(6,5),(6,8),(5,7),(4,6),(4,10),(7,10),(8,8),(9,7),(9,4)]...

java,android,arraylist,traveling-salesman

I think your error is in the second line of your for loop. The variable d is never being incremented, so you are always using points 0 and 1. Personally, I would get rid of the d variable and just use i like this: c = test.get(i+1); However, another option...

java,arraylist,traveling-salesman

You should start be deciding what you have and what you want. What you have For a fitness function for Travelling Salesman Problem, according to your pseudo-code, you will have following input. Number of cities A tour whose fitness is to be calculated Map with distances (in this case adjacency...

Just take any Vehicle Routing Problem with Time Windows (VRPTW) implementation and add only 1 vehicle to get a TSP with TW. Here's an open source (Apache License), Java implementation of VRPTW: Code - Docs - Video. But there are plenty more, just google for VRPTW....

python,algorithm,traveling-salesman

If anyone will search answer, I did it! import math x = int(input("How many cities? ")) a = math.factorial(x) print("For", x, "cities, there are", a, "possible routes") ...

c++,algorithm,traveling-salesman

Here is a traditional TSP problem ,and here is the solution for it . I think it may be helpful to you. int map[15][15]; int dp[(1<<12)+5][12]; int main() { int i,j,n,ans,k,p; while(1) { scanf("%d",&n); if (n==0) break; n++; for (i=0; i<n; i++) { for (j=0; j<n; j++) { scanf("%d",&map[i][j]); }...

algorithm,traveling-salesman,approximation

If you have vertices A, B, C, with edge costs wAB, wAC and wBC, and suppose the triangle inequality doesn't hold. Say wBC > wAB + wAC. Then, suppose we're starting at A, the approximation algorithm will find a minimum spanning tree with root A. This is: A / \...

c#,optimization,traveling-salesman

Does your code for making the improved tour correctly handle the duplicate node at the end? If the duplicate node is an endpoint of one of the edges that is being swapped, I don't think you correctly adjust the start node -- and the same thing if node 0 is...

algorithm,dijkstra,shortest-path,traveling-salesman

You can reduce your graph to a TSP and then invoke a TSP algorithm on it: Use Floyd-Warshall algorithm to find the distance u,v for ALL pairs of vertices u and v. Create a new graph, containing only the "desired" vertices, and set the weight between two such vertices u...

algorithm,linear-algebra,linear-programming,cplex,traveling-salesman

According to this Wikipedia article the travelling salesman problem can be modelled as an integer linear program, which I believe to be the key issue of the question. The idea is to have decision variables of permitted values in {0,1} which model selected edges in the graph. Suitable constraints must...

algorithm,optimization,graph-theory,traveling-salesman

Safe Moves Here are some ideas for safely mutating an existing feasible solution: Any two consecutive stops can always be swapped if they are both pickups, or both deliveries. This is obviously true for the "both deliveries" case; for the "both pickups" case: if you had room to pick up...

r,traveling-salesman,hamiltonian-cycle

As the comments suggest, your question is related to the Traveling Salesman Problem. It is in fact an example of a Hamiltonian path (a path which visits each node once, but does not end where it started). As you might expect, in R there's already a package for that: TSP....

Basically you are looking for 3 edges to remove and then reinsert. So for example: for ( uint a = 1 ; a < currSol.sequence.size() - 3 ; a++ ) ... for ( uint b = a + 1 ; b < currSol.sequence.size() - 2 ; b++ ) ... for...

python,combinations,combinatorics,puzzle,traveling-salesman

Problem is called maximum matching in bipartite graph or assignment problem. It is done by Hungarian algorithm. On Wikipedia page are implementations in different languages. There is python library munkres with an implementation....

algorithm,mathematical-optimization,traveling-salesman,ant-colony

1) You'd usually store the best-so-far path of all iterations (as in Elitist Ant System etc.), which is also the final result then. 2) With cycle you mean iteration? Anyway, as for "Path found on this level or not", I'd only allow successful (complete) paths in the first place, or...

EUC_2D is the rounded L2 norm. That is, the distance between two points is taken to be their Euclidean distance rounded to the nearest integer. Your points are all going to be at distances 0 or 1 to one another and Concorde is going to generate a daft tour like...