ComputersProgramming

The dextra algorithm and its implementation

In mathematical science and computer science there is a separate direction, called the theory of graphs. Within its framework, various tasks are set and solved, for example, about finding the shortest path between the vertices. One of the most common methods for solving this problem among mathematicians has long been the Dijkstra algorithm.

What is a mathematical graph

It is believed that the concept of the graph was introduced in the eighteenth century by Leonard Euler. It was he who voiced the formulation and solution of one of the classical problems of this theory - about the seven bridges of Koenigsberg. In order to explain the object of this theory, most often use such an analogy as the movement between different cities. Then the graph on the plane will represent the whole scheme of the routes, where the vertices are specific points (for example, cities), and the edges are the paths from one vertex to another (analogous to the road between cities). Dijkstra's algorithm, in addition to other methods, can give a solution to this question.

Finding the shortest path

One of the standard problems of graph theory is one in which it is necessary to determine the cost-optimal path between two points. It can be reduced on the plane to the solution of the graph, in which the vertices - the cities - are connected by ribs, which represent possible roads. And each road has its own length, therefore, to travel through it will have to spend certain funds. This sum is equivalent to the weight of an edge on the graph. Then the problem in practice can be formulated as follows: how to pave the way from one city to another, to spend on the road a minimum of funds.

Solutions

To solve this problem, some algorithms were invented, which became widely known in the scientific world. For example, the Floyd-Warshell algorithm, the Ford-Bellman algorithm. The Dijkstra algorithm is also a classic way of finding the solution. It can also be used for weighted (known weight of each edge) graph, and for sparse. To find the final path, you need to do a few steps.

Dijkstra's Algorithm

The meaning of this method is that all vertices are bypassed, beginning with the given one, each being given a label with a certain value. Then the result will include those vertices whose labels are minimal. At the first step, the original vertex is assigned a label with a value of 0. Then all the following vertices are considered, that is, those that can be accessed from the source vertex. They are assigned labels whose value is defined as the sum of the source and the weight of the path. From the vertices of the next step, one is chosen that has the smallest value of the label, and all the vertices to which it can be traversed without using intermediate vertices are studied. A new value of the label is defined, equal to the label of the source vertex plus the weight of the path. If the resulting value is less than the vertex label, then the label changes. Otherwise, the original value remains. In this case, in a separate array, the dimension of which is equal to the number of vertices of the graph, the result of optimization is preserved, along which the path is determined. To implement such a method as the Dijkstra algorithm, Pascal offers very convenient tools. The algorithm has the advantage that it can easily be used as the basis of a program that has a small size. Examples of such software products are easy to find on the Internet.

Various means can be used to solve the problem of finding the optimal path. For a solution like Dijkstra's algorithm, Delphi will create a visual convenient form for inputting the original data and outputting the final result.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.unansea.com. Theme powered by WordPress.