I have never encountered logistics, only in theory at the institute. Imagine a lot of points connected by lines. Points WITHOUT coordinates (x, y, z). Dots have names - these are points of unloading, loading, and the lines connecting them are mashruts. To get a route you need to set the starting point and the final one. And the program already gives the number of waypoints and their names. Here is an example: Map with points

And the question is how to properly store these relationships in the database so that I can effectively route and have an idea of ​​the number of points being crossed?

I tend to the method that you first need to create a table of unique point names with id PRYMARY AUTO_INCREMENT

Then do something like

SELECT t1.`name`,t2.`name` AS `second_name` FROM `table` t1 FULL JOIN `table` t2 ON t1.`name`!=t2.`name` 

and check if there is a connection between them, if there is, then write many to many in a table (a pair, like their id in a couple of columns)

Or go the other way and check how many dots between them and determine their id

The first method is flexible, since it will be possible to choose routes. And the second one is faster - it gives an unambiguous option and you don’t need to count anything, only if you need non-linear routes but with races to the neighboring ones, then I don’t know what some formula will be needed either.

In the first case, I will have to build two trees with linked branches, where their bases are the starting and ending points, all the linked branches are paths, and the shortest path is the desired one.

If someone faced with such tasks - tell me where to look for information.

Thank.

  • four
    Undirected graph Adjacency matrix. Search for the (shortest) way. In my opinion, the terms for the search is enough. If not, they will complement me. Ps. Actually, the problem is not for SQL, although it is completely solvable. And even sometimes quite effectively. - Akina
  • Akina - thank you. It is useful to study if you can find a solution to post it here. By the way, the metro scheme fits in perfectly well; there, too, there are points and lines connecting them. The problem from the category of how many stations to travel from one point to another. - Mcile
  • @Mcile The Metropolitan is a bit off of that opera. There are transit nodes. And transplantation is quite an expensive operation. - Akina

0