Finding the shortest path in a graph and its visualization using C# and WPF

Received Apr 9, 2019 Revised Nov 20, 2019 Accepted Dec 11, 2019 The shortest path problem is a classic problem in mathematics and computer science with applications in Economics (sequential decision making, analysis of social networks, etc.). The presented work is an example of realizing and applying of Dijkstra's algorithm to find the shortest path between two vertices in a connected, undirected graph, which is often a solved problem at a time annual International Olympiad in Informatics. For this purpose, are used the technologies, .NET 4.0, Visual Studio 2010, and WPF for the graphical user interface. The implemented program allows drawing an undirected graph, visualizing the shortest path between two vertices and finding its value. This software is a valuable tool for the study of Dijkstra's algorithm and is a great pedagogic instrument. All figures of path visualization included in this paper are actual screenshots of our visualization program.


INTRODUCTION
The shortest path (SP) in the graph between two vertices is called a path that starts from one vertex and ends in the other, with the sum of the weights of the edges involved in it being minimal [1][2][3]. For some problems, the length of the path may be defined not as a sum, but as some other function of the weights of the edges involved in path (and even vertices). Since there may be no restriction the path to be simple, we must be careful when the graph contains a cycle. For example, if we are finding a minimal path, and in it there is a negative cycle (cycle with negative length), we will be able to "rotate" on this cycle any number of times, in which the length of the path (equal to the sum of the edges in it) will decrease arbitrarily much to minus Infinity. Similarly, if we find a maximum path and there is a positive cycle, for each path that contains it, we will be able to "rotate" on this cycle whereby we get an arbitrary great length [1] The most efficient method of finding a shortest path from a particular vertex to everyone else is Dijkstra's algorithm. Without applying optimization, this algorithm has a complexity of the order of O(N 2 ), with N is the number of vertices in a given graph [1][2][3]. Although it is the most efficient algorithm for finding the shortest path, this algorithm is not applicable to every graph. The graphs in which used are not to have negative cycles. In this work, we finding the shortest paths in undirected graph without cycles.
In the present work is presented .NET implementation of Dijkstra's algorithm to find the shortest path between two vertices in a connected undirected graph. For this purpose, has been used the technology . One vertex of a graph in this particular development has several important propertiesa label (number) that distinguishes it from all other vertices, a set of edges that connects it to other vertices, a property that will show whether the vertex has been visited or not, its coordinates, which will be used in its graphical representation, and the total value (length) of the found path.

MATERIAL AND METHOD 2.1. Dijkstra's algorithm
In this algorithm are assumed, that the lengths cij of all edges to be nonnegative. The algorithm can be considered as the process of sequentially marking the vertices of a graph with corresponding numbers. Generally, the marking number d(x) at the vertex x is temporary and gives the upper limit of the path length from s to x. When performing the algorithm, the values of the markup numbers are reduced, with at each step exactly one of the temporary marker numbers being constant (coloring) [1]. In this case, the permanent (colored) marker number d(x) is no longer an upper limit, but the exact length of the SP from s to x. For colored we also consider the corresponding vertex x. When in addition to the length of the SP the path itself is searching is also colored and one of the edges of the graph, thus it is included in the search path.

.NET 4.0
The Microsoft .NET Framework is a platform created by Microsoft that provides a programming model, a library of classes, the Framework Class Library (FCL), and an environment for the implementation of written specifically for it program code, Common Language Runtime (CRL). It is a key element of Microsoft's development strategy, which aims to make most new Windows applications based on a .NET Framework 3.5. .NET applications are written in high level languages (C#, VB.NET, C++ / CLI, etc.) and compiled into a platform-independent intermediate language called Common Intermediate Language (CIL). The C# language is used in this work. During execution, the CIL code is automatically compiled by CLR for the specific hardware platform and operating system the user is use. The .NET Framework architecture is often considered at levels as shown in Figure 1.

Visual Studio 2010
VS.NET is one of the world's leading integrated application development environments -Integrated Development Environment (IDE). With its help, we can do each of the typical tasks related to building an application-writing code, creating user interface, compiling, running and testing, debugging, error tracking, creating installation packages, viewing documentation and others [4][5][6][7][8]. The Visual Studio .NET 2010 package supports Microsoft C# .NET, Microsoft Visual Basic .NET, Microsoft C++ .NET (managed/ unmanaged) and Microsoft Visual J# programming languages as standard. In the present work, program for the finding and visualization of SP is written in the C# programming language. The VS.NET code editor supports all approved advanced source code editors functions-syntax coloring for easier visualization of the code and error reduction, automatic completion of the sentence, automatic extraction of auxiliary data during writing and many more. Also, IntelliSense functionality for selecting classes, methods, and variables is supported. It provides great ease for the incoming .NET programmers, as it allows them to look at

Windows presentation foundation (WPF)
Windows Presentation Foundation is an entirely new graphical system for building modern desktop applications that provides both developers and designers with a unified platform for creating rich media applications based on XAML language. WPF is designed for the .NET platform, influenced by modern HTML and Flash technologies, and hardware accelerated. WPF is a new generation platform designed to facilitate the creation of a graphical user interface for desktop applications. In this development, the WPF was used to implement the graphical user interface of the program located and visualizing the SP.

RESULTS
The implemented software program allows drawing an undirected graph using the mouse. Drawing the vertex of a graph is done with a click of the mouse, and the setting of the edge and the corresponding weight is done by sequentially choosing the two vertices between which we set the edge by clicking with mouse on them. The general view of the SP finding program is shown in Figure 3. To switch from a plotting mode to a SP search mode, the program has a special button "SP finding". In this mode, the program allows us to select the starting and ending edges, between witches, we are searching SP. The pro-gram finds the SP between the two vertices of the Dijkstra's algorithm by visualizing it and coloring the vertices and edges involved in it in green color and find value of the path. The result of using the program to find the SP in a given graph is shown in Figure 4 and Figure 5. For example, for Figure 4 the graph has 15 vertices and 16 edges. The SP between vertex 1 and vertex 15 has a length of 14. The developed software program for calculation of SP by Dijkstra's algorithm, significantly facilitates the application of this algorithm on any connected, undirected graph and allows for easier interpretation of the result. This software program may be used as an educational software can give a big clarity, regarding the algorithm and programming [7][8][9][10][11][12][13][14][15][16][17][18].

CONCLUSION
Very often a wealth different informatics Olympiads are held national, regional or international levels, in which are decided problems that requiring programming knowledge and various algorithm techniques. The creating high quality problem solution can be a difficult and time-consuming process [19][20][21][22][23][24][25]. In this paper we explored known technique for find the shortest path, with the help of the powerful programming language C# and modern technologies such as WPF, which can be used to find new ideas for problems and refine these ideas into problems suitable for the International Olympiad in Informatics (IOI) annually organized. In additional this article can to help of students in secondary and higher schools to acquire additional skills in programming and to learn more for the algorithms and their application.