traveling-salesman

Building ranking with genetic algorithm,

元气小坏坏 提交于 2019-12-23 17:15:08
问题 Question after BIG edition : I need to built a ranking using genetic algorithm, I have data like this : P(a>b)=0.9 P(b>c)=0.7 P(c>d)=0.8 P(b>d)=0.3 now, lets interpret a,b,c,d as names of football teams, and P(x>y) is probability that x wins with y . We want to build ranking of teams, we lack some observations P(a>d) , P(a>c) are missing due to lack of matches between a vs d and a vs c. Goal is to find ordering of team names, which the best describes current situation in that four team league

Least cost path in a sorted array

一世执手 提交于 2019-12-22 10:55:15
问题 Given a sorted array A e.g. {4,9,10,11,19} . The cost for moving from i->j is abs(A[j]-A[i]) . Start from a given element e.g. 10 . Find out the least cost path without visiting same element twice. So in this example solution would be 10->9->4->11->19 i.e. 1 + 5 + 7 + 8 = 21 . I tried to solve this using nearest neighbor approach. i = start; While (array is not empty) ldiff = A[i] - A[i-1] rdiff = A[i+1] - A[i] (ldiff < rdiff) ? sum += ldiff : sum += rdiff remove A[i] This solution does not

Traveling salesman example with known global optimum

泪湿孤枕 提交于 2019-12-22 05:16:16
问题 I made a memetic algorithm in Python for traveling salesman problem. However, all the test data (list of distances between cities) I've encountered lack the information of the best solution, so I can't know how close to global optimum my algorithm gets. Does anyone know where I can find some tsp test data (preferably in matrix form, but anything's good) with known best solution? 回答1: Did you google? http://www.tsp.gatech.edu/data/index.html That page provides several test-cases of which 16

How to implement a dynamic programming algorithms to TSP in Python?

穿精又带淫゛_ 提交于 2019-12-21 18:04:07
问题 I want to solve the TSP problem using a dynamic programming algorithm in Python.The problem is: Input: cities represented as a list of points. For example, [(1,2), (0.3, 4.5), (9, 3)...]. The distance between cities is defined as the Euclidean distance. Output: the minimum cost of a traveling salesman tour for this instance, rounded down to the nearest integer. And the pseudo-code is: Let A = 2-D array, indexed by subsets of {1, 2, ,3, ..., n} that contains 1 and destinations j belongs to {1,

Neo4J - Traveling Salesman

一世执手 提交于 2019-12-21 06:57:31
问题 I'm trying to solve an augmented TSP problem using a graph database, but I'm struggling. I'm great with SQL, but am a total noob on cypher. I've created a simple graph with cities (nodes) and flights (relationships). THE SETUP: Travel to 8 different cities (1 city per week, no duplicates) with the lowest total flight cost. I'm trying to solve an optimal path to minimize the cost of the flights, which changes each week. Here is a file on pastebin containing my nodes & relationships. Just run

Minimum cost strongly connected digraph

我只是一个虾纸丫 提交于 2019-12-21 02:05:12
问题 I have a digraph which is strongly connected (i.e. there is a path from i to j and j to i for each pair of nodes (i, j) in the graph G). I wish to find a strongly connected graph out of this graph such that the sum of all edges is the least. To put it differently, I need to get rid of edges in such a way that after removing them, the graph will still be strongly connected and of least cost for the sum of edges. I think it's an NP hard problem. I'm looking for an optimal solution, not

Optimal map routing with Google Maps

别说谁变了你拦得住时间么 提交于 2019-12-20 08:49:57
问题 Is there a way using the Google Maps API to get back an "optimized" route given a set of waypoints (in other words, a "good-enough" solution to the traveling salesman problem), or does it always return the route with the points in the specified order? 回答1: There is an option in Google Maps API DirectionsRequest called optimizeWaypoints, which should do what you want. This can only handle up to 8 waypoints, though. Alternatively, there is an open source (MIT license) library that you can use

Minimal Distance Hamiltonian Path Javascript

自作多情 提交于 2019-12-18 13:20:49
问题 I know this is a fairly frequent question (tsp in general), but I've been stumped by it for awhile now. I'm looking to find the minimal distance hamiltonian path given a set of x,y coordinates. The start and end point are completely arbitrary but it must NOT cycle, so standard tsp is out (although supposedly adding a dummy point at 0 distance to all other nodes and then removing it later works, i have no idea how I'd do that). There are plenty of links to math papers and the like discussing

Travelling Salesman with multiple salesmen?

扶醉桌前 提交于 2019-12-17 10:44:39
问题 I have a problem that has been effectively reduced to a Travelling Salesman Problem with multiple salesmen. I have a list of cities to visit from an initial location, and have to visit all cities with a limited number of salesmen. I am trying to come up with a heuristic and was wondering if anyone could give a hand. For example, if I have 20 cities with 2 salesmen, the approach that I thought of taking is a 2 step approach. First, divide the 20 cities up randomly into 10 cities for 2 salesman

Dynamic programming approach to TSP in Java

亡梦爱人 提交于 2019-12-14 03:44:00
问题 I'm a beginner, and I'm trying to write a working travelling salesman problem using dynamic programming approach. This is the code for my compute function: public static int compute(int[] unvisitedSet, int dest) { if (unvisitedSet.length == 1) return distMtx[dest][unvisitedSet[0]]; int[] newSet = new int[unvisitedSet.length-1]; int distMin = Integer.MAX_VALUE; for (int i = 0; i < unvisitedSet.length; i++) { for (int j = 0; j < newSet.length; j++) { if (j < i) newSet[j] = unvisitedSet[j]; else