You are on page 1of 7

A contribution to solving the traveling salesman

problem using ant colony optimization and web
mapping platforms
Application to logistics in a urban context
Ahmed Haroun SABRY, Abdelkabir Bacha, Jamal BENHRA
EAP Team, LISER laboratory, ENSEM
KM7, BP 8118 Route El Jadida
Casablanca, Morocco
Abstract— This article presents an easy to use system for
solving the traveling salesman problem in a urban context, it uses
an ant colony optimization metaheuristic for solving the
combinatorial problem. The system assists the user to formulate,
manage and rapidly solve complicated instances of the routing
problem, delivering optimum or near-optimum solutions that can
be used for improving the quality of modern urban
transportation systems. The proposed model is simple and
scalable and integrates a spatial data management service to
communicate with the web mapping platform to be chosen. The
system integrates Bing maps™ (Imagery and geographic network
data) and an efficient ant colony optimization metaheuristic. It
was tested with a moderately large instance of the problem in the
complex urban environment of the city of Casablanca, Morocco.
optimization; Web mapping platforms;






Modern web mapping platforms offer a range of practical
features with particular emphasis on imagery, navigation,
geocoding and other location-based applications. They offer
very resourceful routing services that play a key role in the
decision making process of many individuals . More precisely
their point to point routes are rich in valuable and up to date
data that can be used to develop new prototypes designed for
solving more scalable and strategic problems. A good example
is the traveling salesman problem in an urban context. Where
the problem complexity adds -up to the richness of the
metropolitan environment to form a more pertinent problematic
with direct impact on traffic congestion, air pollution, energy
consumption, sustainability of public services and the
efficiency of transportation systems and delivery companies
Given a set of locations in a map, the traveling salesman
problem (TSP) consists of finding a minimum length tour that
visits each location exactly once. Due to its complexity, its
large set of applications (and maybe its exotic name) this NPhard problem is one of the most studied problems in
combinatorial optimization [1]. Real world instances of the
978-1-4799-6773-5/14/$31.00 ©2014 IEEE

TSP like the one we are discussing may have a number of
locations that is far beyond the capabilities of any exact
algorithm available today. Ant colony optimization (ACO) and
other nature-inspired approaches have demonstrated
effectiveness in solving large instances of famous combinatory
optimization problems like the TSP, providing near-optimum
or optimum solutions in a considerably reasonable time [2].
However, many companies and groups of individuals
interested in solving everyday navigation problems, cannot
access the power of modern metaheuristics like the ACO. In
the present work we are providing a route optimization model
for finding the shortest possible trip over a set of locations and
projecting the solution over easy-to-use and functional
mapping software.
The present paper is organized as follow: chapter 1 details
the problem background and dresses a state of the art, chapter 2
presents our proposed model, the architecture and algorithmic
approach, chapter 3 discusses the results, finally chapter 4
concludes this work.
Recent developments in computing and openly available
geographical data have provided new opportunities for
developing navigation planning tools and navigation decision
support systems [3]. Modern Geographical Information
Systems (GIS) like the ones behind Google maps™ and Bing
maps™ services use local search algorithms variants to finding
point-to-point routes [4]. Metaheuristics have also
demonstrated efficiency in providing good routes in reasonable
times but their effectiveness diminishes and the runtime
increases with the number of nodes [5].
Real world implementations of the TSP (with actual routes
on interactive maps) are omnipresent in our everyday life with
applications ranging from health systems [6] to logistics [7] or
tourist trip planning [8][9]. Consequently, editable instances of
the problem should be more accessible through easy-to-use
GIS, via their web mapping platforms or third party tools.

When trying to create these instances , the user notices that
a route from location A to B is usually different than B to A,
mainly because of traffic flows and road configuration. The
GIS model this complex road data as geometric networks
similar to directed weighted graphs [10]. The TSP is here
asymmetric (ATSP), and with a time complexity of O(n!) even
instances of 20 locations become insolvable without the help
of effective algorithms [11].
L. Santos and al. proposed with the help of Google maps™
a decision support system to assist the user in the creation of a
vehicle routing problem, with saving and editing possibilities,
the problem is then subject to an ACO implementation to solve
pickup or delivery problems [12], the model proposed is
efficient in formulating the problem but the process is not fully
automated and the user has to manually input a set of arcs that
constitute the graph, this served as a motivation for us to
develop a new tool based on an improved model aimed to
retrieve automatically data over a web service and use it for
solving the TSP with ACO.
The choice of ACO is deliberate, in combinatorial
optimization, ACO outperforms a number of other natureinspired approaches like simulated annealing and evolutionary
algorithms, the analogy between the ants foraging behavior and
the traveling salesmen, seeking both to minimize paths, makes
the ACO a perfect fit to handle the TSP [1][13].
ACO’s ants or agents search in parallel for good solutions
to the TSP, to achieve this, they cooperate through global
indirect communication. Informally, each agent builds a
solution iteratively: it adds new locations to a partial solution
while exploring the problem’s graph, the choice of the next
location to be visited is gained from past experience and a
greedy heuristic [2]. Next chapter presents the details of our
GIS based tool for solving the TSP using the ACO.
This chapter presents the steps taken in order to develop our
solution detailing aspects like the choice of the web mapping

platform suitable for our urban context, the creation of a global
model for our solution, the formatting of data to be provided
(raw geographical nets, asymmetric graphs or simply d ata
matrixes), and finally the algorithmic approach.
The solution defines two user roles, the first user is
concerned with finding the shortest tour between a set of
locations in a city or a region, considering he’s in charge of
picking up or delivering goods or services, this user has no
interest in data retrieval methods or algorithmic approaches.
His user experience consists mainly of choosing a good view in
the map, specifying the delivery points and getting the solution
(route) displayed.
In addition we define a second user role; a user interested in
the aspects of the solving process itself, we granted him access
to previously saved problems, with particular attention to the
algorithmic approach, this user can solve different TSPs with
different instances of the ACO using default or specific
A. Choosing the web mapping platform
The majority of GIS based implementations tend to use
Google maps™ for the imagery and vector data quality, but
also for its ease of use APIs [15]. Other services have emerged
with the same quality of service but different development
goals, most used are: Bing maps™ and Open Street maps
(OSM). We decided to choose between these three mapping
platforms, one that fits best our needs . To do so, we narrowed
our comparative scope to the city of Casablanca, Morocco.
Several decision criteria might be placed in order to select
the right platform depending on user needs. While others may
focus on Geotagging, points of interest (POI) or Geocoding and
reverse geocoding capabilities [8], we are mainly interested in
the richness of geographic network, the performance of the
routing engine, the quality of imagery, and ease of use.
One fast and efficient technique for choosing the right
platform is overlaying a service with another, and comparing
the two, B. Ciepluch and al. suggest that a visual comparison


of several areas is sufficient to decide which of the three
platforms fits our needs [16]. One of the numerous tools for
visually comparing web based maps is provided by Geofabrik,
where OSM, Google maps™ and Bing maps™ views are
confronted in a split-pane window permitting a comparison of
the content [17].
Comparison over several parts of the city shows that Bing
maps™ has the richest network; the tile server generates more
and more detail as we zoom in, and it outclasses other
platforms with a very precise road configuration. Fig1
illustrates a snapshot of the tool in the core center of the city of
Casablanca, the colored circles were added to highlight our
satisfaction towards each service.
While a rich network affects positively the routing engine,
the three platforms did equally well, and provided adequate
point-to-point routes in complicated situations , respecting one
way roads and traffic flows . In some special cases due to the
difference in networks we were unable to fix starting or ending
locations in Google maps™ and OSM-based routing services
(locations in the street Rue Sttatia for example ( Fig1), can only
be explored in Bing maps™, the street is completely absent
from the other two platforms).
For ergonomic purpose we decide to include imagery data
with multiple map views: road view, satellite view and a third
option overlays the two views with 50% transparency each.
The three services showed fair results in rendering the
requested views.
On ease of use, Google maps™ provides rich API for
routing purposes, and a web based control to host map

imagery. Bing maps™ offers a look alike APIs and adds to that
a desktop and phone controls to host the map imagery. OSM is
a community based open GIS and provides extensive third
party tools for advanced GIS purposes, while many
programming libraries exist for handling OSM data [18],
Google maps™ and Bing maps™ fill our needs with really
easy to setup and work with tools and services .
To close the discussion on the choice of the platform, we
decided to implement Bing maps™ routing APIs and imagery,
mainly due the richness of the network and cartographic data
for the region of Casablanca.
B. Solution architecture
Once we chose the adequate mapping platform, other
design aspects were taken in consideration to deliver a working
scalable model, achieving a mix of performance and simplicity.
The model as presented in Fig2 consists of three main parts,
problem formulation, spatial data management and problem
solving. The problem formulation and solving are user oriented
features, spatial data management is necessary for
communication with Bing maps™ and handling all the data
transformation, it ensures that every data request is responded
with the right data format.
Problem formulation starts with the user choosing the city
or region, the solution stores data about the 16 economic
regions of the country of Morocco, the user has the ability to
select the default map location in which the program will start.
With zoom and pan capabilities and navigation controls , the
user can select the desired map view in which the problem will
be formulated, for ease of use several map views were



implemented : 1) Road mode, is the default view found on
most of mapping platforms, it consists of a very ergonomic
rendered map where the highways, roads and streets are
highlighted with different colors. 2) Aerial mode, is similar to
satellite view, many users tend to find this map view very
suitable to recognize locations. 3) Aerial with labels, it
resembles to a combination of the precedent views, this mode
uses the satellite view and overlays it with helpful data like
place names and road configuration.
Formulating the TSP is as easy as clicking on the map, all
the user has to do is finding the desired location and adding a
pin to it, pins are completely draggable and interactive. The
user can add a limitless amount of pins. For the example we are
running, 40 pins were spread over the highly dense and
complex geographic network of the city of Casablanca.
The city was not randomly chosen, with a city area of
386Km² and a metropolitan area of 1615Km², Casablanca is
both economically and demographically the largest city of
Morocco and the region of Maghreb. Historical, social and
economic considerations gave the city a very heterogeneous
and dense road configuration. With high traffic flows and
continuously evolving transportation constraints .
The largest instance of TSP formulated in this paper
“Casablanca_40” consists of 40 locations; Fig3 shows the user
defined locations on the map. Two map views (Aerial with
labels, and Road mode) were put side to side for illustrative
purpose. In all the examples run to test the effectiveness of the
solution, the locations were deliberately distributed over places
with intense transportation traffic like industrial districts, city
connectors and seaports. Other locations were pinned in the
core of the old city characterized by a broad variety of streets
in terms of width and number of lanes, with very narrow and
one-way streets. The rest of the locations were purposely put

near highly populated neighborhoods, transportation hubs,
highly solicited public services, and other known landmarks.
After saving the problem, data management services start
by calculating the number of edges of the TSP graph, given
that the distance from a location to itself is null, in a fully
connected ATSP the number of edges for n nodes is n²-n [19],
the system makes n(n-1) routing requests for Bing maps™
routing services, for each request Bing maps™ responds with a
JSON file, a lightweight data-interchange format easy for
machines to parse and generate. The file contains valuable
spatial data about the route between the two locations, this
graph edge or point-to-point route contains the actual distance,
estimated time, route directions and route coordinates. The
system parses all the JSON files and cons tructs an n by n data
matrix containing distances. The matrix will serve to feed the
The proposed architecture ensures that the problem
formulation is isolated from the algorithmic approach, the data
handling services do all the calculations, requests, parsing and
formatting tasks. This model is scalable in a manner where the
problem can be upgraded to other TSP like problems and the
algorithm can be changed or modified freely from the problem
instances. The passed distance matrix is just a special case of a
cost matrix, distances for example can be replaced with
estimated travel times resulting in fastest tours instead of
shortest tours as an objective function.
The final part of our proposed model is the solving process,
user chooses between a set of previously saved problems and
starts the map viewer, the solutions renders the actual ATSP
over the map as seen in Fig4, the user decides where to start to
optimization process with the default algorithm parameters or
with custom parameters, when the convergence criterion is met
the algorithm gives initial tour, best-so-far tours and the best
found tour, the solution is then displayed over the map.


C. Algorithmic approach
As mentioned previously, we use ACO for solving the
ATSP, the algorithm is fed with a data matrix and has to find
the best tour between a set of feasible solutions. The ACO has
a broad set of variations [13]; the one we are using is a highly
modified version of the code proposed by James McCaffrey
ACO was first proposed in 1996 by Dorigo, and has shown
successful implementations in combinatorial optimization, the
algorithm consists of a number of agents (ants) moving
independently and communicating globally. Informally, each
ant builds a solution while discovering the ATSP graph, the
ants move conferring to a probabilistic transition rule; they tend
to move to next locations with shorter routes and higher
pheromone. Once every ant has discovered the graph and built
tours we apply a global pheromone updating rule [2].
The pheromone updating rule is the key to a good
communication and thus to discovering new solutions with
better objective functions . The rule works like this: due to the
volatile nature of pheromone a fraction of it evaporates on all
edges with every iteration, after visiting all locations ants
deposit a quantity of pheromone relative to a parameter Q and
the length of the route L, shorter routes will have more
pheromone deposited. This rule helps the algorithm to allocate
more desirability for solutions with shorter routes; pheromone
plays here the role of a distributed memory stored in the graph
itself and not the agents [2][13].

Here we present the implemented ACO algorithm:
Start ACO
Initialize ants randomly on starting locations
Loop :
Loop :
Move ants based on locations desirability
Until : All ants have built tours
Update pheromones globally
Until : End criterion is met

Once the end criterion is met the algorithm stops, and
returns the best found tour, the criterion can be a convergence
criterion. For example once the algorithm finds a less or equal
tour than the desired distance it stops, here we fixed a number
of iterations as a criterion.
The returned solution is then subject to spatial data
management to retrieve the geocoordinates of the solution


route. The solution is then drawn over the map, letting the user
to interact with the results of the optimization process.
This chapter will present the underlying details of the
implementation of our solution for TSP solving in the city of
Casablanca. To test the effectiveness of our solution, instances
of 10, 30 and 40 were implemented over different locations of
the city. Table 1 shows that for every problem, data
management system has generated the ATSP formulation with
subroutes details and distance matrixes. And the ACO has
found solutions to the TSPs.
The solution space is shown to highlight the performance of
the algorithm in solving complex problems, in this case
problems with 30 locations and more are all considered


Number of Locations




Number of generated Subroutes




T otal Cumulated Distance (Km)




Solution Space




Found a solution




Initial tour lenght (Km)




Best tour lenght (Km)




Improvement on Initial tour




Best tour returned at iteration




moderately large, and are challenging to solve without an
efficient algorithmic approach [2].
After the problem formulation, data management system
made n(n-1) requests from Bing maps™. With the instance of
40 locations for example, the system made a total of 1560
requests, the resulting files served to draw 1560 different routes
over the city as shown in Fig4. The ACO was then set to run on
the 40² matrix and showed considerably good results in a
reasonable amount of time.
The ACO found solutions to all the test problems in its
early iterations, and kept updating its best so far tour until the
criterion end is met; the Algorithm successfully held an
improvement rate beyond 50% in all the instances. This
improvement rate increases with the size of the solution space
The ACO instance we are running uses the parameters
shown in Fig6. The number of ants was chosen to fit 1/10 of
locations, the pheromone exponent and heuristic or greedy
exponent play a role in ants foraging behavior and their
tendency to select the next location to be visited. Pheromone
deposit and evaporation factors define the algorithm’s memory
shaping through the iterations.
For the largest proposed problem the solution running
through the locations (23 35 38 39 32 37 6 33 34 36 31 14 24
22 26 27 29 30 25 21 28 0 4 5 20 10 11 12 13 16 17 18 19 2 3
15 1 7 8 9 back to 23) was found to be the best, Fig7 shows the
evolution of the objective function through the iterations of the






If we take the 40 locations ATSP, the problem has
16273.18Km of edges. The best initial solution has a closed
tour of 398,5Km, the algorithm kept updating its best so far
solutions to stop at iteration 1000, returning the best solution of
163.6Km (nearly 58.95% of optimized route compared to
iteration 0). This optimum or near-optimum solution was found
in iteration 716 and increasing the maximum iterations didn’t
result in any great change in the quality of the final solution,
consequently, the average runtime of the algorithm became
noticeable to the average user.
The present work results showed efficiency in providing a
solution to various TSP problems in one of the most
complicated transportation environments of Morocco, and the
region of Maghreb.
The optimized tour was a result of the association of many
dynamics, starting from the quality of Bing maps™ data to the
proficiency of data management services and finally the
performance of the Ant colony optimization algorithm.
The proposed model is highly customizable and can be
used with other web mapping platforms, or other algorithmic
approaches. The aim is to solve scalable routing problems with
high efficiency algorithms , using publically accessible
The current approach can be used directly or indirectly to
enhance the performance of urban transportation systems,
resulting in vital improvements of many city-dependent life








JOHNSON, David S. and MCGEOCH, Lyle A. T he traveling salesman
problem: A case study in local optimization. Local search in
combinatorial optimization, 1997, vol. 1, p. 215 -310.
DORIGO, Marco and GAMBARDELLA, Luca Maria. Ant colony
system: a cooperative learning approach to the traveling salesman
problem. Evolutionary Computation, IEEE T ransactions on, 1997, vol.
1, no 1, p. 53-66.
JONES, Chris B. Geographical information systems and computer
cartography. Routledge, 2014.
DELLING, Daniel, GOLDBERG, Andrew Vladislav, PAJOR, T homas,
and al. Customizable route planning in road networks. In : Sixth Annual
Symposium on Combinatorial Search. 2013.
LIN, Shen and KERNIGHAN, Brian W. An effective heuristic
algorithm for the traveling-salesman problem. Operations research,
1973, vol. 21, no 2, p. 498-516.
SNYDERS, F. J. and LANE-VISSER, T . E. Improving the work rate of
community health workers through optimisation. In : 41st Annual
Conference of the Operations Research Society of South Africa. 2012. p.
PERBOLI, Guido, MAGGIONI, F., and T ADEI, Roberto. T he multipath T raveling Salesman Problem with stochastic travel costs: A City
Logistics computational study. 2013.
Vanden, and al. T he city trip planner: an expert system for tourists.
Expert Systems with Applications, 2011, vol. 38, no 6, p. 6540-6546.
RODRÍGUEZ, Beatriz, MOLINA, Julián, PÉREZ, Fátima, and al.
Interactive design of personalised tourism routes. T ourism Management,
2012, vol. 33, no 4, p. 926-940.
ZEILER, Michael (ed.). Geographic Data Management. ESRI, 2001 .
APPLEGATE, David L., BIXBY, Robert E., CHVÁTAL, Vašek, and al.
Certification of an optimal TSP tour through 85,900 cities. Operations
Research Letters, 2009, vol. 37, no 1, p. 11 -15.
Carlos Henggeler. A web spatial decision support system for vehicle
routing using Google Maps. Decision Support Systems, 2011, vol. 51,
no 1, p. 1-9.
DORIGO, Marco, BIRATTARI, Mauro, and ST UTZLE, T homas. Ant
colony optimization. Computational Intelligence Magazine, IEEE, 2006,
vol. 1, no 4, p. 28-39.
LEWCZUK, K., ŻAK, J., PYZA, D., and al. Vehicle routing in an urban
area: environmental and technological determinants. Urban T ransport
XIX, 2013, vol. 130, p. 373-384.
Gibin, M., Singleton, A., Milton, R., Mateos, P., and Longley, P. (2008).
An exploratory cartographic visualisation of London through the Google
maps™ API. Applied Spatial Analysis and Policy, 1(2), 85 -97.
MOONEY, Peter. Comparison of the accuracy of OpenStreetMap for
Ireland with Google maps™ and Bing maps™ .
Geofabrik, GmbH, Germany. Map compare. Geofabrik Tools Web Site.
[Online] 2014.
HAKLAY, Mordechai and WEBER, Patrick. Openstreetmap: Usergenerated street maps. Pervasive Computing, IEEE, 2008, vol. 7, no 4, p.
JOHNSON, David S., GUT IN, Gregory, MCGEOCH, Lyle A., and al.
Experimental analysis of heuristics for the AT SP. In : T he traveling
salesman problem and its variations. Springer US, 2007. p. 445 -487.
James McCaffrey, Microsoft. T est Run - Ant Colony Optimization.