algorithms and procedures of determining the optimal ...

4 downloads 24378 Views 423KB Size Report
Keywords: Graph model, object-oriented programming, optimal route, nearest neighbor algorithm. 1. ... ly modern personal computer is incapable of analysis that number of ... vehicle routing problem with time windows (Polacek et al. 2008).
TRANSBALTICA 2013

ISSN 2029-2376 print / ISSN 2029-2384 online ISBN 978-609-457-470-2 print / ISBN 978-609-457-469-6 online doi: 10.3846/transbaltica2013.045 http://transbaltica.vgtu.lt

The 8th International Conference May 9–10, 2013, Vilnius, Lithuania Selected papers

Transport Engineering Faculty of VGTU, J. Basanavičiaus g. 28, LT-03224, Vilnius, Lithuania

ALGORITHMS AND PROCEDURES OF DETERMINING THE OPTIMAL ROUTE IN THE GRAPH Algirdas Sokas Vilnius Gediminas Technical University, Department of Engineering Graphics, Sauletekio al. 11, LT-10223 Vilnius, Lithuania E-mail: [email protected] Abstract. This article analyzes algorithms and procedures of determining the optimal route in the graph. The model of the problem is presented as non-directional graph, where nodes are towns and edges are roads among towns. All towns are connected by roads. These roads are shown as graph edges. Nearest neighbor algorithm is selected for route optimization. Algorithms and procedures to exercise solution are presented. The program is written in Visual Basic for Application language working in the graphical system AutoCAD environment. Graphical system for selected towns on Lithuanian map finds optimal route. A solution is presented in graphical form with total length of the route. Obtained results are discussed and conclusions are made. Keywords: Graph model, object-oriented programming, optimal route, nearest neighbor algorithm.

life applications (Goel and Gruhn 2008). Second, example use variable neighborhood search to solve the multi-depot vehicle routing problem with time windows (Polacek et al. 2008). Third, problem is solved using a two-phase solution framework based upon a hybridized search, within a new reactive variable neighborhood search metaheuristic algorithm (Paraskevopoulos et al. 2008). Fourth example, a mixed load algorithm for the school bus routing problem that seeks to find an optimal set of routes for a fleet of vehicles (buses). Each bus must pick up students from their homes and transfer them to their schools while satisfying various constraints, such as vehicle capacity, student’s maximum allowable riding time in a bus, and time windows of the schools (Park et al. 2012). The nearest neighbor algorithm is used for solve other problems. Example present a novel algorithm for efficiently splitting deformable solids along arbitrary piecewise linear crack surfaces in cutting and fracture simulations. The algorithm combines a mesh less discretion of the deformation field with explicit surface tracking using a triangle mesh (Steinemann 2009). Example embedded systems become a prevailing element in daily life. They dominate mobile communication and perform control tasks in most automation domains such as in buildings and automotive. The complexity and diversity of implementations steadily increase with new features added to the already complex control tasks like anti-lock braking system or electronic stability control (Ryssel et al. 2012). Typically, the single-source shortest-path problem was discovered by Dijkstra (1959), while the all-pair shortest-path algorithm is due to Floyd (1962), who obtained the result based on a theorem by Warshall (1962). This article analyzes algorithms and procedures of determining the optimal route among given towns.

1. Introduction Optimal route problem has been studied by many authors. It is a well-known problem, and can be used to solve many real-world problems. The goal of the task is to determine traveler’s shortest route that stops at given towns, but each town can be visited only one time. Such task in the graph theory (Diestel 2000; Cormen et al. 2001) is called traveling salesman problem. Problem is that a full graph with n nodes has (n – 1)! cycles. In our case the graph with 80 nodes has 7·10118 cycles. Obviously modern personal computer is incapable of analysis that number of cycles. So we refuse to find most optimal solution and try to search only for an optimal solution. Literature analysis shows that traveling salesman problem has been studied by many authors in recent years. The optimization of routing and packing decisions plays a crucial role in logistics, since the final cost of goods is strongly affected by an efficient distribution. For example paper investigated theoretical properties of the double traveling salesman problem with multiple stacks (Casazza et al. 2012). Other work proposed the issue of asymmetry in the distance matrix from road transportation networks. The main objective of this research is to measure the effect that the asymmetry of the road network has in solving the traveling salesman problem, both the symmetric and the asymmetric variant (Rodrıguez and Ruiz 2012). One of the simple strategies is the nearest neighbor algorithm, which always chooses the unvisited node nearest to the current position (Rosenkrantz et al. 1977). They proposed the weighted nearest neighbor algorithm and showed that it achieves the competitive ratio of 16 for planar graphs (Asahiro et al. 2010). In literature nearest neighbor algorithm is praised for route optimization. Example, study a rich vehicle routing problem incorporating various complexities found in real-

202

 Vilnius Gediminas Technical University (VGTU) http://leidykla.vgtu.lt

8th International Scientific Conference TRANSBALTICA 2013, Vilnius, 9–10 May, 2013

2. Optimal route modelling with graph The model of the problem is presented as nondirectional graph G = (N, E), where nodes are towns and crossings outside towns N = (1, ..., n), and edges are roads among towns and crossings E = (1, ..., m). Each node has some information attached to it: name and size of the town, maintenance organizations, and mark of the crossing. All towns are connected by roads. These roads are shown as graph edges. Each edge also has information sketched in: type of road (main, country, and district), length of road, allowable speed on the road and other useful information. Floyd–Warshall algorithm is selected for finding shortest way from one graph node to another selected node. The algorithm uses intermediate node idea. It approaches path among all intermediate nodes and finds shortest route. Result of the algorithm is two symmetric and quadratic matrices n measurements: distance matrix [DM], which keeps graph’s shortest distances among nodes, and path matrix [PM], which keeps the found shortest way intermediate node numbers. Matrix [DM] is used for finding route distance. Matrix [PM] is used for finding shortest path from start node until end node. Distance matrix and intermediate nodes matrix forming algorithms and procedures are presented in the article (Sokas 2011).

Fig. 2. Lithuania map

Fig. 3. Database table Points

2.1. Graph in the drawing Graphical system AutoCAD is a program used as operating environment, and Visual Basic for Application (VBA) is a language used for programming. Drawing is a very good environment for programming because each point has coordinates and each line segment has start and end coordinates. The end coordinate of each polygon line is the beginning coordinate of another line. This program determines the graph of the Lithuania towns and roads drawing (Fig. 1).

Fig. 4. Database table Roads

The database table Roads haves fields from, to, length, type and speed limit of road. Using these database tables it programmatically forms cities and crossings nodes which coordinates are known. Cities and intersections have different ID codes. Based on the cities’ codes the edges are drawn symbolizing the routes with a length corresponding to the real length. This creates a graph in the drawing of the routes and cities. Most importantly, this graph-making system is easily transformed to include new cities and specifying new routes in the database. Database presents the main Lithuanian cities and roads. It can be expanded by adding new entries and the system easily creates another graph with a different number of nodes and edges. It only needs the changed settings to be specified.

Fig. 1. Graph in the AutoCAD drawing

The program controls database with two tables: Points (Fig. 3) and Roads (Fig. 4). The database table Points have fields town names and its coordinates x, y. This table was created in such a way as shown in (Fig. 2) by measuring horizontal and vertical distances of cities on the map from the left and bottom edges in millimeters respectively.

2.2. Optimization of optimal route Start and return towns are selected. These towns can be different. Towns to be visited on the way are indicat203

A. Sokas. Algorithms and procedures of determining the optimal route in the graph

ed. Several algorithms that find the optimal route are found in literature: traveling salesman problem, nearest neighbor algorithm. Nearest neighbor algorithm is selected for route optimization. From start town search nearest town from selected to visit. Then select nearest town, then from him again search nearest other town and in such way from all selected to visit towns. There are start, end and transitional towns, all together pn number of towns. Indices of selected towns are writen to travel points vector TP. At first, from matrix [DM] shortest distances are selected for these towns according to towns index ID (Fig. 3) and travel distances is written to the matrix [TLM] (Fig. 5): For i = 1 To pn For j = 1 To pn TLM(i, j) = DM(TP(i), TP(j)) Next j Next i There TLM – travel length matrix, DM – distance matrix, TP – travel points vector, pn – points number, i, j – indexes.

Fig. 6. Algorithm of method NearestNeighbor Fig. 5. Algorithm result [TLM] matrix

Next, travel route points vector TRP is found using nearest neighbor algorithm (Fig. 6) which is presented in the procedure: TRP(1) = TP(1) curp = 1 For i = 2 To pn - 1 min= 700 nexp = 0 For j = 2 To pn - 1 If TLM(curp, j) < min And TVP(j) = False Then min= TLM(curp, j) nexp = j End If Next j TVP(nexp) = True TRP(i) = TP(nexp) curp = nexp Next i TRP(pn) = TP(pn)

Fig. 7. Algorithm result TVP and TRP vectors

Then a route between specific towns is tested for the shortest route with Floyd–Warshall algorithm: For j = 1 To pn - 1 Route.ExtractRoute TRP(j), TRP(j + 1) For k = 0 To rs - 1 t1(0) = GM(RP(k), 3) t1(1) = GM(RP(k), 4): t1(2) = 0 t2(0) = GM(RP(k + 1), 3) t2(1) = GM(RP(k + 1), 4): t2(2) = 0 Set linija = ThisDrawing.ModelSpace.AddLine(t1, t2) linija.Layer = “kelias” linija.Update k=k+1 Next k Next j

There TRP – travel route points vector, TP – travel points vector, TLM – travel length matrix, TVP – travel visited points vector, min – minimal length from town to town, nexp – next point index, curp – current point index, pn – points number, i, j – indexes. Result of nearest neighbor algorithm is two vectors: travel visited points vector TVP and travel route points vector TRP (Fig. 7).

There TRP – travel route points vector, RP – route points vector, GM – graph matrix with towns ID, names and x, y coordinates in the drawing, pn – points number, k, j – indexes. 204

8th International Scientific Conference TRANSBALTICA 2013, Vilnius, 9–10 May, 2013

(Fig. 10). A solution is presented in graphical form (Fig. 11) and a list of route’s towns is written with town ID and length of the route (Fig. 10).

3. Examples, optimal route in the Lithuania map Graphical system for selected start Vilnius and end Vilnius towns with visited towns Sirvintos, Anyksciai, Utena, Pabrade on Lithuanian map finds optimal route (Fig. 8). A solution is presented in graphical form (Fig. 9) and a list of route’s towns is written with town ID and length of the route (Fig. 8). The program consists of main program’s dialog window (Fig. 8) and two class modules: Graph and Route, which have some properties and methods. The program controls database with two tables: Points and Roads.

Fig. 10. Optimal route from Vilnius to Kaunas with visited towns Trakai, Alytus, Ukmerge

Fig. 8. Optimal route from Vilnius to Vilnius with visited towns Sirvintos, Anyksciai, Utena, Pabrade

Fig. 11. Optimal route Vilnius, Trakai, Alytus, Ukmerge, Kaunas

The system is open and is possible to expand, append database with new towns, crossings and roads.

4. Conclusions 1. Literature analysis shows that nearest neighbor algorithm are used to solve many real-world problems such as vehicle routing in transportation, in cutting and fracture simulations, perform control tasks in most automation domains. 2. Presented a graph model allows to analyze the resulting matrix and vector, allows you to see the program's analysis of a graph and print the entire string.

Fig. 9. Optimal route Vilnius, Sirvintos, Anyksciai, Utena, Pabrade, Vilnius

Graphical system for selected start Vilnius and end Kaunas towns with visited towns Trakai, Alytus, Ukmerge on Lithuanian map finds optimal route 205

A. Sokas. Algorithms and procedures of determining the optimal route in the graph

3. Object-oriented programming language, classes with specific properties and methods allows writing a program with individual modules, which simplifies and clarifies programmer’s work. 4. Method of Nearest Neighbor presented as the algorithm. This algorithm is implemented software code. 5. The route between specific towns is tested for shortest route with Floyd–Warshall algorithm which realized method Extract Route.

6. A programming language and graphical objects controlled by the language are required for design of such systems. For example, Visual Basic for Application programming language works with the AutoCAD objects. 7. The presented program is practical and clear for using, easy to select start, end and intermediate towns. Accessible result is clear and visual.

References Asahiro, Y.; Miyano, E.; Miyazaki, S.; Yoshimuta, T. 2010. Weighted nearest neighbor algorithms for the graph exploration problem on cycles. Information Processing Letters, 110, 93–98. Casazza, M.; Ceselli, A.; Nunkesser, M. 2012. Efficient algorithms for the double traveling salesman problem with multiple stacks. Computers & Operations Research 39: 1044–1053. Cormen, T. H.; Leiserson, C. E.; Rivest, R. L.; Stein, C. 2001. Introduction to Algorithms, The MIT Press, New York. Diestel, R. 2000. Graph theory. Electronic edition. Springer – Verlag New York. Dijkstra, E. 1959. A note two problems in connection with graphs, Numerical Mathematics 1: 269–271. Floyd, R. W. 1962. Algorithm 97: shortest path, Communications of the Association for Computing Machinery 5(6): 345. Goel, A.; Gruhn, V. 2008. A General Vehicle Routing Problem. European Journal of Operational Research 191: 650–660. Paraskevopoulos, D. C.; Repoussis, P. P.; Tarantilis, C. D.; Ioannou, G.; Prastacos, G. P. 2008. A reactive variable neighborhood tabu search for the heterogeneous fleet vehicle routing problem with time windows. Journal Heuristics 14: 425–455. Park, J.; Tae, H.; Kim, B.-I. 2012. A post-improvement procedure for the mixed load school bus routing problem. European Journal of Operational Research 217: 204–213. Polacek, M.; Doerner, K. F.; Hartl, R. F.; Maniezzo, V. 2008. A variable neighborhood search for the capacitated arc routing problem with intermediate facilities. Journal Heuristics 14: 405–423. Rodrıguez, A.; Ruiz, R. 2012. The effect of the asymmetry of road transportation networks on the traveling salesman problem. Computers & Operations Research 39: 1566–1576. Rosenkrantz, D. J.; Stearns, R. E.; Lewis, P. M. 1977. An analysis of several heuristics for the traveling salesman problem, SIAM J. Computing 6(3): 563–581. Ryssel, U.; Ploennigs, J.; Kabitzsch, K. 2012. Automatic library migration for the generation of hardware-in-the-loop models. Science of Computer Programming 77: 83–95. Sokas, A. 2011. Algorithms and procedures of determining the shortest route in the graph, in Proceedings of the 7th international scientific conference Transbaltica 2011. Vilnius: Technika, p. 211–215. Steinemann, D.; Otaduy, M. A.; Gross, M. 2009. Splitting mesh less deforming objects with explicit surface tracking. Graphical Models 71: 209–220. Warshall, S. 1962. A theorem on boolean matrices. Journal of the Association for Computing Machinery 9(1): 11–12.

206

Suggest Documents