I'm doing a logic system that addresses the route / routing issue. Where should I choose the best route to travel.
Initially I'm just doing some testing and testing advanced algorithms, what I'm doing seems like something illogical, but it will suit my need.
Come on: I have a bank of registered sites. These locations can border with several other locations. For each locality the distance is reported in KM.
Based on the registered locations, the system has an option where the user informs two points (origin and destination) and at the end the system informs the route so that the vehicle arrives at its destination considering the shortest path. / p>
I already have some cities, for example, CityA, CityB, CityC, CityD, cityE.
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 city to cityB, so he should bring me all the routes, that is, all the passes to get to city D in the fastest way, by the distance, there he should bring the points, so
CidadeA - > CidadeB
CidadeB - > Cidade C...
e assim sucessivamente.
The user informs the source and destination, the system must calculate showing point by point where it should pass.
I tried to do cross joins and analyze, I tried to give inside for until finding, but it is something that seems infinite, even thinking a lot is difficult to assemble. Does anyone know a way, famous algorithms that do this? I'm checking the A * algorithm, etc., but it still has not helped.
Friends, here is the structure of the tables: Location table and the DistanceLocations table.
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