You are on page 1of 60

/ Department of

Mechanical Engineering
Manufacturing Networks

Topology Optimization versus A:


a comparison for 2D robot path
planning
A.R.P. Andrin

Where innovation starts

Report Number: MN-420707

Topology Optimization versus A*:


a comparison for 2D robot path planning
Alex Andrien
Mentors: dr.ir. L.F.P. Etman, ir. J.J.M. Lunenburg

December 12, 2012

Bachelor Final Project


Manufacturing Networks Group
Departement of Mechanical Engineering
Eindhoven University of Technology
PO Box 513
5600 MB Eindhoven
The Netherlands
http://mn.wtb.tue.nl/

Cover picture from: https://www.jacobsschool.ucsd.edu/uploads/

Abstract
In this article two algorithms for robot path planning are compared and
reviewed on completeness, optimality, error reporting and computational
cost. The algorithms considered are the widely used A* algorithm and the
recently developed Topology Optimization Method (TOM). We compare
both algorithms and proceed implementing them in Matlab to study several
specific cases. These cases include new and previously proposed simulations
to test the strength of the algorithms under several limiting cases. We show
that A* is always complete, optimal and reports if a path does not exist. On
the other hand, the TOM algorithm does not satisfy these criteria, but has
lower computational cost especially for larger search domains. This study
suggests that future research in robot planning could focus on combining
the A* and TOM algorithms to create a hybrid algorithm.

Contents
1 Introduction

2 Topology Optimization Method


2.1 Finite element method on heat transfer . . . . . . . . . . . .
2.2 Robot path adaptation . . . . . . . . . . . . . . . . . . . . . .
2.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . .

3
4
5
7

3 A* Algorithm
3.1 Overview . . . . . . . . .
3.2 Heuristics . . . . . . . . .
3.2.1 Manhattan . . . .
3.2.2 Diagonal . . . . . .
3.2.3 Euclidian . . . . .
3.2.4 Choice of heuristic
3.3 Implementation . . . . . .

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

4 Comparison
4.1 Requirements for a path planning algorithm . . . . . . . . . .
4.2 Test problems proposed by Ryu et al. (2012) . . . . . . . . .
4.2.1 Case 1: Symmetrical obstacles, start and goal . . . . .
4.2.2 Case 2: Different obstacles, multiple paths . . . . . . .
4.3 Newly developed test cases . . . . . . . . . . . . . . . . . . .
4.3.1 Case 1: A* challenge . . . . . . . . . . . . . . . . . . .
4.3.2 Case 2: Elaborate Maze . . . . . . . . . . . . . . . . .
4.4 Cases with a stopover . . . . . . . . . . . . . . . . . . . . . .
4.4.1 Case 1: Symmetrical obstacles, start, stopover and goal
4.4.2 Case 2: Different obstacles, multiple paths with stopover
4.5 Cases with mesh refinement . . . . . . . . . . . . . . . . . . .
4.6 Real life case . . . . . . . . . . . . . . . . . . . . . . . . . . .

8
8
9
10
10
11
11
11
12
12
13
13
14
14
15
16
17
17
19
20
21

5 Conclusions and Recommendations


23
5.1 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.2 Recommendations . . . . . . . . . . . . . . . . . . . . . . . . 24

A MATLAB code for robot path planning using topology optimization (by Van den Goor (2012))
27
B MATLAB code for robot path planning using topology optimization with adaptations and path calculation
31
C A* Matlab code including subfunctions

37

D Map Editor

45

E Cases with
E.1 Case 1:
E.2 Case 2:
E.3 Case 3:
E.4 Case 4:
E.5 Case 5:

52
52
53
53
54
54

increasing mesh refinement


80x80 (6x6 m) . . . . . . . . . .
120x120 (9x9 m) . . . . . . . . .
160x160 (12x12 m) . . . . . . .
200x200 (15x15 m) . . . . . . .
240x240 (18x18 m) . . . . . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

Chapter 1

Introduction
In the last few years mobile robots have found many practical applications,
including: logistics (moving packages), military (explosives removal), domestic (house cleaning), medical (assisting robots, see also RoboCup (2012)) and
many more. Mobile robots encompass a wide variety of different research
fields, including mechanics, dynamics, micro-scale engineering, manufacturing networks and many more. The focus of this article is on robot path
planning.
Robot path planning in general requires an algorithm to find a suitable path between a start and finish point (with optional stops in between)
whilst avoiding certain areas referred to as obstacles. It is essential for mobile robots to have good path planning in order to efficiently move and avoid
obstacles. Masehian and Sedighizadeh (2007) give an overview of algorithms
for robot path planning. The path planning research area can be roughly
divided in to two areas: global and local path planning. Global path planning is concerned with determining a route from start to finish on a large
scale, whilst local path planning manages the movement in the area directly
around the robot often including dynamic obstacles. The global path planner should also prevent a robot from entering an infinite loop, which can
occur when using a local path planner only.
The main challenges considering global path planning consist of compiling the the available information into an effective and appropriate configuration space and subsequently using a search algorithm to find the best path
in that space. This article concerns itself with the search algorithms used
to find the best path.
A commonly used search method is the A* (pronounced A-star ) algorithm, which was first introduced in 1968 by Hart et al.. The algorithm is an
improvement of Dijkstras algorithm and Best-First-Search (BFS) by using
the best parts of both. The advantage of the A* algorithm is that it favors
points close to the starting point (Dijkstras algorithm) as well as point close
to the goal point (BFS) using an estimation (or heuristic). Because of this,

A* still guarantees to find the shortest path possible like Dijkstras algorithm, but is significantly faster because of the heuristic and the resulting
smaller search area.
Recently, Ryu et al. (2012) proposed a new algorithm for robot path
planning. They formulate the path planning problem as an equivalent heat
conduction problem, with the start point as a heat source, the goal point
as a heat sink and all obstacles as thermal insulators. Ryu et al. (2012)
apply topology optimization (Bendse and Sigmund, 2004) to determine the
optimal heat path from heat source to heat sink. The problem parameters
are adjusted so that only a single path is obtained, preferably of single
element thickness.
The main goal of this article is to compare the TOM in its current form
as a global path planning method with the widely used A* algorithm. The
implementation will be done in MATLAB, because the Topology Optimization Method is already programmed in MATLAB by Van den Goor (2012)
using the 88-line MATLAB code by Andreassen et al. (2011). Besides this
obvious advantage, MATLAB also offers excellent debugging tools and extensive graphic handling opportunities.
These methods will be reviewed briefly together with their implementation in Sections 2 and 3, respectively. The comparison results for speed,
consistency, resulting paths and (dis)advantages of one compared to the
other will be discussed in Section 4. The article ends with a conclusion and
discussion in Section 5.

Chapter 2

Topology Optimization
Method
The TOM used in the comparison of this article has been developed by Ryu
et al. (2012). It is based on topology optimization for heat transfer problems and uses analogies between robot path planning and heat flow: the
areas where a robot can move freely (free configuration space) are the design domain for conductive heat transfer, the areas where the robot cannot
go (obstacle configuration space or obstacles) are designed as thermal insulators and the start and goal points of robot path planning are modeled as a
heat source and heat sink, respectively. To clarify, the analogies are graphically represented in Figure 2.1, where C is the robot configuration space
and the design domain for the thermal compliance topology optimization
problem.

Figure 2.1: Analogy between (a) robot path and (b) topology optimization
of a heat path (Ryu et al., 2012)

2.1

Finite element method on heat transfer

In order to create the TOM, the finite element method is first applied to the
following governing equation for two-dimensional steady state heat transfer
in a design domain (Dewitt and Incropera, 2002):
(k) + h + Q = 0

in

(2.1)

with boundary conditions:


=

on 1

(2.2)

q = q

on 2

(2.3)

where k and h are the thermal conductivity and convective heat transfer coefficients, Q denotes heat generation, (= T T ) is an excess temperature
with T the temperature of the material and T the surrounding temperature, is a pre-defined value on the boundary 1 and q is the heat flux
defined on 2 .
Applying the finite element method results in the matrix equation:
K = F

(2.4)

where matrix K contains the thermal conductivity of the elements, matrix


contains the nodal temperatures and matrix F is the driving force for the
heat flow (heat flux), set here to an arbitrary value of 0.01 on the entire
domain, except at the heat sink (see Section 2.2). To formulate a topology
optimization problem to find an optimal heat path, the thermal conductivity
k e of the e-th finite element must be interpolated as a function of the element
density design variable e (0 e 1). Here, the interpolation proposed
by Yang and Chuang (1994) is used:
k e = k 0 e p

(2.5)

where k0 is the nominal thermal conductivity and p a penalty exponent.


For varying the penalty exponent the method proposed by Ryu et al. (2012)
is used:
(
1
for n nc (n : iterationnumber)
p=
min(3, 1 + 0.1 (n 10)) for n > nc

(2.6)

where nc can be modified depending on the problem.


The design objective for the problem formulated above is to minimize the
thermal compliance subject to a mass constraint. The thermal compliance
minimization used is given by (Bendse and Sigmund, 2004):
minimize(1 ,2 ,3 , ,N e)
Ne
X

= FT = T K

e me M0 0

(2.7)

(2.8)

e=1

0 < e 1 (e = 1, 2, . . . , N e : = small value)

(2.9)

Here (2.8) is the mass constraint, where me is the mass of the e-th
element and M 0 the allowed total mass.

2.2

Robot path adaptation

In order to adapt the finite element heat transfer model discussed in the
previous paragraph for use in robot path planning, the design space needs
to be converted to equivalent heat flow definitions. This includes the free
design space, obstacle space as well as the start and finish point. The free
design space is modeled as an arbitrary heat flow with:
0 < r 1,
5

qr 6= 0

(2.10)

with r the mass of the free element and qr the load vector component.
The obstacle space is then modeled as thermal insulators according to:
0 = 0,

q0 = 0

(2.11)

To define the start and goal point the essential boundary conditions in
(2.2) and (2.3) will be used. The starting point is modeled as a heat source
when it is located inside the design domain and as a incoming heat flux
when it is located on the boundary of the design domain. Also the following
essential boundary condition is used (see Equation 2.2):
start = 0

(2.12)

The goal point is defined as a heat sink, resulting in surface normal


convection if the goal point is inside the domain and side convection if the
goal point is on the edge of the domain. For the convection an arbitrary
value that proved to function well during tests is used. Ryu et al. (2012)
does not give specific values, so the value proposed by Van den Goor (2012)
is used:

Ne
qsink = qr + qconv , qconv =
(2.13)
10
By using the optimality criteria method of Bendse and Kikuchi (1988),
an optimization algorithm with the following convergence criterium is defined:
|n n1 |/|n |
(n : the objective function value at the n-thiteration)

(2.14)

Check the criterion for three consecutive iteration numbers

(2.15)

A typical value of is 0.01

(2.16)

The allowed total mass needs to be correctly chosen in order to avoid multiple and/or meaningless paths. It is required that the algorithm produces
a unique path because otherwise there has to be chosen between several
possible paths, which slows down the algorithm. Also, most of these other
possible paths will be longer than the optimal one. Here Van den Goor
(2012) uses the same method as Ryu et al. (2012) again, being:
M0 (n) = max((n), Mmin )

(2.17)

PN e

e=1 me
n2

(n) =

(2.18)

Mmin =

|PG PS |me
PN e
e=1 me

(2.19)

(PG , PS : position vector of the goal and starting points)


From (2.17) and (2.18) it becomes clear that the algorithm starts with
the full mass and decreases with 1/n2 towards Mmin . This minimum mass
is defined in (2.19) as the Euclidian distance between the start and goal
points, so no path connecting the starting and goal point is shorter than
a straight line. Although this approach works in most cases, it does not
always yield the desired result. If the value of Mmin is too low, the path
will not have enough mass and will be incomplete, if it is too high the path
can be too wide or have some incomplete sidetracks. The above equations
try to solve this by either calculating the correct minimum mass or by the
TOM converging somewhere between the full mass and Mmin .

2.3

Implementation

The Topology Optimization Method used in the comparison in this article


was very recently implemented by Van den Goor (2012). It is an adaptation
on the 88 line Matlab code by Andreassen et al. (2011), making it suitable
for robot path planning and introducing a useful interface to create, load and
save 2D maps. The 88 line Matlab code itself is an improvement on the 99
Matlab code (Sigmund, 2001), which was developed to provide a relatively
simple topology optimization code for compliance minimization of statically
loaded structures. In the report by Van den Goor the 88 line Matlab code
is combined with the research paper of Ryu et al. (2012) to create a robot
path planning algorithm that uses heat flow topology optimization. The
Matlab file that results from the steps followed in this section was created
by Van den Goor (2012) and can be found in Appendix A. In order to make
the Matlab file suitable for this comparison, several adjustments were made
which are shown in Appendix B.

Chapter 3

A* Algorithm
3.1

Overview

A* was rst presented in 1968 by Hart et al. and since has been widely used
in path nding problems. The paper gives the proof that A*, if correctly
implemented (see Section 3.2), is both admissible and minimalistic. An
algorithm is admissible if the algorithm is guaranteed to nd the shortest
path, if there is one. It is minimalistic if compared to other admissible
algorithms with the same knowledge of the search area, it will investigate
the minimal amount of nodes necessary to nd an optimal path.

(a) Step 1 and 2

(b) Step 4

Figure 3.1: Example of the A* algorithm Step 1 and 2 (a) and 4 (b), with
the green, red, black and blue squares the start, goal, free and obstacle nodes
respectively (Guerin, 2011)
The way A* does this is by rst reading the search area, adding all
This description has been made using Patel (2012)

obstacles to the closed list. This list contains all the nodes that have already
been explored or should not be explored at all. It then sets the start node
as the current node, of which it adds all its neighbors, except for the ones
in the closed list, to the open list, which holds all nodes that still need to
be checked (Figure 3.1a). Along with each neighbor several parameters are
added, namely: g(n), h(n), f (n) and their parent node, where n is a number
to identify each node. Here g(n) is the cost of moving from the starting point
to it, h(n) is an estimate of the cost of the distance between the neighbor
and the goal point using some heuristic (more on this cost in Section 3.2),
f (n) = g(n) + h(n) is the total cost and the parent node is the node from
which the node in question was discovered. Next, it checks if some of the
neighbors are already in the open list; if there are, it checks whether the
newly calculated f (n) score is lower than the one currently attached to it. If
this is the case, g(n), f (n) and parent node are updated. It then chooses the
neighbor with the smallest f (n) score, sets it as the current node, removes
it from the open list and adds it to the closed list (Figure 3.1b). These
steps are repeated until the target node is added to the closed list or until
the open list is empty. If the target is added to the closed list, the optimal
path is constructed by tracing back the path by following the parent nodes
until the start node is reached. If the open list is empty, it means no path is
possible and the algorithm terminates. The algorithm is summarized below.
1. Set start node as current node and add it to the closed list
2. Add all neighbors of the current node to open list along with g(n),
h(n), f (n) and their parent node
3. If a neighbor is already in the open list, check if the f (n) score is lower
and if so, update g(n), h(n), f (n) and its parent
4. Choose the node with the smallest f (n) score in the open list, set it as
the current node, remove it from the open list and add it to the closed
list
5. Repeat step 2 through 4, until the target node is added to the closed
list, or until the open list is empty
6. If the target node is found, retrace the nodes by identifying their parents until the start node is found; this is the shortest path
7. If the open list is empty, no path to the target is possible

3.2

Heuristics

The kind of heuristic used in the A* algorithm greatly influences its speed.
Also, for A* to be admissible, the heuristic must satisfy the following demand
9

(Hart et al., 1968):

h(n) h(n)

for all n

(3.1)

where h(n) is some estimate for the cost of the optimal path from node n

to the target node and h(n)


is the actual cost. The demand states that the
heuristic may never over estimate the cost of the optimal path from node n
to the target node, for all n.
Because of the importance of the used heuristic, we will take a look at
the ones used in the comparison between the two algorithms. Three different
kinds of heuristics will be examined: Manhattan, Diagonal and Euclidian.
They all use the same principle: calculating the shortest path between the
current node and the goal node, thus satisfying (3.1). The difference is in
the allowed movement on the grid.

3.2.1

Manhattan

This heuristic is commonly used for square grids that only allow horizontal
and vertical movement (this also requires a different algoritme that blocks
diagonal movement). The name itself comes from the Manhattan island,
with its streets divided in blocks by avenues and streets. The heuristic cost
h(n) is calculated by:
h(n) = |xn xgoal | + |yn ygoal |

(3.2)

Here xn , xgoal , yn and ygoal are the node x-position, goal x-position,
node y-position and goal y-position, respectively.

3.2.2

Diagonal

Diagonal heuristic is very similar to Manhattan heuristic, with the slight


difference that it is used for square grids that allow diagonal movement.
The cost is calculated by:

h(n) =

hmanhattan (n) = |xn xgoal | + |yn ygoal |

(3.3)

hdiagonal (n) = min(|xn xgoal |, |yn ygoal |)

(3.4)

2 hdiagonal (n) + (hmanhattan (n) 2 hdiagonal (n))

(3.5)

In short, the algorithm first calculates what the distance would be if the
Manhattan heuristic is used (3.3), then the number of possible diagonal steps
are calculated (3.4) and finally the shortest diagonal distance is calculated
by adding the distance gained and subtracting the distance won by diagonal
movement from the Manhattan distance (3.5).

10

3.2.3

Euclidian

The Euclidian heuristic is used when movement in any angel is allowed in


the grid, instead of only grid directions, resulting in the following heuristic
cost:

h(n) = (xn xgoal )2 + (yn ygoal )2


(3.6)

3.2.4

Choice of heuristic

The heuristic used in this article will be Diagonal, since the Manhattan
heuristic might overestimate the cost of the optimal path because it does
not use diagonal moves, thus not satisfying Equation 3.1. The Euclidian
heuristic does not overestimate the cost, however it tends to be slower than
Diagonal because of the larger amount of explored nodes and the high computational demand of the square root. For instance, Figure 3.2 represent
the paths calculated using the Euclidian and Diagonal heuristic in red, the
nodes on the open and closed list in light blue and yellow, respectively and
the unexplored area in dark blue. The calculation times in this case were
0.243 and 0.084 seconds for Euclidian and Diagonal heuristic, respectively.

(a) Euclidian

(b) Diagonal

Figure 3.2: A*

3.3

Implementation

The A* algorithm was implemented using the Interactive A* Search Demo


from MATLAB (2012) adding a path length calculation, a convertor to read
the map input and a visualization of the path found including visited nodes.
The algorithm and corresponding subfunctions are shown in Appendix C.

11

Chapter 4

Comparison
In the previous chapters the basics of the A* and TOM algorithms have
been described. To compare the two methods we start with the demands
for a path planning algorithm, followed by a selection of two test cases from
Ryu et al. (2012), after which two newly devised test cases will be used
to find specific (dis)advantages of both methods. Thereafter, two cases to
test how the methods deal with a stopover are discussed, then several cases
with increasing mesh refinement are researched and to conclude a real world
scenario will be tested.
With each case three plots will be shown, the first being the problem
definition, the second the path found by the A* method as well as the nodes
in the closed (yellow) and open (light blue) lists (this is useful in explaining
the results) and the third is the path found by the TOM. A table with
the path length and calculation time of both methods will also be shown
for each test case. To reduce the effects of deviations in calculation time
caused by computational demand of the system the calculation time will be
averaged over ten iterations. Because of the importance of some settings
(see Adjustment 4 in Appendix B and Section 2.2) in the algorithm of the
TOM, these settings will also be displayed in the table. The maps used were
created using the Matlab file in Appendix D which is based on a previous
map editor by Van den Goor (2012).

4.1

Requirements for a path planning algorithm

In order to make an objective comparison between the algorithms some requirements for a path planning algorithm have to be defined. The algorithms
will be tested against the following criteria:
1. Completeness: the algorithm always finds a path if there is one
2. Reporting Failures: if there is no path possible or the algorithm simply
does not find one, (how fast) does the algorithm report this?
12

3. Optimality: the path found is the shortest one possible


4. Computational cost: the calculation time necessary to nd the path

4.2
4.2.1

Test problems proposed by Ryu et al. (2012)


Case 1: Symmetrical obstacles, start and goal

(a) Problem Denition

(b) A*

(c) TOM

Figure 4.1: Case 1


This case presents a symmetric problem, with two obstacles and two possible, optimal paths. In Figure 4.1, it can be seen that both methods nd a
path, but the one TOM found is slightly longer. This is because the heat
dissipates from the source in all directions evenly and the sink draws the
heat back towards it, resulting in an arc. In some way the TOM is still
optimal, because the implementation by Van den Goor (2012) denes distance as the number of elements instead of Euclidian distance, which makes
the small detour it takes irrelevant. However, in a real world scenario this
would in fact be a small detour, so in its current implemented form the
TOM does not nd the optimal path for this case. This could be adapted
using post-processing, but this would make it slower. So both algorithms
are complete, A* is optimal and the TOM is faster by a small margin as
shown in Table 4.1.
Table 4.1: Results Case 1
Method

Path Length [-]

Calculation Time [s]

Mmin

A*
TOM

55,11
55,94

0,61
0,57

0,0235

13

4.2.2

Case 2: Dierent obstacles, multiple paths

(a) Problem Denition

(b) A*

(c) TOM

Figure 4.2: Case 2


In the second case, the design area consists of multiple dierently shaped
obstacles, and presents the algorithms with several possible paths. The
two algorithms are complete, although they nd dierent paths, as shown
in Figure 4.2. The one found by the TOM is longer, but perhaps more
interesting is that the path is not one element wide. This can be solved by
changing the rate at which M0 (n) is decreased in (2.17), further reducing
the robustness of the algorithm, because it would mean changing another
parameter for every problem. Also, A* is almost ve times faster than the
TOM, as shown in Table 4.2.
Table 4.2: Results Case 2

4.3

Method

Path Length [-]

Calculation Time [s]

Mmin

A*
TOM

64,53
65,11

0,15
0,65

0,0291

Newly developed test cases

Both algorithms deal with the previous cases without very signicant differences apart from the calculation times in the second case. The following
cases are designed to be hard for either the A* algorithm (4.3.1) or the TOM
(4.3.2), revealing their specic strengths and weaknesses.

14

4.3.1

Case 1: A* challenge

(a) Problem Denition

(b) A*

(c) TOM

Figure 4.3: Case 1


This case (Figure 4.3) is designed to challenge the A* algorithm to see in
which case it would slow down, by tricking it using the same heuristic
that makes it so fast. Because of the heuristic, the costs of the nodes in a
direct diagonal to the goal will be lower, so these are searched rst. Both
algorithms calculate paths of the same length and are complete as well as
optimal, only A* takes nearly twice as long to nd it. Because of the heuristic
used, it will rst search almost the entire map before nding the actual path,
resulting in a large open list which has to be searched every time a new node
is explored. The TOM does not have this disadvantage and nds the path
faster as shown in Table 4.3.
Table 4.3: Results Case 1
Method

Path Length [-]

Calculation Time [s]

Mmin

A*
TOM

76,24
76,24

1,04
0,54

0,044

15

4.3.2

Case 2: Elaborate Maze

(a) Problem Denition

(b) A*

(c) TOM

Figure 4.4: Case 2


Contrary to the previous case, this map (Figure 4.4) has been designed to
challenge the TOM. The labyrinth makes it impossible for the TOM in its
current form to nd a complete, single element width path even if both the
rate at which M0 (n) is decreased and the minimum mass are tuned. They
can be tuned to generate a path, but this would make it incredibly wide and
would need post-processing to choose a direction. Another disadvantage is
revealed in this case, namely that the TOM in its current form does not
report if it has not found a complete path. Apart from challenging the
TOM, this problem shows one of A* greatest strengths: no matter how
complicated the path, if there is one, A* will nd it (see Section 3). Also,
A* does report if there is no path. In short, A* always satises the rst
three points of Section 4.1 while the TOM is not guaranteed to do so. The
calculation times are displayed in Table 4.4, where the time noted for the
TOM is the time needed until the solution of Figure 4.4c.
Table 4.4: Results Case 2
Method

Path Length [-]

Calculation Time [s]

Mmin

A*
TOM

287,56
-

0,408
0,44

0,3

16

4.4

Cases with a stopover

In this section we will investigate how the two algorithms deal with a user
specied stopover. Both cases are from Ryu et al. (2012) and are the same
as the cases in Section 4.2, except for the added stopover. In this section,
an extra gure is added, because the A* algorithm is implemented to rst
nd a path from the start to the stopover and then from the stopover to the
goal. Both paths are shown separately.

4.4.1

Case 1: Symmetrical obstacles, start, stopover and


goal

(a) Problem Denition

(b) A* rst step

(c) A* second step

(d) TOM

Figure 4.5: Case 1


From Figure 4.5 it becomes clear that both algorithms deal with the stopover
correctly and nd the shortest path, although A* turns right and TOM
17

turns left. Interestingly, A* is twice as fast as in the case without the


stopover while the TOM is slightly slower than in Case 4.2.1, losing its
small advantage in calculation time. It can be explained that A* is faster
in this case by recognizing that the area it has explored is smaller. Another
important thing to take into account is that the open list is emptied after
the stopover is found, this means the open list never becomes as large as
in Case 4.2.1. This is a very large contribution to the calculation time of
the algorithm, since all the entries of the open list have to be checked every
time a new node is set to current (steps two through four in Section 3.1).
Table 4.5: Results Case 1
Method

Path Length [-]

Calculation Time [s]

Mmin

A*
TOM

76,08
76,08

0,33
0,72

0,0345

18

4.4.2

Case 2: Dierent obstacles, multiple paths with stopover

(a) Problem Denition

(b) A* rst step

(c) A* second step

(d) TOM

Figure 4.6: Case 2


This case (Figure 4.6) is also handled correctly by both algorithms, although
the path found by the TOM is longer as shown in Table 4.6. The calculation
times are slightly longer for both algorithms in comparison with Case 4.2.2,
which is expected since the stopover forces longer paths. The A* algorithm is
one tenth of a second slower in comparison to the case without the stopover,
while in the previous case the stopover sped up the algorithm by a factor
of two. This can be explained by the fact that the search area is somewhat
larger and the eect of clearing the open list when reaching the stopover is
reduced because most of the path has already been found.

19

Table 4.6: Results Case 2

4.5

Method

Path Length [-]

Calculation Time [s]

Mmin

A*
TOM

83,84
85,84

0,25
0,70

0,0349

Cases with mesh renement

(a) A*

(b) TOM

Figure 4.7: Case 5


To investigate how the algorithms handle larger or higher resolution maps
we will increasingly rene the mesh of the case in Section 4.2.2, starting
from the original 40x40 element map until a map six times larger of 240x240
elements. Using the same resolution as the real life case (Section 4.6) of 0.075
meters, the mesh renement will range from 3x3 meters to 18x18 meters.
These resulting calculation times associated with each mesh are shown in
Table 4.7. Clearly, A* is faster for smaller meshes but the TOM is faster
from meshes of 160x160 elements and upwards. This becomes interesting
when we will look at a real life scenario in Section 4.6. For compactness
of the article, there is only one plot of the mesh renement shown, namely
the nal one of 240x240 elements (Figure 4.7). The remaining results are
displayed in Appendix E. From Figure 4.7 it becomes clear that A* deals
with the larger map in a very similar way as it did with the original, small
map. The TOM on the other hand shows a strange second path and various
obvious detours.

20

Table 4.7: Results mesh renement


Method / Mesh Size
Time [s] A*
Time [s] TOM

4.6

40x40

80x80

120x120

160x160

200x200

240x240

0,15
0,65

1,43
2,92

6,53
7,10

18,59
12,50

45,52
20,62

93,94
36,97

Real life case

(a) Problem Denition

(b) A*

(c) TOM

Figure 4.8: Case 1


The map Figure 4.8 is a discretized version of a laser scan of the arena of
the RoboCup Dutch Open @Home competition. The original map was 21.6
by 17.1 meters and had a resolution of 0.025 meters (so 865x665 elements),
but for this case the resolution was changed to 0.075 meters (288x228 elements) to balance speed an accuracy. As can be seen, both algorithms nd
the optimal path, but the one found by the TOM does not have single element thickness throughout. Also, the TOM is more than twice as slow as
the A* algorithm (see Table 4.8), which would contradict the results from
Section 4.5 because the real life map is discretized in 288x228 elements. The
explanation for this contradiction can again be attributed to the size of the
open list in the A* algorithm, because half of the map is not searched the
open list remains relatively small.
Table 4.8: Results real life case
Method

Path Length [-]

Calculation Time [s]

Mmin

A*
TOM

184,84
184,84

15,27
35,28

0,0028

To verify the previous notion the test case is altered with an obstacle in
the way of the current path, forcing both algorithms to nd a way around it.
In Figure 4.9 again both cases nd a path, so they are complete. The TOM
is far from optimal, showing a wide path and some unnished ones like in
21

Section 4.5. A* is still optimal, but the calculation times yield interesting
results (Table 4.9). Where the TOM has a calculation time similar to the
previous case, A* is almost six times slower. This is also more in line with
the results from Section 4.5 and gives rise to the notion that the calculation
time of the A* algorithm depends more strongly on the shape of the map
as well as the length of the path than with the TOM. When looking at the
cases previous to the mesh renement, where all maps are 40x40, the same
seems to hold true: A* calculation times range from 0.15 to 1.04 seconds
while the TOM calculation times only range from 0.54 to 0.72. So for maps
of the same size, the TOM seems to have more consistent calculation times
than A*.

(a) Problem Denition

(b) A*

(c) TOM

Figure 4.9: Case 1


Table 4.9: Results additional real life case
Method

Path Length [-]

Calculation Time [s]

Mmin

A*
TOM

265,85
265,85

87,07
30,45

0,016

22

Chapter 5

Conclusions and
Recommendations
5.1

Conclusions

The TOM and A* algorithm have been compared using a combination of


existing problems, newly developed cases and real life scenarios, showing
that the algorithms deal with most problems correctly, including stopovers.
The advantages and disadvantages of the algorithms were tested according
to the criteria in Section 4.1, with the results shown below.
A*
Completeness: Proven in theory by Hart et al. (1968)
Reporting Failures: Very simple implementation
Optimality: Proven in theory by Hart et al. (1968)
Computational cost: Good for small maps, but very high for large
maps because of large open list, see Case 4.4.1 in Section 4.4
Topology Optimization Method
Completeness: Not guaranteed, could by improved by estimating the
allowed mass better (see Equation 2.17)
Reporting Failures: Currently not possible, algorithm will converge
without reporting incomplete path
Optimality: Not guaranteed, heat flow causes arcs which do not always
form the optimal path, see Case 4.2.1 in Section 4.2
Computational cost: Higher than A* on small maps, but lower for
large maps
23

5.2

Recommendations

The great disadvantage of the TOM is its lack of robustness, the method
proposed by Ryu et al. (2012) does not always yield the shortest path,
but more importantly it does not always yield a complete path. If the
estimation of the allowed mass would be improved it would greatly improve
the robustness of the TOM and make it far more interesting for robot path
planning.
A* already has very good aspects for path planning, but lacks fast calculation times for large maps with long paths. A possibility to remedy this
is to add stopovers in the calculation of the path, shortening the calculation
time by clearing the open list, as shown in the stopover cases (Section 4.4).
However, this is currently not possible without sacrificing the guarantee of
an optimal path.
Further research could also be done to see how both algorithms deal
with varying terrain costs, where the TOM already proves promising (see
Ryu et al. (2012) and changing maps to investigate the alternatives both
algorithms find when the original path is blocked.
Lastly an interesting possibility for further research arises from this comparison: a combination of both the TOM and A* algorithm. Using the TOM
to quickly find wide or even multiple paths and then using this narrowed
down search area for A* to find the optimal and correct path. This could
combine the guarantee of A* to find the shortest path with the speed of the
TOM, and would be especially useful for large maps.

24

Bibliography
E. Andreassen, A. Clausen, M. Schevenels, B.S. Lazarov, and O. Sigmund.
Efficient topology optimization in matlab using 88 lines of code. Structural
and Multidisciplinary Optimization, 43(1), 2011.
M.P. Bendse and N. Kikuchi. Generating optimal topologies in structural
design using a homogenization method. Computer methods in applied
mechanics and engineering, 71(2), 1988.
M.P. Bendse and O. Sigmund. Topology optimization: theory, methods and
applications. Springer, 2004.
D.P. Dewitt and F.P. Incropera. Fundamentals of heat and mass transfer.
Wiley, 2002.
F. Guerin. a star pathfinder v. 1.92.exe. Course: Grand Challenges of
Artificial Intelligence, July 2011.
P.E. Hart, N.J. Nilsson, and B. Raphael. A formal basis for the heuristic
determination of minimum cost paths. Systems Science and Cybernetics,
IEEE Transactions on, 4(2), 1968.
E. Masehian and D. Sedighizadeh. Classic and heuristic approaches in robot
motion planning - a chronological review. World Academy of Science,
Engineering and Technology, 23, 2007.
MATLAB. version 7.14.0.739 (R2012a). The MathWorks, Inc., Natick,
Massachusetts, 2012.
A. Patel. Heurstics (from amits thoughts on pathfinding), October
2012. URL http://theory.stanford.edu/~amitp/GameProgramming/
Heuristics.html#heuristics-for-grid-maps.
RoboCup.
RoboCup @Home, October 2012.
robocupathome.org.

URL http://www.

J.C. Ryu, F.C. Park, and Y.Y. Kim. Mobile robot path planning algorithm
by equivalent conduction heat flow topology optimization. Structural and
Multidisciplinary Optimization, 1(1), 2012.
25

O. Sigmund. A 99 line topology optimization code written in matlab. Structural and Multidisciplinary Optimization, 21(2), 2001.
V.J.P. Van den Goor. Trajectorie-planning van een mobiele robot met behulp van topologieoptimalisering. Bachelor End Project, Departement
of Mechanical Engineering, Eindhoven University of Technology, August
2012.
RJ Yang and CH Chuang. Optimal topology design using linear programming. Computers & Structures, 52(2), 1994.

26

Appendix A

MATLAB code for robot


path planning using topology
optimization (by Van den
Goor (2012))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

%%%% AN 88 LINE ROBOT PATH OPTIMIZATION CODE July, 2012 %%%%


function [obj vol path] = top88r(nelx,nely,nc,rmin,fast,Mn,MAP)
tic
ft=1;
obsx=[];
obsy=[];
sourcepos=[];
sinkpos=[];
mapsize=size(MAP);
for i=1:mapsize(1)
for j=1:mapsize(2)
if MAP(i,j)==1
obsx=[obsx i];
obsy=[obsy j];
elseif MAP(i,j)==3
sourcepos=[sourcepos j1 i1];
elseif MAP(i,j)==4
sinkpos=[sinkpos j i];
end
end
end
%% MATERIAL PROPERTIES
E0 = 1;
Emin = 1e9;
%% PREPARE FINITE ELEMENT ANALYSIS
KE = [ 2/3 1/6 1/3 1/6
1/6 2/3 1/6 1/3

27

28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52

1/3 1/6 2/3 1/6


1/6 1/3 1/6 2/3];
nodenrs = reshape(1:(1+nelx)*(1+nely),1+nely,1+nelx);
edofVec = reshape(nodenrs(1:end1,1:end1),nelx*nely,1);
edofMat = repmat(edofVec,1,4)+repmat([0 nely+[1 2] ...
1],nelx*nely,1);
iK = reshape(kron(edofMat,ones(4,1))',16*nelx*nely,1);
jK = reshape(kron(edofMat,ones(1,4))',16*nelx*nely,1);
% DEFINE LOADS AND SUPPORTS
F = sparse((nely+1)*(nelx+1),1);
% Conduction force
iF = 0.01;
F(:,1)=iF;
for a=1:numel(obsx)
F((obsy(a)1)*(nely+1)+obsx(a),1)=0;
end
% Robot end points
qv=sqrt(nelx*nely)/10; %Arbitrary convection component
for i=1:numel(sinkpos)/2
nodes = [1 0 nely nely1] + ((nely+1)*sinkpos(2*i1) + ...
sinkpos(2*i));
F(nodes,1)=iF+qv;
end
U = zeros((nely+1)*(nelx+1),1);
fixeddofs=[];
for i=1:numel(sourcepos)/2
fixeddofs = [fixeddofs ...
(nely+1)*sourcepos(2*i1)+sourcepos(2*i)+2];

53
54

55

56

57
58
59
60
61
62
63
64
65
66
67
68

69

70
71
72
73

fixeddofs = [fixeddofs ...


nely+1+(nely+1)*sourcepos(2*i1)+sourcepos(2*i)+2];
fixeddofs = [fixeddofs ...
(nely+1)*sourcepos(2*i1)+sourcepos(2*i)+1];
fixeddofs = [fixeddofs ...
nely+1+(nely+1)*sourcepos(2*i1)+sourcepos(2*i)+1];
end
alldofs = [1:(nely+1)*(nelx+1)];
freedofs = setdiff(alldofs,fixeddofs);
%% PREPARE FILTER
iH = ones(nelx*nely*(2*(ceil(rmin)1)+1)2,1);
jH = ones(size(iH));
sH = zeros(size(iH));
k = 0;
for i1 = 1:nelx
for j1 = 1:nely
e1 = (i11)*nely+j1;
for i2 = ...
max(i1(ceil(rmin)1),1):min(i1+(ceil(rmin)1),nelx)
for j2 = ...
max(j1(ceil(rmin)1),1):min(j1+(ceil(rmin)1),nely)
e2 = (i21)*nely+j2;
k = k+1;
iH(k) = e1;
jH(k) = e2;

28

sH(k) = max(0,rminsqrt((i1i2)2+(j1j2)2));

74

end

75

end

76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

104
105
106
107
108
109

end
end
H = sparse(iH,jH,sH);
Hs = sum(H,2);
%% INITIALIZE ITERATION
me=1/nelx/nely;
Mmin = ...
me*max(abs(sinkpos(1)sourcepos(1)),abs(sinkpos(2)sourcepos(2)))
x = repmat(1,nely,nelx);
xPhys = x;
loop = 0;
change = 1;
obj = []; vol = [];
cold=0; % Old objectivity function value
conv count=0; % Number of consecutive convergences
%% START ITERATION
while change > 0.01
loop = loop + 1;
%% CALCULATE ALLOWED MASS
z=1/loop; % z=1/loop2 for large maps
Mn=max(z,Mmin);
%% FEANALYSIS
if (loop <= nc)
penal = 1;
else
penal = min(3,1+0.1*(loop10));
end
sK = ...
reshape(KE(:)*(Emin+0.001+0.999*xPhys(:)'.penal*(E0Emin)),16*nelx*nely,1);
K = sparse(iK,jK,sK); K = (K+K')/2;
U(freedofs) = K(freedofs,freedofs)\F(freedofs);
%% OBJECTIVE FUNCTION AND SENSITIVITY ANALYSIS
ce = reshape(sum((U(edofMat)*KE).*U(edofMat),2),nely,nelx);
c = sum(sum((Emin+0.001+0.999*xPhys.penal*(E0Emin)).*ce));
dc = 0.999*penal*(E0Emin)*xPhys.(penal1).*ce;

110
111
112
113
114
115
116
117
118
119

120
121
122
123
124

dv = ones(nely,nelx);
%% FILTERING/MODIFICATION OF SENSITIVITIES
if ft == 1
dc(:) = H*(x(:).*dc(:))./Hs./max(1e3,x(:));
elseif ft == 2
dc(:) = H*(dc(:)./Hs);
dv(:) = H*(dv(:)./Hs);
end
%% OPTIMALITY CRITERIA UPDATE OF DESIGN VARIABLES AND ...
PHYSICAL DENSITIES
l1 = 0.1; l2 = 1e9; move = 0.2;
cnt = 0;
while (l2l1)/(l1+l2) > 1e3
cnt = cnt+1;
if (cnt>1000)

29

125
126
127
128
129
130

131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

155
156
157
158

159
160
161
162
163
164

fprintf('Terminate iteration...\n');
obj = []; vol = [];
return
end
lmid = 0.5*(l2+l1);
xnew = ...
max(0,max(xmove,min(1,min(x+move,x.*sqrt(dc./dv/lmid)))));
for a=1:numel(obsx)
xnew(obsx(a),obsy(a))=0;
end
if ft == 1
xPhys = xnew;
elseif ft == 2
xPhys(:) = (H*xnew(:))./Hs;
end
if sum(xPhys(:)) > Mn*nelx*nely, l1 = lmid; else l2 = ...
lmid; end
end
change = max(abs(xnew(:)x(:)));
x = xnew;
obj=[obj c];
vol=[vol mean(xPhys(:))];
if (abs(ccold)/abs(c))<0.01, conv count=conv count+1;
else conv count = 0;end
if (loop>3 & conv count >=3)
fprintf('Convergence, cn = %f, cn1 = %f\n',c,cold)
change = 0;
end
cold = c;
%% PRINT RESULTS
if(fast | | change <= 0.01)
fprintf(' It.:%5i Obj.:%11.4f Vol.:%7.3f ...
ch.:%7.3f\n',loop,c, ...
mean(xPhys(:)),change);
%% PLOT DENSITIES
if change<= 0.01, xPhys=round(xPhys);path = xPhys; end
imagesc(xPhys+0.25*MAP); caxis([0 1]); axis equal; ...
axis off; drawnow;
end
end
t=toc;
fprintf('Time taken: %4.3f Average/iteration: %4.4f\n',t,t/loop);
path = xPhys;
end

30

Appendix B

MATLAB code for robot


path planning using topology
optimization with
adaptations and path
calculation
The following adjustments were made to the Matlab file by Van den Goor
(2012):
1. The less or equal sign in equation (2.14) was not correctly implemented in Matlab, see line 145 in Appendix A
2. Van den Goor does not use (2.19) in the sense that the distance between the two points is not calculated by the Euclidian definition, but
rather the maximum absolute distance in x and y direction, as shown
below (line 83 in Appendix A):

Mmin =

max((|PG (x) PS (x)|), (|PG (y) PS (y)|))me


PN e
e=1 me

(B.1)

This is correct, because Van den Goor uses number of elements as


the definition for the path length. However, since we will be using
Euclidian distance in this article, we will use the form of Equation 2.19.
3. A path length calculation using Euclidian distance has been added,
see lines 169-212 in Appendix B
4. For almost every case in Section 4 the value of Mmin is adapted manually in order to achieve a correct path. More on this in Sections 4 and
5.
31

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51

%%%% AN 88 LINE ROBOT PATH OPTIMIZATION CODE July, 2012 %%%%


function [obj vol path timeTOM] = ...
top88r adapt(nelx,nely,nc,rmin,fast,Mn,MAP)
tic
ft=1;
obsx=[];
obsy=[];
sourcepos=[];
sinkpos=[];
mapsize=size(MAP);
for i=1:mapsize(1)
for j=1:mapsize(2)
if MAP(i,j)==1
obsx=[obsx i];
obsy=[obsy j];
elseif MAP(i,j)==3
sourcepos=[sourcepos j1 i1];
elseif MAP(i,j)==4
sinkpos=[sinkpos j i];
end
end
end
%% MATERIAL PROPERTIES
E0 = 1;
Emin = 1e9;
%% PREPARE FINITE ELEMENT ANALYSIS
KE = [ 2/3 1/6 1/3 1/6
1/6 2/3 1/6 1/3
1/3 1/6 2/3 1/6
1/6 1/3 1/6 2/3];
nodenrs = reshape(1:(1+nelx)*(1+nely),1+nely,1+nelx);
edofVec = reshape(nodenrs(1:end1,1:end1),nelx*nely,1);
edofMat = repmat(edofVec,1,4)+repmat([0 nely+[1 2] ...
1],nelx*nely,1);
iK = reshape(kron(edofMat,ones(4,1))',16*nelx*nely,1);
jK = reshape(kron(edofMat,ones(1,4))',16*nelx*nely,1);
% DEFINE LOADS AND SUPPORTS
F = sparse((nely+1)*(nelx+1),1);
% Conduction force
iF = 0.01;
F(:,1)=iF;
for a=1:numel(obsx)
F((obsy(a)1)*(nely+1)+obsx(a),1)=0;
end
% Robot end points
qv=sqrt(nelx*nely)/10; %Arbitrary convection component
for i=1:numel(sinkpos)/2
nodes = [1 0 nely nely1] + ((nely+1)*sinkpos(2*i1) + ...
sinkpos(2*i));
F(nodes,1)=iF+qv;
end
U = zeros((nely+1)*(nelx+1),1);
fixeddofs=[];
for i=1:numel(sourcepos)/2

32

52

53

54

55

56
57
58
59
60
61
62
63
64
65
66
67

68

69
70
71
72
73
74
75
76
77
78
79
80
81

fixeddofs = [fixeddofs ...


(nely+1)*sourcepos(2*i1)+sourcepos(2*i)+2];
fixeddofs = [fixeddofs ...
nely+1+(nely+1)*sourcepos(2*i1)+sourcepos(2*i)+2];
fixeddofs = [fixeddofs ...
(nely+1)*sourcepos(2*i1)+sourcepos(2*i)+1];
fixeddofs = [fixeddofs ...
nely+1+(nely+1)*sourcepos(2*i1)+sourcepos(2*i)+1];
end
alldofs = [1:(nely+1)*(nelx+1)];
freedofs = setdiff(alldofs,fixeddofs);
%% PREPARE FILTER
iH = ones(nelx*nely*(2*(ceil(rmin)1)+1)2,1);
jH = ones(size(iH));
sH = zeros(size(iH));
k = 0;
for i1 = 1:nelx
for j1 = 1:nely
e1 = (i11)*nely+j1;
for i2 = ...
max(i1(ceil(rmin)1),1):min(i1+(ceil(rmin)1),nelx)
for j2 = ...
max(j1(ceil(rmin)1),1):min(j1+(ceil(rmin)1),nely)
e2 = (i21)*nely+j2;
k = k+1;
iH(k) = e1;
jH(k) = e2;
sH(k) = max(0,rminsqrt((i1i2)2+(j1j2)2));
end
end
end
end
H = sparse(iH,jH,sH);
Hs = sum(H,2);
%% INITIALIZE ITERATION
me=1/nelx/nely;

82
83

Mmin = ...
me*sqrt((sinkpos(1)sourcepos(1))2+(sinkpos(2)sourcepos(2))2);

84
85
86
87
88
89
90
91
92
93
94
95
96

x = ones(nely,nelx);
xPhys = x;
loop = 0;
change = 1;
obj = []; vol = [];
cold=0; % Old objectivity function value
conv count=0; % Number of consecutive convergences
%% START ITERATION
while change > 0.01
loop = loop + 1;
%% CALCULATE ALLOWED MASS
z=1/(loop2); % z=1/loop2 for large maps

97
98

Mn=max(z,Mmin);

33

99
100
101
102
103
104
105
106

107
108
109
110
111
112

%% FEANALYSIS
if (loop <= nc)
penal = 1;
else
penal = min(3,1+0.1*(loop10));
end
sK = ...
reshape(KE(:)*(Emin+0.001+0.999*xPhys(:)'.penal*(E0Emin)),16*nelx*nely,1);
K = sparse(iK,jK,sK); K = (K+K')/2;
U(freedofs) = K(freedofs,freedofs)\F(freedofs);
%% OBJECTIVE FUNCTION AND SENSITIVITY ANALYSIS
ce = reshape(sum((U(edofMat)*KE).*U(edofMat),2),nely,nelx);
c = sum(sum((Emin+0.001+0.999*xPhys.penal*(E0Emin)).*ce));
dc = 0.999*penal*(E0Emin)*xPhys.(penal1).*ce;

113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142

143
144
145
146
147
148

dv = ones(nely,nelx);
%% FILTERING/MODIFICATION OF SENSITIVITIES
if ft == 1
dc(:) = H*(x(:).*dc(:))./Hs./max(1e3,x(:));
elseif ft == 2
dc(:) = H*(dc(:)./Hs);
dv(:) = H*(dv(:)./Hs);
end
%% OPTIMALITY CRITERIA UPDATE OF DESIGN VARIABLES AND ...
PHYSICAL DENSITIES
l1 = 0.1; l2 = 1e9; move = 0.2;
cnt = 0;
while (l2l1)/(l1+l2) > 1e3
cnt = cnt+1;
if (cnt>1000)
fprintf('Terminate iteration...\n');
obj = []; vol = [];
return
end
lmid = 0.5*(l2+l1);
xnew = ...
max(0,max(xmove,min(1,min(x+move,x.*sqrt(dc./dv/lmid)))));
for a=1:numel(obsx)
xnew(obsx(a),obsy(a))=0;
end
if ft == 1
xPhys = xnew;
elseif ft == 2
xPhys(:) = (H*xnew(:))./Hs;
end
if sum(xPhys(:)) > Mn*nelx*nely, l1 = lmid; else l2 = ...
lmid; end
end
change = max(abs(xnew(:)x(:)));
x = xnew;
obj=[obj c];
vol=[vol mean(xPhys(:))];
if (abs(ccold)/abs(c))<=0.01, conv count=conv count+1;

34

149
150
151
152
153
154

else conv count = 0;end


if (loop>3 && conv count >=3)
fprintf('Convergence, cn = %f, cn1 = %f\n',c,cold)
change = 0;
end
cold = c;

155
156
157
158

159
160
161

162
163
164

%% PRINT RESULTS
if(fast | | change <= 0.01)
fprintf(' It.:%5i Obj.:%11.4f Vol.:%7.3f ...
ch.:%7.3f\n',loop,c, mean(xPhys(:)),change);
%% PLOT DENSITIES
if change<= 0.01, xPhys=round(xPhys);path = xPhys; end
imagesc(xPhys+0.25*MAP); caxis([0 1]); axis equal; ...
axis off; drawnow;
end
end
timeTOM=toc;

165
166
167
168
169
170
171
172
173
174
175
176
177
178

179
180
181

182
183
184

185
186
187
188
189

190

191

192

193

% Path length calculation


[r,c] = find(path);
path coordinates = [r c];
current(1) = sourcepos(2)+1;
current(2) = sourcepos(1)+1;
sorted path(1,1) = sourcepos(2)+1;
sorted path(1,2) = sourcepos(1)+1;
closedlist = [];
for g = 1:size(path coordinates,1)
for h = 1:size(path coordinates,1)
for i = 1:1:1
for j = 1:1:1
if (i = j | | i = 0) %the node can't be its ...
own successor
node x = current(1)+i;
node y = current(2)+j;
if ((node x == path coordinates(h,1)) && ...
(node y == path coordinates(h,2)))
check = 1;
for k = 1:size(closedlist)
if (node x == closedlist(k,1)) && ...
node y == closedlist(k,2)
check = 0;
end
end
if (check == 1)
sorted path((g+1),1) = ...
path coordinates(h,1);
sorted path((g+1),2) = ...
path coordinates(h,2);
closedlist(g,1) = ...
path coordinates(h,1);
closedlist(g,2) = ...
path coordinates(h,2);
end

35

end

194

end

195

end

196

end

197

end
current = sorted path(g+1,:);

198
199
200

end

201
202
203
204

sorted path(g+2,1) = sinkpos(2);


sorted path(g+2,2) = sinkpos(1);

205
206
207
208

209
210

pathlength TopOpt = 0;
for i = 1:(size(sorted path,1)1)
pathlength TopOpt = pathlength TopOpt + ...
distance(sorted path(i,1),sorted path(i,2),...
sorted path((i+1),1),sorted path((i+1),2));
end

211
212
213

title('Topography Optimization Algorithm Path')


fprintf('\n Time taken TopOpt: %4.3f Average time/iteration ...
TopOpt: %4.4f \n Path length TopOpt: %4.5f Number of ...
iterations TopOpt: %4.5f \n ...
',timeTOM,timeTOM/loop,pathlength TopOpt,loop);

214
215

end

36

Appendix C

A* Matlab code including


subfunctions

1
2
3
4
5
6
7
8
9
10

%% An Astar algorithm for Robotpath planning, September 2012 %%


function [timeAstar] = Astar(MAP,fast,heuristic)
clearvars except MAP fast heuristic
tic %start time
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A* ALGORITHM Demo
% Interactive A* search demo
% 04262005
%
Copyright 20092010 The MathWorks, Inc.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%LISTS USED FOR ALGORITHM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%OPEN LIST STRUCTURE
%
%IS ON LIST 1/0 | X val | Y val | Parent X val | Parent Y val ...
| h(n) | g(n) | f(n) |
%
OPEN=[];
%CLOSED LIST STRUCTURE
%
%X val | Y val |
%
% CLOSED=zeros(MAX VAL,2);
CLOSED=[];

27
28
29
30
31

%SUCCESSOR LIST STRUCTURE


%
% | X val | Y val | | h(n) | g(n) | f(n) |
%

32

37

33
34

%% Read map and add obstacles to closed list


% Space=0, Obstacle=1, Start=3, Target = 4

35
36
37
38
39

MAX X=size(MAP,1);
MAX Y=size(MAP,2);

40
41
42
43
44
45
46
47
48
49
50
51
52
53

k = 1;
for i=1:MAX X
for j=1:MAX Y
if(MAP(i,j) == 1)
CLOSED(k,1)=i;
CLOSED(k,2)=j;
k=k+1;
elseif (MAP(i,j) == 3)
xStart=i;%Starting Position
yStart=j;%Starting Position
elseif(MAP(i,j) == 4)
xTarget=i;%X Coordinate of the Target
yTarget=j;%Y Coordinate of the Target

54

end

55

end

56
57

end

58
59

CLOSED count = size(CLOSED,1);

60
61
62
63
64
65
66
67
68
69
70
71
72
73

%% Set 'Start' as first node


%add start node to open list
xpos = xStart;
ypos = yStart;
g cost = 0; %distance to itself is zero
OPEN count = 1;
OPEN(OPEN count,:) = [1, xpos, ypos, xpos, ypos,g cost,...
distance(xStart,xTarget,yStart,yTarget),distance(xStart,xTarget,yStart,yTarget)];
%remove start node from open list
OPEN(OPEN count,1) = 0;
CLOSED count = CLOSED count + 1;
CLOSED(CLOSED count,1) = xpos;
CLOSED(CLOSED count,2) = ypos;

74
75
76
77
78
79
80

81

loop = 0;
NoPathFound = 1;
%% Forward Path Construction Loop
while ((xpos = xTarget | | ypos = yTarget) && NoPathFound == 1)
loop = loop+1;
successorlist = ...
successors(xpos,ypos,xTarget,yTarget,g cost,CLOSED,MAX X,MAX Y,heuristic);
num succesors = size(successorlist,1);

82
83

84

%Start check if one of the successors is already in the ...


open list
for i = 1:num succesors %go through all successors

38

check = 0; %presume that node is not already in open list


for j = 1:OPEN count %go through all entries in the ...
open list
if ((successorlist(i,1) == OPEN(j,2)) && ...
(successorlist(i,2) == OPEN(j,3))) %check if ...
position of successor is the same as the one ...
in the open list
OPEN(j,8) = min(OPEN(j,8),successorlist(i,5)); ...
%change the f(n) score to the lowest of ...
the two
if (OPEN(j,8) == successorlist(i,5)) %if entry ...
in list is renewed, replace g(n) and h(n) ...
scores and parent coordinates
OPEN(j,4) = xpos;
OPEN(j,5) = ypos;
OPEN(j,6) = successorlist(i,3);
OPEN(j,7) = successorlist(i,4);
end %end of entry replacements
check = 1; %The node was already in open list ...
and has now been adapted
end %end of same coordinate check
end
if (check == 0) %The node was not already in the open list
OPEN count = OPEN count + 1; %One node is going to ...
be added to the open list
OPEN(OPEN count,:) = [1 successorlist(i,1) ...
successorlist(i,2) xpos ypos ...
successorlist(i,3) successorlist(i,4) ...
successorlist(i,5)]; %add node to open list
end
end %All successors that are not in the closed list have ...
been added or updated in the open list

85
86

87

88

89

90
91
92
93
94
95

96
97
98
99

100

101
102

103

%Find the node with lowest f(n) score in the open list
index min = min fn(OPEN,OPEN count,xTarget,yTarget); ...
%returns the index of the node in the open list with ...
the lowest f(n) score

104
105

106

if (index min = 1) %this means that there still is a path


%Change the current node to the one with lowest f(n) score
xpos = OPEN(index min,2);
ypos = OPEN(index min,3);
g cost = OPEN(index min,6);

107
108
109
110
111
112

%Remove current node from open list and add it to ...


closed list
CLOSED count = CLOSED count +1;
CLOSED(CLOSED count,1) = xpos;
CLOSED(CLOSED count,2) = ypos;
OPEN(index min,1) = 0;

113

114
115
116
117

else

118

NoPathFound = 0; %There is no path possible to the target!

119

end

120
121

end

39

122
123
124

125

126

%% Backward optimal path construction loop


%Once algorithm has run The optimal path is generated by ...
starting of at the
%last node(if it is the target node) and then identifying its ...
parent node
%until it reaches the start node.This is the optimal path

127
128
129
130
131
132
133
134
135

i=size(CLOSED,1);
Optimal path=[];
xpos=CLOSED(i,1);
ypos=CLOSED(i,2);
i=1;
Optimal path(i,1)=xpos;
Optimal path(i,2)=ypos;
i=i+1;

136
137
138
139
140

141

if ( (xpos == xTarget) && (ypos == yTarget))


inode=node index(OPEN,xpos,ypos);
%Traverse OPEN and determine the parent nodes
parent x=OPEN(inode,4);%node index returns the index of ...
the node
parent y=OPEN(inode,5);

142
143
144
145
146
147
148

149
150
151
152
153

while( parent x = xStart | | parent y = yStart)


Optimal path(i,1) = parent x;
Optimal path(i,2) = parent y;
%Get the grandparents:)
inode=node index(OPEN,parent x,parent y);
parent x=OPEN(inode,4);%node index returns the index ...
of the node
parent y=OPEN(inode,5);
i=i+1;
end
Optimal path(i,1) = xStart;
Optimal path(i,2) = yStart;

154
155
156
157
158
159
160
161
162
163
164
165
166
167

timeAstar = toc; %stop time


%% Visualization
visual path = [MAP];
for a = 1: size(OPEN,1)
if OPEN(a,1) == 1
visual path(OPEN(a,2),OPEN(a,3)) = 1.5;
end
end
for b = 1: size(CLOSED,1)
visual path(CLOSED(b,1),CLOSED(b,2)) = 2.5;
end
for i = size(Optimal path,1):1:1
visual path(Optimal path(i,1),Optimal path(i,2)) = 4;

168
169
170

if ((fast = 1) | | (i == 1))
imagesc(visual path+0.25*MAP); caxis([0 4]); axis ...
equal; axis off; drawnow;

40

end

171

end

172
173

%% Path length calculation


pathlength = 0;

174
175
176

for i = 1:(size(Optimal path,1)1)


pathlength = pathlength + distance(Optimal path(i,1),...
Optimal path(i,2),Optimal path((i+1),1),Optimal path((i+1),2));
end

177
178
179
180
181

if heuristic == 0
fprintf('\n Time taken Astar Dijkstra: %4.3f Average ...
time/iteration Astar: %4.4f \n Path length: %4.5f ...
Number of iterations: %4.5f \n ...
',timeAstar,timeAstar/loop,pathlength,loop);
title('Astar Dijkstra Algorithm Path')

182
183

184
185

elseif heuristic == 1
fprintf('\n Time taken Astar Straight: %4.3f Average ...
time/iteration Astar: %4.4f \n Path length: %4.5f ...
Number of iterations: %4.5f \n ...
',timeAstar,timeAstar/loop,pathlength,loop);
title('Astar Straight Algorithm Path')

186
187

188
189

elseif heuristic == 2
fprintf('\n Time taken Astar Manhattan: %4.3f Average ...
time/iteration Astar: %4.4f \n Path length: %4.5f ...
Number of iterations: %4.5f \n ...
',timeAstar,timeAstar/loop,pathlength,loop);
title('Astar Manhattan Algorithm Path')

190
191

192
193

elseif heuristic == 3
fprintf('\n Time taken Astar Diagonal: %4.3f Average ...
time/iteration Astar: %4.4f \n Path length: %4.5f ...
Number of iterations: %4.5f \n ...
',timeAstar,timeAstar/loop,pathlength,loop);
title('Astar Diagonal Algorithm Path')
end

194
195

196
197
198
199
200

else
fprintf('No path to target possible!')

201
202

end

203
204
205

1
2
3
4

end

function dist = distance(x1,y1,x2,y2)


%This function calculates the distance between any two cartesian
%coordinates.
%
Copyright 20092010 The MathWorks, Inc.

41

dist=sqrt((x1x2)2 + (y1y2)2);

function successorlist = ...


successors(xpos,ypos,xTarget,yTarget,gparent, CLOSED, ...
MAX X,MAX Y,heuristic)
% This function creates a list of successors of the node and ...
their fn values
s = size(CLOSED,1);
successorlist = [];
p = 1.0;
count = 1;
for i = 1:1:1
for j = 1:1:1
if (i = j | | i = 0) %the node can't be its own successor
node x = xpos+i;
node y = ypos+j;
if ((node x > 0 && node x <= MAX X) && (node y > 0 ...
&& node y <= MAX Y)) %check if node is in domain
check = 1;
for k = 1:s
if ((node x == CLOSED(k,1)) && node y == ...
CLOSED(k,2))
check = 0;
end
end
if (check == 1) %Add the successor to the ...
successorlist with all info
successorlist(count,1) = node x;
successorlist(count,2) = node y;
successorlist(count,3) = gparent + ...
distance(node x,node y,xpos,ypos); %gn ...
= path cost
if heuristic == 0 %Dijkstra's algorithm
successorlist(count,4) = 0; %hn = ...
distance to goal
elseif heuristic == 1% Straight line (or ...
Euclidian) heuristic
successorlist(count,4) = ...
distance(node x,node y,xTarget,yTarget); ...
%hn = distance to goal
elseif heuristic == 2 %Manhattan heuristic
successorlist(count,4) = ...
abs(node xxTarget)+abs(node yyTarget); ...
%hn = distance to goal
elseif heuristic == 3 %Diagonal heuristic
h diag = ...
min(abs(node xxTarget),abs(node yyTarget));
h manhattan = ...
abs(node xxTarget)+abs(node yyTarget);
successorlist(count,4) = ...
sqrt(2)* h diag + (h manhattan ...
2* h diag); %hn = distance to goal

3
4
5
6
7
8
9
10
11
12

13
14
15

16
17
18
19

20
21
22

23
24

25

26

27
28

29
30

31

32

42

end

33
34

successorlist(count,5) = ...
successorlist(count,3)+successorlist(count,4)*p; ...
%fn = gn+hn
count = count+1;

35

36
37

end

38

end

39

end

40

end

41
42
43

1
2
3

4
5
6

end
end

function i min = min fn(OPEN,OPEN COUNT,xTarget,yTarget)


%Function to return the Node with minimum fn
% This function takes the list OPEN as its input and returns ...
the index of the
% node that has the least cost
%
%
Copyright 20092010 The MathWorks, Inc.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27

28

29
30

31

temp array=[];
k=1;
flag=0;
goal index=0;
for j=1:OPEN COUNT
if (OPEN(j,1)==1)
temp array(k,:)=[OPEN(j,:) j]; %#ok<*AGROW>
if (OPEN(j,2)==xTarget && OPEN(j,3)==yTarget)
flag=1;
goal index=j;%Store the index of the goal node
end;
k=k+1;
end;
end;%Get all nodes that are on the list open
if flag == 1 % one of the successors is the goal node so send ...
this node
i min=goal index;
end
%Send the index of the smallest node
if size(temp array = 0)
[min fn,temp min]=min(temp array(:,8));%Index of the ...
smallest node in temp array
i min=temp array(temp min,9);%Index of the smallest node in ...
the OPEN array
else
i min=1;%The temp array is empty i.e No more paths are ...
available.
end;

43

1
2

3
4
5
6
7
8
9
10
11

function n index = node index(OPEN,xval,yval)


%This function returns the index of the location of a node ...
in the list
%OPEN
%
%
Copyright 20092010 The MathWorks, Inc.
i=1;
while(OPEN(i,2) = xval | | OPEN(i,3) = yval )
i=i+1;
end;
n index=i;
end

44

Appendix D

Map Editor

1
2
3
4
5
6
7
8
9
10

function map edit stopover


clc; clear all; close all;
% GUI for robot pathplanner based on topology optimization
m= 10; n= 10; % Define map size
mousedown=0;
rightbutton=0;
material=1;
Map=zeros(n,m);
Map(1,1)=3; % Starting point
Map(n,m)=4; % End point

11
12
13
14

15

16

17

18

19

20

21

22

23

24

pos=[1;1];
filename=''; pathname=''; file='';
fig = figure(); set(fig,'name','Robot Map ...
editor','numbertitle','off','Position',[600 300 700 550]);
uicontrol('String','Obstacle','Position', [3 90 60 30], ...
'Callback',{@mat,1})
uicontrol('String','Free','Position', [3 60 60 30], ...
'Callback',{@mat,0})
uicontrol('String','Start','Position', [3 30 60 30], ...
'Callback',{@mat,3})
uicontrol('String','Goal','Position', [3 0 60 30], ...
'Callback',{@mat,4})
uicontrol('String','Go','Position', [3 150 60 ...
30],'Callback',@press go)
its = uicontrol('Style', ...
'slider','Min',1,'Max',50,'Value',1,'SliderStep',[1/49 ...
1/49],'Position', [63 370 60 30],'Callback',@displayits);
uicontrol('Style','text','Position',[63 415 60 ...
15],'String','Iterations')
uicontrol('Style','text','Position',[63 400 60 ...
15],'String',get(its,'value'))
stopover = uicontrol('Style','checkbox','String','Stop ...
Over','Position',[63 440 70 30],'Callback',@stops);
quick = ...
uicontrol('Style','checkbox','String','Quick','Position',[3 ...

45

25

26

27

28

29

30

31

32
33
34
35
36

400 60 30]);
astar = ...
uicontrol('Style','checkbox','String','A*','Fontsize',10,'Position',[3 ...
370 60 30],'Callback',@heuristics);
TopOpt = ...
uicontrol('Style','checkbox','String','TopOpt','Fontsize',10,'Position',[3 ...
210 100 30]);
Subplots = ...
uicontrol('Style','checkbox','String','Subplot','Position',[3 ...
180 60 30]);
uicontrol('String','Reset','Position', [3 440 60 30], ...
'Callback',@reset map)
uicontrol('String','Load','Position', [3 500 60 30], ...
'Callback',@load map)
uicontrol('String','Load Mesh','Position', [63 500 70 30], ...
'Callback',@load map mesh)
uicontrol('String','Save','Position', [3 470 60 30], ...
'Callback',@save map)
editor = imagesc(Map);
caxis([0 4]); axis equal; axis off; drawnow;
set(editor,'ButtonDownFcn', @startDrawing);
set(fig,'WindowButtonUpFcn', @stopDrawing);
set(fig,'WindowButtonMotionFcn',@mouseMovement);

37
38
39

40

function displayits(,)
uicontrol('Style','text','Position',[63 400 60 ...
15],'String',get(its,'value'))
end

41
42
43
44

45

46

47

48
49
50

51
52
53
54

function heuristics(,,)
if get(astar,'value') == 1
uicontrol('Style','checkbox','String','Dijkstra','Position',[3 ...
340 100 30]);
uicontrol('Style','checkbox','String','Straight ...
Line','Position',[3 310 100 30]);
uicontrol('Style','checkbox','String','Manhattan','Position',[3 ...
280 100 30]);
uicontrol('Style','checkbox','String','Diagonal','Position',[3 ...
250 100 30]);
else
delete(findobj('Style','checkbox','String','Dijkstra'))
delete(findobj('Style','checkbox','String','Straight ...
Line'))
delete(findobj('Style','checkbox','String','Manhattan'))
delete(findobj('Style','checkbox','String','Diagonal'))
end
end

55
56
57
58

59
60

function stops(,,)
if get(stopover,'value') == 1
uicontrol('String','Stop','Position', [63 90 60 ...
30], 'Callback',{@mat,2})
else
delete(findobj('String','Stop'))

46

end

61
62

end

63
64
65

function mat(,,m), material = m;


end

66
67
68

69

70

71

72
73

74

function press go(a,b)


dijkstra = ...
get(findobj('Style','checkbox','String','Dijkstra'),'value');
straight = ...
get(findobj('Style','checkbox','String','Straight ...
Line'),'value');
Manhattan = ...
get(findobj('Style','checkbox','String','Manhattan'),'value');
diagonal = ...
get(findobj('Style','checkbox','String','Diagonal'),'value');
topopt = get(TopOpt,'value');
number subplots = ...
dijkstra+straight+Manhattan+diagonal+topopt;
subplots = get(Subplots,'value');

75
76
77
78
79

80
81

for a = 1:1:round(get(its,'value'))
if subplots == 1
figure()
set(gcf, 'Position', get(0,'Screensize')); % ...
Maximize figure
i = 1;
end

82
83
84
85
86
87
88
89
90
91
92

93
94

95
96

if dijkstra == 1
if subplots == 1
subplot(2,round(number subplots/2),i)
i = i+1;
else
figure
end
heuristic = 0;
if get(stopover,'value') == 1
[tAstar] = ...
Astar stopover(Map,get(quick,'value'),heuristic);
else
[tAstar] = ...
Astar(Map,get(quick,'value'),heuristic);
end
end

97
98
99
100
101
102
103
104
105

if straight == 1
if subplots == 1
subplot(2,round(number subplots/2),i)
i = i+1;
else
figure
end
heuristic = 1;

47

if get(stopover,'value') == 1
[tAstar] = ...
Astar stopover(Map,get(quick,'value'),heuristic);
else
[tAstar] = ...
Astar(Map,get(quick,'value'),heuristic);
end

106
107

108
109

110
111

end

112
113
114
115
116
117
118
119
120
121
122

123
124

125
126

if Manhattan == 1
if subplots == 1
subplot(2,round(number subplots/2),i)
i = i+1;
else
figure
end
heuristic = 2;
if get(stopover,'value') == 1
[tAstar] = ...
Astar stopover(Map,get(quick,'value'),heuristic);
else
[tAstar] = ...
Astar(Map,get(quick,'value'),heuristic);
end
end

127
128
129
130
131
132
133
134
135
136
137

138
139

140
141

if diagonal == 1
if subplots == 1
subplot(2,round(number subplots/2),i)
i = i+1;
else
figure
end
heuristic = 3;
if get(stopover,'value') == 1
[tAstar, film] = ...
Astar stopover(Map,get(quick,'value'),heuristic);
else
[tAstar, film] = ...
Astar film(Map,get(quick,'value'),heuristic);
end
end

142
143
144
145
146
147
148
149
150

151

if topopt == 1
if subplots == 1
subplot(2,round(number subplots/2),i)
i = i+1;
else
figure
end
[obj vol rpath timeTOP] = ...
top88r adapt(m,n,10,1.1,get(quick,'value'),2/(m+n),Map);
end

152

48

if get(astar,'value') == 1
times Astar(a) = tAstar;
end
if topopt == 1
times TOP(a) = timeTOP;
end

153
154
155
156
157
158

end

159
160

if topopt == 1
averageTOM = sum(times TOP)/size(times TOP,2);
fprintf('\n Average Time taken TopOpt: %4.3f ...
\n',averageTOM);
end

161
162
163

164
165

if get(astar,'value') == 1
averageAstar = sum(times Astar)/size(times Astar,2);
fprintf('\n Average Time taken Astar: %4.3f ...
\n',averageAstar);
end

166
167
168

169
170
171
172
173

end

174
175
176
177
178
179
180
181
182

function reset map(a,b)


Map=zeros(n,m);
Map(1,1)=3;
Map(n,m)=4;
pos=[1;1];
set(editor,'cdata',Map);
axis equal;
end

183
184
185
186
187
188
189

function save map(object,eventStruct)


[filename,pathname] = uiputfile('.map');
file=[pathname,filename];
if file==0,return; end
dlmwrite(file,Map);
end

190
191
192

function load map(object,eventStruct)


[filename,pathname] = uigetfile('.map');

193
194
195
196
197
198
199
200
201
202
203
204

file=[pathname,filename];
if file==0,return; end
if (exist(file))
Map = dlmread(file);
mapdim=size(Map);
m=mapdim(2)
n=mapdim(1)
set(editor,'cdata',Map);
axis equal;
else
fprintf('%s does not exist.\n',filename)

49

end

205
206

end

207
208
209
210
211
212

function load map mesh(object,eventStruct)


[filename,pathname] = uigetfile('.map');
options.Resize='on';
options.WindowStyle='normal';
factor = str2double(inputdlg('Enter mesh refinement ...
factor','Mesh refinement',1,{'2'},options));

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

228
229
230
231

232
233

234
235

236
237
238

file=[pathname,filename];
if file==0,return; end
if (exist(file))
oldmap = dlmread(file);
mapdim=factor*size(oldmap);
n=mapdim(2)
m=mapdim(1)
Map = zeros(m,n);
for i=1:(m/factor)
for j=1:(n/factor)
if(oldmap(i,j) == 1)
for k = 1:1:(factor)
for l = 1:1:(factor)
Map(factor*i(k1),factor*j(l1)) ...
= 1;
end
end
elseif (oldmap(i,j) == 3)
Map(factor*i(factor1),factor*j(factor1)) ...
= 3;
elseif(oldmap(i,j) == 4)
Map(factor*i(factor1),factor*j(factor1)) ...
= 4;
elseif(oldmap(i,j) == 2)
Map(factor*i(factor1),factor*(factor1)) ...
= 2;
end
end
end

239

set(editor,'cdata',Map);
axis equal;

240
241
242

else
fprintf('%s does not exist.\n',filename)

243
244
245
246
247
248
249
250
251
252
253

end
end
function mouseMovement(object,eventStruct)
pos1 = get(gca,'CurrentPoint');
% Determine the mouseposition
pos = [ pos1(1,1)0.5;
pos1(1,2)0.5];
if (mousedown)
x=pos(1);
y=pos(2);

50

if (x>0 && x<m && y>0 && y<n)


if (rightbutton)
Map(ceil(y),ceil(x))=0;
else
Map(ceil(y),ceil(x))=material;
end
set(editor,'cdata',Map);
end

254
255
256
257
258
259
260
261

end

262
263

end

264
265
266
267

268
269
270

function startDrawing(object,eventStruct)
mousedown = 1; rightbutton = 0;
if strcmp(get(fig,'SelectionType'),'alt'),rightbutton ...
= 1;
end
mouseMovement(object,eventStruct)
end

271
272
273

function stopDrawing(object,eventStruct), mousedown = 0;


end

274
275
276
277
278
279
280
281
282
283

284

285
286
287
288
289
290

291

292
293

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This Matlab code was written by V.J.P. van den Goor, %
% And adapted by A.R.P. Andri n to include the A* algorithm,%
% stopovers, subplots, multiple iterations and load mesh%
% Department of Mechanical Engineering, %
% Eindhoven University of Technology %
% %
% The code is intended for educational purposes and acts as a ...
GUI for %
% the robot pathplanner program of which theoretical details ...
are %
% discussed in the paper %
% "Trajectorieplanning van een mobiele robot met behulp van %
% topologieoptimalisering", Reportnumber: MN420694 %
% %
% Disclaimer: %
% The authors reserves all rights but do not guaranty that the ...
code is %
% free from errors. Furthermore, we shall not be liable in any ...
event %
% caused by the use of the program. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

51

Appendix E

Cases with increasing mesh


renement
E.1

Case 1: 80x80 (6x6 m)

(a) A*

(b) TOM

Figure E.1: Case 1

52

E.2

Case 2: 120x120 (9x9 m)

(a) A*

(b) TOM

Figure E.2: Case 2

E.3

Case 3: 160x160 (12x12 m)

(a) A*

(b) TOM

Figure E.3: Case 3

53

E.4

Case 4: 200x200 (15x15 m)

(a) A*

(b) TOM

Figure E.4: Case 4

E.5

Case 5: 240x240 (18x18 m)

(a) A*

(b) TOM

Figure E.5: Case 5

54