Work with massive charts - Traveling seller

I teach how to program algorithms using TSP (Djikstra, Kruskal) and I am looking for advice on starting up. I am working with C # and SQL. Ideally, I would like to be able to do this strictly in SQL, but I'm not sure if this is possible (I assume the runtime will be terrible after 50 vertices).

So, I think the question is, can I only do this SQL, and if so, what is the best approach? If not, and I need to attract C #, what would be the best approach out there?

+6
source share
3 answers

It is advisable to perform simple calculations in SQL, for example, calculate the sum. Amounts are faster in SQL because only sums are returned instead of all records. Complex algorithms like the ones you have in mind must be executed in C # code! Firstly, the SQL language is not suitable for such problems, and secondly, it is optimized for access to db, which makes it very slow for other uses.

Read the data from your db using SQL into the appropriate data structure in your C # program. There is all the logic associated with TSP, and if you want, save the result in db when you're done.

+6
source

Well, I'm not sure if SQL is the best option for this, but you can try using an adjacency matrix for input. Many published algorithms are designed for such input, and after that the only problem is to put the pseudocode in C #. See what it is: http://en.wikipedia.org/wiki/Adjacency_matrix .

You would use a two-dimensional array to represent the matrix.

+1
source

I am going to listen to SQL. Although in reality it was not my first choice for working with TSP - it can still easily do such things - assuming, of course, that the data model is optimal for your efforts.

The first task will be to define a data model that contains the information your algorithm needs, and then fills in some sample data, and then processes the query, which can retrieve arrays as needed.

Finally, you can decide whether any simple SQL will work in this query, or perhaps an extension in the form of a stored procedure.

Finally, you can choose to pull it into your alternative language of choice.

+1
source

Source: https://habr.com/ru/post/905453/


All Articles