travelling-salesman-problem | C | Architecture library
kandi X-RAY | travelling-salesman-problem Summary
kandi X-RAY | travelling-salesman-problem Summary
The Travelling Salesman Problem - parallel with OpenMP. C++
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of travelling-salesman-problem
travelling-salesman-problem Key Features
travelling-salesman-problem Examples and Code Snippets
def tabu_search(
first_solution, distance_of_first_solution, dict_of_neighbours, iters, size
):
"""
Pure implementation of Tabu search algorithm for a Travelling Salesman Problem in
Python.
:param first_solution: The solution for
Community Discussions
Trending Discussions on travelling-salesman-problem
QUESTION
I'm following an online course in which one of the assignments is to implement a dynamic programming algorithm to solve the Traveling Salesman Problem (TSP). My Python implementation works for small cases (~5 cities), but for the 'real' application of 25 cities it seems to be very slow. I'm looking for suggestions to speed up the algorithm.
The algorithm is described in the following excerpts:
The dynamic programming solution is also described at http://www.geeksforgeeks.org/travelling-salesman-problem-set-1/, where additional references are given.
The problem statement of the assignment is:
I've implemented the pseudocode using a pandas DataFrame
object for the array A
. Since sets are not hashable and can't be used as indices, I've instead used tuples, taking care to sort them in order to make them unique representations of sets. Here is the code along with several test cases of increasing size:
ANSWER
Answered 2017-Sep-20 at 22:00Some ideas how to improve performance:
- instead of tuples use 32 bit ints to represent your subsets - this should be enough if you have no more than 32 cities
- on each step you need previously calculated values for subsets of size m - 1 only (you don't have to store any values for subsets of size m-2, m-3 etc.) - this may vastly reduce your memory usage
QUESTION
Good evening guys,
Currently working on a piece of code with arrays that would be deleted if a condition is met. After trying it with array_unset I decided to use array_splice to not destroy the id-structure. Unfortunately I have the same problem:
...ANSWER
Answered 2017-Feb-11 at 00:04I tried to simplify your code as much as possible according to your description. If something will be unclear, don't hesitate to ask. I omitted the 'next_city' item in the result, because it seems unnecessary (due to same data in the next item), but the code can be easily altered.
Worth to mention those things after reviewing your code:
- try to use variable variables ${xy} only when it's necessary, it's less readable, even for you after a year or two :-)
- when you're dealig with iterables (e.g. arrays) with unclear index, use foreach loop instead of for. You won't come into problems with undefined indexes when you remove items from array.
The final code (without array definition):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install travelling-salesman-problem
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page