For NP problems such as TSP, when the task size is small, traditional methods can obtain the exact optimal solution; however, in real life, the problems are generally more complex and larger in size, and traditional methods require huge resources for computation and the results will not be ideal. Traditional methods are challenged. Therefore, heuristic methods are derived. Some heuristics can help us to find approximate optimal solutions. Usually, this is enough to be applied in practical situations.
In this presentation, we present the application of the basic ant colony algorithm to the tsp problem and implement it using matlab; and, conduct comparative experiments with the application of other other heuristics (particle swarm algorithm, genetic algorithm).
This is useful for beginners to understand heuristic algorithms and NP problems.
4. Classical algorithms
Exact algorithms for solving TSP
Brute Force
Method: try all possible
permutations of the city,
calculate the total distance
travelled for each combination,
and then choose the shortest
path.
Time complexity: O(n!),
where n is the number of cities.
This is because it is necessary
to iterate through all possible
city permutations.
Applicability: only works for
very small problem instances
(e.g. n<10).
Dynamic Programming
Method: The core of the algorithm is
to recursively calculate the shortest
path from each subset to a certain
point, and finally get the shortest path
of the whole set.
Time complexity: O(n2*2n), where n
is the number of cities. Although an
improvement over the violent
method, the time complexity is still
exponential, limiting its application to
medium- to large-scale problems.
Applicability: suitable for medium-
sized problem instances (e.g., n < 20).
Branch and Bound
Method: A tree structure is used to
systematically enumerate all
possible solutions, and the number
of paths to be explored is reduced
by bounding and pruning.
Time complexity: O(n!) in the worst
case, but may be lower than this in
practice, as the number of paths to
be considered is massively reduced
by pruning.
Applicability: can be applied to
medium-sized problems, and the
actual performance depends on the
effectiveness of the bounding and
pruning strategies. (Experienced)
5. Integer linear programming(ILP)
ij ij
ij trips
dist
min
This method utilizes the cut-plane method of integer
programming, which involves solving a linear program
formed by the two constraints in the model, and then solving
for the cut-plane by adding inequality constraints that
gradually converge to the optimal solution. People applying
this method to find the cutting plane often rely on
experience, so this method is rarely used as a generalized
method.
So, in the last semester's question on tsp containing 200
U.S. cities. The cut plane in question, i.e., a linear
inequality that can exclude current illegal solutions (e.g.,
those containing subloops) without excluding any
possible integer solutions. We got the relevant tangent
plane settings from the matlab website, otherwise we
would not have been able to set the tangent plane by
ourselves
7. The ants are able to leave pheromones on the paths it passes through during its movement, and the
ants are able to sense the presence and strength of pheromones and use them to guide the direction
of their movement, the ants tend to move in the direction of high pheromone strength.The ants tend
to move in the direction of high pheromone strength.
The collective behavior of a large number of ants in a colony shows a positive feedback
phenomenon: the more ants that pass on a certain path, the higher the probability that later ants will
choose that path. It is through this exchange of information that individual ants search for food.This
exchange of information between individual ants leads to the fastest search for food.
heuristic algorithm
Ant colony algorithm
8. Ant colony algorithm
positive feedback effect
Assuming that the pheromone left behind by the ants at
each point they pass through is one unit, then after 36
time units, all the ants that started to leave together
obtained food from point D through different paths. At
this time, the route of ABD made 2 round trips, and the
pheromone of each place was 4 units, and the ants of the
route of ACD returned only once, and the pheromone of
each place was 2 units, and the ratio was 2:1.
The search for food continues, and as guided by the pheromone, the colony sends additional ants on the
ABD route. The pheromone gap between the two routes will get bigger and bigger and eventually all
the ants will abandon the ACD route!
9. Ant colony algorithm
Ant colony foraging Ant colony algorithm
ant colony
foraging space
pheromone
A path from the nest to the food
Shortest path found
A set of valid solutions in the search space
(expressed as a population size N)
The search space of the problem (expressed as
dimension D)
Pheromone concentration variables
An effective solution
Optimal solution of the problem
10. Ant colony algorithm
The ACO algorithm for solving TSP has two main steps: path construction and
pheromone updating
1. Path construction
Each ant randomly selects a city as its starting city and maintains a path memory
vector to hold the cities that the ant passes through sequentially.
At each step of the path construction, the ant chooses the next city to be reached
according to a randomized proportionality rule.
11. Ant colony algorithm
Randomized proportionality rules
For each ant k, the path memory vector Rk, records the serial numbers of all the cities that k has passed through
in the order of visit. Let the current city of ant k be i,then the probability that it chooses city j as its next visit is
the above rule.
where allowedk is the set of nodes that have not been visited yet; α,β are two constants, weighted by
pheromone and visibility, respectively
:visibility
:pheromone intensity
(inverse of distance)
12. Ant colony algorithm
2.Pheromone updating
Pheromone updating is at the heart of the ant algorithm. The algorithm has a fixed concentration value
during the initial period, and after each iteration is completed, all the ants that go out and come back
will calculate the routes they have traveled, and then update the pheromone concentration of the
corresponding edges.
Obviously, this value must be related to the length of the ants traveled, and after one iteration, the
concentration will be high for close routes, thus obtaining a near-optimal solution.
Initialize the pheromone concentration C(0), if it is too small, the algorithm is easy to precocious, the
ants will quickly concentrate on a locally optimal path,; if C is too large, the guiding effect of the
pheromone on the search direction is reduced, affecting the algorithm performance.
In general, we can use the greedy algorithm to obtain a path value Cnn, and then according to the
number of ants to calculate C(0) = m/Cnn ,m is the number of ants
13. Ant colony algorithm
To simulate ants leaving more pheromone on shorter paths, when all ants reach the end point, the
pheromone concentration of each path must be re-updated once, and the pheromone updating is also
divided into two steps.The updating of pheromone is also divided into two steps:
First, after each round, the pheromone on all paths in the problem space evaporates.
Then, all ants release pheromone on the edges they pass through this round according to
the length of the paths they constructed.
In the formula, m is the number of ants, 0 < ρ ≤ 1 is the pheromone evaporation rate,
which is usually set to 0.5 in the algorithm, and Δτk
ij is the pheromone left behind by the
kth ant in the path i to j
14. Ant colony algorithm
Definition of
Ck is the total path length obtained after the kth ant has traveled the whole path
15. Ant colony algorithm
The ants search for paths
in the graph and
pheromones are used to
guide the search process,
the pheromones evaporate
over time and are updated
based on the quality of the
paths found by the ants.
This continuous process
allows the algorithm to
find solutions that are
close to the shortest
possible path.
16. Ant colony algorithm
Simple Application of ACO
The TSP problem for four cities, with the distance matrix and cities illustrated below:
17. Ant colony algorithm
Step 1 :Initialize pheromone
Assuming a total of m = 3 ants and the parameters α = 1, β = 2 and ρ = 0.5 (from
internet experience)
Firstly,we use the greedy algorithm to get the (ACDBA) of the path,
then Cnn = 1+2+4+3 = 10, and find τ0 =m/Cnn =0.3
Step 2:Randomly select a departure city for each ant, assuming that ant 1 selects
city A, ant 2 selects city B, and ant 3 selects city D.
18. Ant colony algorithm
Step 3.1: Select the next city to visit for each ant (ant 1 only)
Ant 1 is in the current city i=A and can visit the set of cities
J1(i)={B,C,D}, Calculate the probability that ant 1 visits each
city
Use roulette to select the next city to visit. We get that ant 1 will choose city B.
Similarly, suppose Ant 2 chooses city D and Ant 3 chooses city A.
19. Ant colony algorithm
Step 3.2: Select the next city to visit for each ant (ant 1 only)
Ant 1 is in the current city i=B ,The path memory vector
Rl=(AB), and the ant 1 can visit the set of cities J1(i)={C,D},
Calculate the probability that ant 1 visits cities C,D:
Use roulette to select the next city to visit. We get that ant 1 will choose city D.
Similarly, suppose Ant 2 chooses city C and Ant 3 chooses city D.
20. Ant colony algorithm
At this point, so the ants' paths have been constructed
Ant 1:A→B →D →C →A
Ant 2:B→D →C →A →B
Ant 3:D→A →C →B →D
21. Ant colony algorithm
Step 4: Pheromone updating
Calculate the length of the path constructed by each ant: C1=3+4+2+1=10;
C2=4+2+1+3=10; C3=2+1+5+4=12. updating the pheromone on each edge.
Step 5:
If the end condition is satisfied, output the globally optimal result and end the
program.
Otherwise, it turns to step 2 to continue execution.
23. First, I used the rand function to generate a 31*2 two-dimensional variable of type double in
the range [0,5000].That's 31 cities. Also 30 ants were set up with parameter variables α = 1, β
= 5 and ρ = 0.1.And find the globally optimal path and draw.
Also, I plotted a line graph of the change in shortest distance and average distance with
increasing number of iterations.
Programming
24. Programming
With the limit of 200 iterations, we can see that the algorithm finds a good solution at the 92nd
iteration, with the shortest distance being 15833.2 units of length. And the fluctuation of the average
distance after that indicates that the ants are still exploring new possible optimal solutions.
26. Comparative experiment
Ant colony algorithm (iterations extended to 2000)
The ACO algorithm stabilizes after
about 100 iterations, finding a better
path at 394 iterations. The shortest
distance of 15601.9 units of length
reached at this point (not much
different from the previous 15833.2)
remains almost unchanged for the
next 1500 iterations. In reality, we
just need to find a better solution in
as little time consumption (iterations)
as possible.
Compare this to the PSO and GA
algorithms, which both find a better
solution around 1000 iterations at
around 18500 unit lengths. Both are
inferior to ACO algorithm (in this
TSP problem)
28. Traditional :
Accuracy: Traditional optimization methods, such as linear
programming and integer programming, can provide exact solutions,
which is necessary for application scenarios that require precise results.
Computational complexity: for smaller problem instances, these
methods are usually feasible. However, TSP is NP-hard problem, which
means that an increase in problem size leads to an exponential increase
in solution time, making traditional methods impractical for large-scale
problems.
Resource requirements: finding an exact solution often requires
significant computational resources, including time and memory,
especially when the problem size is large.
Traditional vs. Heuristics
29. Efficiency: Heuristic methods, such as ant colony algorithms, genetic algorithms, and
particle swarm optimization algorithms, usually find good enough solutions in an
acceptable amount of time, especially for large-scale problems.
Flexibility: these methods are well adapted to various variants of TSPs, and the
performance can be optimized by tuning the parameters.
Quality of solutions: while heuristics may not be guaranteed to find an optimal
solution, they are often able to find very close to optimal solutions in practical
applications.
Ease of implementation: Heuristics tend to be easier to implement and debug than
complex exact algorithms.(Less math)
Scalability: Heuristic methods can be easily extended to other complex multi-
objective optimization problems, combinatorial optimization problems.
Traditional vs. Heuristics
Heuristics: