Final project of analysis and design of algorithmsESSAY Instructing Lecturer: Teacher NGUYỄN CHÍ THIỆN Students: NGUYỄN VĂN TÀI – 518H0050 TRẦN CÔNG PHÚ – 518H0550 Khoá : 22 THÀNH PHỐ HỒ
Trang 1Final project of analysis and design of algorithms
ESSAY
Instructing Lecturer: Teacher NGUYỄN CHÍ THIỆN
Students: NGUYỄN VĂN TÀI – 518H0050
TRẦN CÔNG PHÚ – 518H0550
Khoá : 22
THÀNH PHỐ HỒ CHÍ MINH, NĂM 2022
Trang 2Final project of analysis and design of algorithms
ESSAY
Instructing Lecturer: Teacher NGUYỄN CHÍ THIỆN
Students: NGUYỄN VĂN TÀI – 518H0050
TRẦN CÔNG PHÚ – 518H0550
Khoá : 22
THÀNH PHỐ HỒ CHÍ MINH, NĂM 2022
Trang 4LỜI CẢM ƠN
Để hoàn thành tiểu luận này, em xin gửi lời cảm ơn chân thành đến:
Các thầy cô trong khoa Công nghệ thông tin đã cung cấp các kiến thức nền tảng để áp dụng và nghiên cứu thông tin trong bài tiểu luận.
Em xin bày tỏ lòng biết ơn sâu sắc đến thầy Nguyễn Chí Thiện người đã trực tiếp giảng dạy và hướng dẫn tạo mọi điều kiện thuận lợi giúp đỡ em trong quá trình thực hiện đề tài.
Tuy đã có nhiều cố gắng, nhưng chắc chắn tiểu luận của em còn có vài điểm sai sót Rất mong nhận được sự nhận xét, ý kiến đóng góp, phê bình từ phía Thầy để bài tiểu luận được hoàn thiện hơn.
Xin chân thành cám ơn!
Trang 5LỜI CAM ĐOAN
Tôi xin cam đoan đây là sản phẩm đồ án của riêng tôi và được sự hướng dẫn của Bui Thanh Hung Các kết quả trong đề tài này là trung thực và chưa công bố dưới bất
kỳ hình thức nào trước đây Những số liệu trong các bảng biểu phục vụ cho việc phân tích, nhận xét, đánh giá được chính tác giả thu thập từ các nguồn khác nhau có ghi rõ trong phần tài liệu tham khảo.
Ngoài ra, trong tiểu luận còn sử dụng một số nhận xét, đánh giá cũng như số liệu của các tác giả khác, cơ quan tổ chức khác đều có trích dẫn và chú thích nguồn gốc.
Nếu phát hiện có bất kỳ sự gian lận nào tôi xin hoàn toàn chịu trách nhiệm
về nội dung đồ án của mình Trường đại học Tôn Đức Thắng không liên quan đến
những vi phạm tác quyền, bản quyền do tôi gây ra trong quá trình thực hiện (nếu có).
TP Hồ Chí Minh, ngày 31 tháng 03 năm 2022
Tác giả (ký tên và ghi rõ họ tên)
Trần Công Phú Nguyễn Văn Tài
Trang 6PHẦN XÁC NHẬN VÀ ĐÁNH GIÁ CỦA GIẢNG VIÊN
Phần xác nhận của GV hướng dẫn
_ _ _ _ _ _ _
Tp Hồ Chí Minh, ngày tháng năm
(kí và ghi họ tên)
Phần đánh giá của GV chấm bài
_ _ _ _ _ _ _
Tp Hồ Chí Minh, ngày tháng năm
(kí và ghi họ tên)
Trang 8TÓM TẮT
Trang 9LỜI CẢM ƠN i
LỜI CAM ĐOAN ii
PHẦN XÁC NHẬN VÀ ĐÁNH GIÁ CỦA GIẢNG VIÊN iii
TÓM TẮT iv
MỤC LỤC 1
DANH MỤC KÍ HIỆU VÀ CHỮ VIẾT TẮT 2
DANH MỤC CÁC BẢNG BIỂU, HÌNH VẼ, ĐỒ THỊ 3
CHƯƠNG I - What is Traveling Salesman Problem? 4
CHƯƠNG II - List all possible algorithm design strategies to solve the problem: 6
1 Nearest-neighbor algorithm: 6
2 Brute force algorithm: 8
3 Ant colony optimization algorithm: 10
CHƯƠNG III - FUTURE SCOPE 11
CHƯƠNG IV - REFERENCES 12
Trang 10DANH MỤC KÍ HIỆU VÀ CHỮ VIẾT TẮT
Trang 12CHƯƠNG I - What is Traveling Salesman Problem
The traveling salesman problem (TSP) is an algorithmic problem tasked with finding the shortest route between a set of points and locations that must be visited In the problem statement, the points are the cities a salesperson might visit The salesman’s goal is to keep both the travel costs and the distance traveled as low as possible
Given a list of cities, what is the shortest possible route that visits each city and returns to the origin city?
Rules:
Each city needs to be visited exactly one time
We must return to the starting city, so our total distance needs to be calculated accordingly
plt.annotate(alphabet[i].upper(), (x[i], y[i]))
for j in range(i+ 1 , len(x)):
allPaths.append(str(i)+str(j))
Trang 13connectPoints(x, y, int(path[ 0 ]), int(path[ 1 ]))
plt.axis('equal')
plt.show()
Fig 1 An instance of TSP
Trang 14CHƯƠNG II - List all possible algorithm design strategies to solve the problem:
Trang 15 Repeat the first two steps until there is no city left
Comeback to the starting city
for vertex in G.keys():
for neighbour in G[vertex].keys():
forward_edge = (vertex, neighbour, G[vertex][neighbour])
backward_edge = (neighbour, vertex, G[vertex][neighbour], )
if (forward_edge not in edges) and (backward_edge not in edges): edges.append(forward_edge)
edges = sorted(edges, key=lambda : e[ 2 ])
return edges
def findVertices( , v):
E = edges(G)
Trang 162 Brute force algorithm:
Fig 3 TSP solver solution using Brute-Force algorithm
Trang 17The Brute Force approach, also known as the Naive Approach, calculates andcompares all possible permutations of routes or paths to determine the shortestunique solution.
Steps:
Calculate the total number of routes
List all the possible routes
Calculate the distance of each route
Choose the shortest one
distance += cities[path[- 2 ]][node]
if (len(cities) == len(path)) and (path[ 0 ] in cities[path[- 1 ]]):
for city in cities:
if (city not in path) and (node in cities[city]):
find_paths(city, dict(cities), list(path), distance)
find_paths('A', graph, [], 0
routes.sort()
print (routes[ 0 ][ 1 ])
Trang 183 Ant colony optimization algorithm:
Fig 4 TSP solver solution using Ant colony optimization algorithm
Describe:
Ants are social insects They live in colonies The behavior of ants is controlled
by the goal of searching for food While searching, ants roaming around their colonies An ant repeatedly hops from one place to another to find the food While moving, it deposits an organic compound called pheromone on the
ground Ants communicate with each other via pheromone trails When an ant finds some amount of food it carries as much as it can carry When returning it deposits pheromone on the paths based on the quantity and quality of the food Other ants can smell it and follow that path The higher the pheromone level has,
a higher probability of choosing that path and the more ants follow the path, the amount of pheromone will also increase on that path Ant colony optimization based on the foraging behavior of an ant for seeking a path between their colony
and source food was first introduced in the 90s by Marco Dorigo.
Steps:
Each ant generates a solution
Found paths are compared
Pheromone is updated
Trang 20CHƯƠNG III - FUTURE SCOPE
This assignment presents application analysis among possible algorithm for solving TSP There exists in order to classify which algorithm gives the best optimal
In this paper we have described on the basis of total distance travelled and
implement based on properties of these algorithms In future the comparison can
be done on the basis of performance and cost to see which algorithm gives the better result
Trang 21 https://en.wikipedia.org/wiki/Nearest_neighbour_algorithm
On the Nearest Neighbor Algorithms for the Traveling Salesman Problem | SpringerLink
Ant colony optimization algorithms - Wikipedia
Ant Colony Optimization - an overview | ScienceDirect Topics
Solving the Travelling Salesman Problem for deliveries (routific.com)
Trang 22PHỤ LỤC
Phần này bao gồm những nội dung cần thiết nhằm minh họa hoặc hỗ trợ cho nội dung luận văn như số liệu, biểu mẫu, tranh ảnh nếu sử dụng những câu trả lời cho
một bảng câu hỏi thì bảng câu hỏi mẫu này phải được đưa vào phần Phụ lục ở dạng
nguyên bản đã dùng để điều tra, thăm dò ý kiến; không được tóm tắt hoặc sửa đổi.
Các tính toán mẫu trình bày tóm tắt trong các biểu mẫu cũng cần nêu trong Phụ lục của luận văn Phụ lục không được dày hơn phần chính của luận văn.