Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Using Path-Finding Algorithms of Graph Theory

for Route-Searching in Geographical Information


Systems
B. Sobota*, Cs. Szabó* and J. Perhá*
* Dept. of Computers and Informatics, FEEI, Tech. University of Koice, Slovakia
Branislav.Sobota@tuke.sk, Csaba.Szabo@tuke.sk, Jan.Perhac@tuke.sk

Abstract—This paper deals with graph theory application in software and geographical data designed for effective
large-scale geographical data searching and visualization. gathering, retaining, editing, processing, analysis and
We present a comparison of two path-finding algorithms of visualization of all kinds of geographical information.
graph theory, i.e. blind-search and A* algorithm, that Generally, it is a spatial specialized IS.
results into the selection of the second one for
implementation within a geographical information system. Being an IS, GIS has to provide information in
The main goal is to process the terrain map representation graphical (e.g. location of the hotel on the map) and
in the form of a graph during route-searching between start nongraphical (e.g. fees, room equipment) way that
and target positions, and during the visualization and supports fast searching and actualization of data.
animation of the results of this search. We show the Nowadays, graphical information are stored as vector
implementation results on random city map and on real graphics (two-dimensional), but the trends are clearly
three-dimensional model of our university campus. Finally,
forecasting the 2nd generation GIS as an IS working with
we discuss further directions of current work.
3D objects and surfaces.
It is useful to extend the implementation of the above-
I. INTRODUCTION mentioned searching of objects by route-searching
Graphs can be imagined as a set of points (vertices) between two selected objects. As the map is the core of
interconnected by lines (edges). The edges can have any GIS, a possible way of use of path-finding on graphs
specified direction (orientation). Paths are sequences of within such a system is the mapping of these maps onto
vertices and edges between them. Path-finding between searchable graphs that will be shown in next sections of
two graph points is used in many areas, like GPS this paper. Section II presents the theoretical background
navigation, CAD systems (auto-routing in design of needed in algorithm descriptions in the other following
circuit boards), and applications of artificial intelligence, sections. In Section III, we define terms such as map and
computer games, virtual reality, military forces or route, and the blind-search and A* algorithms are also
robotics. The main aim is to pass through environment in introduced. Next two sections deal with the test results:
secure form and to avoid of obstacles. Examples of this Sec. IV presents test results on static two-dimensional
need are autonomous robots on distant planets without maps, while Sec. V presents results from tests where
the possibility to be controlled in real time because of three-dimensional (city) maps were used. Sec. V
latencies in signal sending, or automatic vehicles control. demonstrates the tested 3D city information system,
Another example of path-finding are strategic computer especially its user interface, as well. Section VI is
games, mostly with computer opponent. Path-finding is denoted to conclusions and future work.
also widely used in finding best routers interconnection II. THEORETICAL BACKGROUND
for data transmission in many kinds of computer
networks. L. Euler, mathematician from the 18th Century, is
considered as the founder of graph theory. Graph theory
To be successful in path-finding, the need of reliable as a science discipline started with first graph theory
algorithm and reliable implementation of that algorithm is
monographs written by mathematicians D. König (1936)
enormous. Another important thing is the need of some
and C. Berge (1958). The next part of this section relies
user-friendly visualization of results of path-finding,
on definitions in [2].
which is realized by application of computer graphics
Let V be a final non-empty set, i.e. the set of vertices,
techniques. and let E be the set of edges defined as:
A geographical information system [1] (GIS) is an E = {e | e = {v1,v 2 };v1,2  V} . (1)
information system (IS) designed to work with data that V  V 
represent geographical or spatial coordinates. These data Obviously, E    , where   is a set of all two-
can be further analyzed and statistically evaluated. 2 2
Another way to specify a GIS is that it is a specialized element subsets of set V:
IS defined as a collection of computer hardware and

1-4244-2407-8/08/$20.00 ©2008 IEEE


V  vertices and elements of E are called oriented graph
 = {A | A  V  A = 2} . (2) edges.
2
Considering these two sets, the couple G = (V, E) III. MAPS, ROUTES AND ALGORITHMS
defines graph G with the corresponding vertices and The core element of any GIS is the map. All objects
edges. have spatial coordinates defining their placement on this
Path is a sequence of vertices where an edge exists for map. On other hand, maps are also basic elements if it
any two consecutive vertices of this sequence. Degree of comes to path-finding or animations.
a vertex is the count of edges outgoing from this vertex, The basic working structure of algorithms is the map,
e.g. the degree of any internal vertex in a path is not less which is represented as a set M = N  N (two-
than two, the end vertices have a degree at least one. dimensional quadratic grid). Square is a member of set M.
The graph G is a coherent graph if all vertices are Every square represents position in map and has its own
reachable, i.e. for all vertices exists at least one path to coordinates [x,y] according to beginning Pm. Squares
any other vertex. [x1,y1] and [x2,y2] are neighbors, if (|x1–x2|=1 and |y1–
Let G = (V, E) be a coherent graph. Distance d(u, v) y2|<=1) or (|x1–x2|<=1 a |y1–y2|=1) (they are neighbors
between vertices u and v of graph G is the length of geometrically). The beginning in map Pm is a defined
shortest route linking vertices u, v, i.e. the shortest path. square. This representation is called map representation.
Vertices distance d(u, v) of graph G has the following Next, a function is defined:
properties:
w m : M  R +  {+} . (4)
d(u,v)  0;d(u,v) = 0  u = v,
This function assigns regress (e.g. weight, terrain cost)
d(u,v) = d(v,u), (3) to every square. This function determines the difficulty of
z  V : d(u,v)  d(u,z) + d(z,v). input for square (or square traversing). If the regress is
+ then the square is impassable and contains an
These properties are metrics axioms; so ordered pair obstacle. This function is simple only if it contains a two-
(V, d) is a metrical space. Nevertheless V is a vertical set element set 1 and +. In the map, the start square of the
of graph G = (V, E), d is a metric – vertices distance in route is marked A, the target square is marked B.
graph G. The advantage of these properties is the fact that Route in map is a sequence of map squares (m1, m2…
they consist even after isomorphism is done. One result mn) in which every next square is neighbor to previous
of this is the fact, that also notions defined by metric have square on the route. There are no squares on the route that
the same advantage. are included more than once. The route length is the sum
Let G = (V, E) be a coherent graph, then: of regresses of all route squares:
1. For every vertex u  V the number e(u,G) = max d =  w m (mi ) . (5)
d(u,v), v  V is called eccentricity of vertex u. i
2. Number P(G) = max e(v,G), v  V is average of The algorithm task is to find the shortest route in map
graph G. from the start to the target, i.e. from A to B.
3. Number r(G) = min e(v,G), v  V is radius of The map representation is a special graph example.
graph G. Vertices are corresponding to squares. The bijection
4. The centre of graph G is every vertex u of graph transforming the graph to squares will be called map.
G with eccentricity equal to radius e(u,G) = Transition between neighbor squares corresponds to
r(G). graph edge and initial vertex in graph Pg corresponds to
Graph diameter can also be defined as P(G) = max initial vertex in map Pm. Next we need to define function
d(u,v), u, v  V. w, which will perform weight calculation on the graph.
Graph G = (V, E) is an Euler graph, if this graph is Function wg is defined as representation from set of edges
coherent and every one of its vertices has even degree. to set of non-negative real numbers with +:
Graph can be covered by a single enclosed stroke only if w g : E  R +  {+}. (6)
it is an Euler graph. Graph G = (V, E) can be covered by For edge e=(p,q), function wg is defined as:
a single enclosed stroke only if it is a coherent graph with w g (e) = w m (map(q)) . (7)
two vertices of degree 2 (opened stroke starts in one of +
Heuristics is defined as function h :V  R  {+},
these vertices and ends in another).
which assigns to vertex v the expected distance to target.
Let G = (V, E) be a graph, |V| = n, n  3. Let the degree
It estimates the length of shortest route from vertex v to
of every vertex of graph G be at least n/2. Then G is a
the target.
Hamilton graph. If graph G = (V, E) is a Hamilton graph,
There are several algorithms for route-searching in
this graph has to be terminal, non-empty, coherent and
static maps:
may not consist of bridges. Nevertheless fulfillment of
• blind-search
these conditions does not guarantee existence of
• divide & conquer
Hamilton graph.
• breadth–first search
Oriented graph G is defined as ordered pair (V, E),
• bidirectional breadth–first search
where V is the set of vertices and E is set of ordered
• depth-first search
element pairs of set V. Elements of V are called graph
• iterative depth-first search
• Dijkstra’s algorithm checked if the direction with obstacle is not released. If
• best-first search yes, then the square in this direction is set as new starting
• Dijkstra’s algorithm with heuristics (A*) square and the evaluation process starts again. If not, then
the algorithm continues with new direction and tests first
In our tests, the blind-search algorithm and Dijkstra’s route. By this movement the algorithm can collide with
algorithm with heuristics (A*) were used. new obstacles. It remembers again only the direction with
obstacle and sets new course. This new course is tested
A. Blind-Search Algorithm
and if it is released, then the original direction is tested. If
The blind-search algorithm (results on Fig. 1-3) is the algorithm collides with obstacle it stops to evaluate
based on progress to the target, until it collides with squares and tests transitivity of only one square. This can
obstacle, then the direction of movement is changed and fasten the algorithm but can also become the algorithm
the algorithm tries to move along nearest edge and to get into endless loop (see Fig. 2).
around it. This algorithm works with aim on one square
and usually does not take to consider the whole B. A* Algorithm
evaluating function w, but only two states + or 1. So it The A* algorithm (test results on Fig. 4-6) is a natural
works only with simple evaluating function and does not generalization of Dijkstra’s algorithm and the scanning is
count with regress. This algorithm does not guarantee the based only on heuristics. In A* the element classification
finding of shortest route and can be used on special maps process is done by a binary heap. All square near the
because of its speed, low memory requirements and evaluated square are also evaluated in eight directions.
simple implementation. Function g(x) is evaluated from the starting square. If the
The evaluation process is as follows: evaluated square is in the diagonal, then the number 14 is
[ ]
abs (ex  t x ) + (ey  t y ) , (8) assigned to this square, and if not, then number 10 is
assigned to this square. As heuristics, the Manhattan
where ex,y are the [x,y] coordinates of the actually
method is used:
evaluated square and tx,y are coordinates of target square
on the map. [ ]
10 * abs(ex  t x ) + abs(ey  t y ) , (9)
The square with the lowest evaluation is chosen and i.e. the distance between dx+dy is computed. Sequence
set as new starting square for next iteration. With using function is defined as f(x) = g(x)+h(x). The algorithm
this mechanism this algorithm continues to target with description follows.
fastest possible approach. Because of the use of a simple Assume that graph G = (V, E) has already evaluated
evaluation, this algorithm is one of fastest algorithms for edges, i.e. the mapping and weight computation is already
path-finding. Problem occurs when evaluated square is done. We store two values for every already processed
impassable. If this satiation occurs the algorithm stops to vertex: d[v] will store the length of the shortest path to
evaluate squares and remembers the obstacle direction the vertex, p[v] will be the vertex before v on the path.
and then tries to avoid this obstacle. The avoid process is The algorithm also uses two sets: OPEN and CLOSED.
done by choosing the nearest available square, which is OPEN is the set of vertices to process, CLOSED includes
gained by turning the process into right. This square is the vertices already processed [3].
new starting square, which is not evaluated but only

Figure 4. Path found by A* algorithm on Map1


Figure 1. Path found by blind-search algorithm on Map1

Figure 2. Blind-search algorithm trouble on Map2 Figure 5. Path found by A* algorithm on Map2

Figure 3. Path found by blind-search algorithm on Map3 Figure 6. Path found by A* algorithm on Map3
At the beginning, the starting vertex is inserted into
OPEN. The iteration cycle starts with the choose of the
vertex n with best value of f(n). This vertex will be
inserted into set CLOSED and all from n reachable
vertices v are selected, and if they are not in set OPEN,
they will be inserted with p[v]=n and the corresponding
value of d[v]=d[n]+l(n,v), where l(n,v)=wg(v) is the cost
function for the selected edge from n. If v was already a
member of OPEN, we need to test if the new path is
shorter than the old by comparing d[v]<d[n]+l(n,v). If
the comparison fails, we need to update the values p[v]
and d[v]. The presented cycle continues until the target is Figure 7. Statistics on searched squares on maps by both algorithms
found or the set OPEN is empty. After the algorithm had
finished, we need to reconstruct the path using values of
V. TESTING WITH THREE-DIMENSIONAL CITY MAPS
p[v].
Fig. 4-6 show examples of usage of the A* algorithm Two-dimensional maps, as presented above, are a good
on 2D static maps to compare with the results of the testing tool, but in real systems three-dimensional ones
blind-search algorithm from the previous section. are nowadays more useful. Representing higher fidelity to
There are possible modifications to this algorithm that real world, virtual reality techniques help to build more
can decrease memory usage and fasten the A* algorithm. user-friendly and more precise information systems.
The most common techniques optimize the number of Dealing with geographical information, a three-
vertices within the sets OPEN and CLOSED by dimensional map (or more precisely, the visualization of
discarding the less useful ones. This technique limits the it) introduces a few new problems into the path-finding
count of the elements of each set separately to get best by extending the information character to be searched.
performance but do not miss some possible paths. The Therefore, we run tests on more complicated surfaces
common problem is the grid resolution selection: high and maps with building objects, hills etc. The result is
resolution rapidly slows down the algorithm execution; shown on Fig. 8 in the form of the found route form point
low resolution may cause loss on important information A to point B between the buildings of a randomly
as smaller buildings and/or gates. The maximum sizes of generated city.
sets OPEN and CLOSED were examined and We also performed tests on optimizing of set sizes for
experimentally defined in [3] as 1000 and 3000. OPEN and CLOSED. As we already mentioned, in [3]
were made some experiments under our supervision. The
IV. TEST RESULTS FOR STATIC TWO-DIMENSIONAL testing conditions were as follows: each test case was run
MAPS separately on the same hardware (no sequences etc.);
We run a couple of tests on two-dimensional static visualization (rendering) speed was set to minimum; each
maps to compare the blind-search and A* algorithms, test case was run ten times and results were averaged.
which implementations were based on [4,5]. Ten (10) The test results are shown on Tab. I and Tab. II; we got
maps were tested. Found routes differ in length (compare best performance by dual optimizing (i.e. using both
results on Fig. 3 and Fig. 6). The route always starts with limits), but the optimization of size of set OPEN had
red arrow. If the route is returning by the same route stronger effect on execution speed than the optimization
backward, then the arrow is changed to yellow and the of set CLOSED. The tested A* algorithm was
route continues with yellow arrow. If the route crosses implemented within the 3D city IS we do present in next
itself (blind-search algorithm), then it is in cycle and the section.
arrow will be marked by boxed blue color. Yellow square
is start square, blue square is target square.
The efficiency of blind-search algorithm is only 40%
because from 10 maps it found route only in four of them.
A* algorithm searched in all maps 14 895 squares
together. Blind-search needed to search 83 928 squares,
because it used to cycle itself (see Fig. 2) and the
condition of cycle detection was at 10000 cycles. The
blind-search algorithm searched 5,64 times more squares
than A* algorithm.
We present the test results of both algorithms on Fig.
7. It is obvious that blind-search was not so effective like
the A* algorithm when compared the count of squares
searched. The speeds are not comparable due to the low
Figure 8. A* algorithm test results on a random 9 km2 city map
efficiency of the blind-search algorithm.
TABLE I.
SPEED TEST RESULTS OF A* ALGORITHM OPTIMIZATION

Optimization Average execution


technique time [s]
none 489
CLOSED 458
OPEN 368
OPEN & CLOSED 346

TABLE II.
SET SIZES AND PATH LENGTH DURING A* ALGORITHM OPTIMIZATION Figure 10. Search window of 3D city information system
Optimization Path |OPEN| |CLOSED|
technique length
[m] only moves the camera to the selected target.
none 5210 6022 5210 Function show-path opens after a few minutes the
CLOSED 5210 6022 3000 resulting route from the actual position on the map to the
selected target as shown on Fig. 8. The speed is faster
OPEN 5210 1000 5263
with less resolution, but some narrow streets have been
OPEN & CLOSED 5210 1000 3000
missed. With the campus map are nearly real-time results
due to the small count of objects.
The virtual reality oriented part of the tested
A. The 3D City Information System Test Case geographical information system was the animation
function. The path-finding module was shared with the
Fig. 9 shows the main screen of the tested GIS. We can other already mentioned parts. The test case had to ensure
see few building objects on the base map, in the upper the quality of the obstacle detection. This part offers the
right corner are navigation buttons (3 – minimize, 4 – path visualization by circles and the animated walk-
close). Upper left corner has also two buttons: 1 – open through of the scene rendered from the map and
map, 2 – options. Options are like map resolution etc. The additional object information stored in the GIS database.
number 5 indicates the search button, which functionality
Fig. 11 shows the animation screen. Buttons 13-16 are
we tested.
classical navigation buttons for movement within the
Selecting this last option, a search dialog opens that is
animation.
shown on Fig. 10. As any classical search dialogs, it has a
field for the search query (reference number ref. no. 6), VI. CONCLUSION
results displaying area (ref. no. 7), search execution This paper presents a view on graph theory from point
button (ref. no. 8), animation button (ref. no. 9), path of view of virtual reality. We showed the application of
display button (ref. no. 10), object display button (ref. no. the modified Dijkstra’s A* algorithm of path-finding in
11), and close dialog button (ref. no. 12). graphs within a geographical information system.
The testing procedure is simple: open a map, i.e. in our Due to the required speed and reliability of the
case by other tool randomly generated maps with some searching, we chose this algorithm. Our tests of the
known labeled objects, the real (but yet only partial) city selected algorithm are included as well as the introduction
map, and the map of the university campus; type a search of the visualization system within we needed to
phrase and see what is found and displayed. Now follows implement them.
the test of path-finding abilities. Function go-to-object From the test results some conclusions can be made.

Figure 9. Main screen of 3D city information system Figure 11. Walk-through animation of 3D city information system
The blind-search algorithm is fast but is not accurate graphics and virtual reality systems. Collision detection is
enough and can be used in maps with low number of the main area of it, but, as this article implies, the
obstacles only when the results have to be gained as fast information system area should follow these trends as well
as possible and the route does not have to be the shortest by implementing its algorithms into the visualization and
one. A* algorithm is the most used algorithm and showed searching modules.
its qualities in our tests as well. Despite time results (the Large graphical data volumes are not only points clouds
speed of this algorithm is not the fastest), this algorithm is got from three-dimensional scanning but also spatial data
reliable on 100% and has provided better results. The from existing maps. These data are exactly the ones
optimization techniques of set size restrictions were useful processed, gathered, edited, searched etc. in conclusion
and brought higher speed into execution of path-finding. with extending nongraphical information by GIS.
The implementation of both algorithms showed up as
useful, but the significant difference of applicability ACKNOWLEDGMENT
between them excludes the blind-search algorithm from This work is supported by VEGA grant project No.
the set of candidates of route-searching algorithms for a 1/3136/06: “Research of parallel, distributed and network
GIS. computer systems applications to solve computational
We implemented the 3D city information system as a processes in an area of large graphical data volumes
prototype of a GIS. The included functionalities except processing.”
those presented include the object browser and map editor.
In the future, we plan to interconnect the system with REFERENCES
other systems for geographical data processing such points
[1] J. Tuek, Geographical Information Systems, “Geografické
clouds analyzers, video or ortophoto processors etc. informaní systémy” (original Czech title), Praha: Computer
Our plan is also to extend the models as huge as Press, 1998.
possible and provide a more complex information system [2] M. Buko and M. Kle, Discrete Mathematics, “Diskrétna
applicable for logistics as well. Matematika” (original Slovak title), Koice: Academic press elfa,
1999.
The similarity to today’s GPS in the case of route-
searching is intentional. According to the trends in the [3] M. Vlasova, “3D city information system,” DCI FEEI TU, Koice,
diploma thesis, 2008.
area, future navigation systems might offer three-
[4] T. Barron, Strategy Game Programming with DirectX 9.0,
dimensional interfaces as well. The only difference is in Wordware Publishing Inc., 2003.
the type of the map, because our system uses a static map [5] J. Adams, Advanced Animation with DirectX, Premier Press, a
while a good navigation system uses a dynamic one that division of Course Technology, 2003.
might future GIS use too.
As we mentioned in the introducing section, the use of
graph theory becomes common in modern computer

You might also like