9
I’m doing a logging system that addresses the issue of routes/routing. Where I should choose the best route to travel.
Initially I am only doing some tests and testing advanced algorithms, what I am doing seems to be something illogical, but it will meet my need.
Come on, let’s go: I have a bank of registered locations. These locations can make borders with several other locations. For each location is informed the distance in KM.
Based on the registered locations, the system has an option in which the user informs two points (origin and destination) and at the end the system informs the route for the vehicle to reach its given destination considering the shortest way.
I already have some cities, for example, Cidadea, Cidadeb, Cidadec, Cidaded, cidadee.
For example,
de CidadeA pra cidadeB são 5 km.
de CidadeB para cidadeC são 7 km.
de CidadeC para cidadeE são 22 km.
de CidadeC para cidadeD são 8 km.
e assim como posso ter outras cidades.
And I chose (two comboboxes) to go from the cityA to cityeB, so he has to bring me all the routes, that is, all the tickets to get to the city D in the most "fast" way, by the distance, then he has to bring the points, so
CidadeA - > CidadeB
CidadeB - > Cidade C...
e assim sucessivamente.
The user informs the source and destination, the system must calculate displaying point by point where it must pass.
I tried to cross joins and analyze, I tried to give go inside until I find, but it’s something that seems infinite, even thinking too much becomes difficult to assemble. Does anyone know a way, famous algorithms that do this? I’m checking out the A* algorithms, etc, but they still haven’t helped me.
Friends, here is the structure of the tables: Table Location and table Distances.
use master
go
CREATE DATABASE Rota
go
USE Rota
GO
CREATE TABLE [dbo].[Localidade](
[cod_cidade] [int] IDENTITY(1,1) NOT NULL,
[nome] [varchar](50) NULL,
CONSTRAINT [PK_Localidade] PRIMARY KEY CLUSTERED
(
[cod_cidade] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE TABLE [dbo].[DistanciaCidades](
[cod_cidade1] [int] NOT NULL,
[cod_cidade2] [int] NOT NULL,
[distancia] [int] NULL,
CONSTRAINT [PK_DistanciaCidades] PRIMARY KEY CLUSTERED
(
[cod_cidade1] ASC,
[cod_cidade2] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
If you read English, I strongly recommend the wikipedia article on the Travelling salesman problem. The Portuguese version doesn’t look so reliable.
– bfavaretto
Your question seems very logical yes, I just didn’t understand your "kms", are you by chance using a structure in the database of n:m? I know it seems irrelevant to ask this, but the structure of the bank in my view seems to be analyzed as well
– Guilherme Nascimento