Final project of analysis and design of algorithms ESSAY list all possible algorithm design strategies to solve the problem

22 16 0
Final project of analysis and design of algorithms ESSAY list all possible algorithm design strategies to solve the problem

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

VIETNAM GENERAL CONFEDERATION OF LABOUR TON DUC THANG UNIVERSITY FACULTY OF INFORMATION TECHNOLOGY Final 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 Khố THÀNH PHỐ HỒ CHÍ MINH, NĂM 2022 : 22 VIETNAM GENERAL CONFEDERATION OF LABOUR TON DUC THANG UNIVERSITY FACULTY OF INFORMATION TECHNOLOGY Final 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 Khố THÀNH PHỐ HỒ CHÍ MINH, NĂM 2022 : 22 i LỜ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ô khoa Công nghệ thông tin cung cấp kiến thức tảng để áp dụng nghiên cứu thông tin 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 hướng dẫn tạo điều kiện thuận lợi giúp đỡ em trình thực đề tài Tuy có nhiều cố gắng, chắn tiểu luận em cịn có vài điểm sai sót Rất mong nhận nhận xét, ý kiến đóng góp, phê bình từ phía Thầy để tiểu luận hoàn thiện Xin chân thành cám ơn! ii LỜI CAM ĐOAN Tôi xin cam đoan sản phẩm đồ án riêng hướng dẫn Bui Thanh Hung Các kết đề tài trung thực chưa cơng bố hình thức trước Những số liệu bảng biểu phục vụ cho việc phân tích, nhận xét, đánh giá tác giả thu thập từ nguồn khác có ghi rõ phần tài liệu tham khảo Ngoài ra, tiểu luận sử dụng số nhận xét, đánh số liệu tác giả khác, quan tổ chức khác có trích dẫn thích nguồn gốc Nếu phát có gian lận tơi xin hồn tồn chịu trách nhiệm nội dung đồ án Trường đại học Tôn Đức Thắng không liên quan đến vi phạm tác quyền, quyền gây q trình thực (nếu có) TP Hồ Chí Minh, ngày 31 tháng 03 năm 2022 Tác giả (ký tên ghi rõ họ tên) Trần Công Phú Nguyễn Văn Tài iii PHẦN XÁC NHẬN VÀ ĐÁNH GIÁ CỦA GIẢNG VIÊN Phần xác nhận GV hướng dẫn _ _ _ _ _ _ _ Tp Hồ Chí Minh, ngày tháng (kí ghi họ tên) năm Phần đánh giá GV chấm _ _ _ _ _ _ _ Tp Hồ Chí Minh, ngày tháng năm (kí ghi họ tên) iv v TĨM TẮT MỤC LỤC LỜ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 DANH MỤC KÍ HIỆU VÀ CHỮ VIẾT TẮT DANH MỤC CÁC BẢNG BIỂU, HÌNH VẼ, ĐỒ THỊ CHƯƠNG I - What is Traveling Salesman Problem? CHƯƠNG II - List all possible algorithm design strategies to solve the problem: .6 Nearest-neighbor algorithm: Brute force algorithm: .8 Ant colony optimization algorithm: 10 CHƯƠNG III - FUTURE SCOPE 11 CHƯƠNG IV - REFERENCES 12 DANH MỤC KÍ HIỆU VÀ CHỮ VIẾT TẮT DANH MỤC CÁC BẢNG BIỂU, HÌNH VẼ, ĐỒ THỊ CHƯƠ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 import matplotlib.pyplot as plt x=[1, 3, 2, 4, 5.5, 5, 7] y=[4.5, 7, 3, 1, 2.5, 7.5, 4] alphabet = 'abcdefghijklmnopqrstuvwxyz' plt.plot(x,y, 'ro') def             connectPoints(x,y,p1,p2): x1, x2 = x[p1], x[p2] y1, y2 = y[p1], y[p2] plt.plot([x1,x2],[y1,y2],'g-') def calDistance(i, j):     return ((x[i]-x[j])**2+(y[i]-y[j])**2)**(1/2) allPaths = [] for i in range(len(x)):     plt.annotate(alphabet[i].upper(), (x[i], y[i]))     for j in range(i+1, len(x)):         allPaths.append(str(i)+str(j)) for path in allPaths:     connectPoints(x, y, int(path[0]), int(path[1])) plt.axis('equal') plt.show() Fig An instance of TSP CHƯƠNG II - List all possible algorithm design strategies to solve the problem: Nearest-neighbor algorithm: Fig Solving TSP using NN Describe: The nearest neighbor algorithm was one of the first algorithms used to solve the travelling salesman problem approximately In that problem, the salesman starts at a random city and repeatedly visits the nearest city until all have been visited The algorithm quickly yields a short tour, but usually not the optimal one Steps:  Choose a city randomly to start  Moving to the nearest city which haven't ever been arrived  Repeat the first two steps until there is no city left  Comeback to the starting city Implementation: graph = {} for i in range(len(x)):     rowList = {}     for j in range(len(x)):         if calDistance(i, j) != 0:             rowList[alphabet[j].upper()] = calDistance(i, j)     graph[alphabet[i].upper()] = rowList print(graph) def TSP(G):     V = [i for i in G.keys()]     s = [V[0]]     visited = [V[0]]     for i in range(len(V)):         adj = findVertices(G, s[i])         for j in adj:             if j not in visited:                 s.append(j)                 visited.append(j)                 break     s.append(s[0])     return s def                                     edges(G):   edges = [] 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: e[2]) return edges def findVertices(G, v):     E = edges(G)                             connected = [] for e in E:     if e[0] == v:         connected.append(e[1])     elif e[1] == v:         connected.append(e[0]) return connected print(TSP(graph)) Brute force algorithm: Fig TSP solver solution using Brute-Force algorithm Describe: The Brute Force approach, also known as the Naive Approach, calculates and compares all possible permutations of routes or paths to determine the shortest unique solution Steps:  Calculate the total number of routes  List all the possible routes  Calculate the distance of each route  Choose the shortest one Implementation: routes = [] def find_paths(node, cities, path, distance):     path.append(node)     if len(path) > 1:         distance += cities[path[-2]][node]                         if (len(cities) == len(path)) and (path[0] in cities[path[-1]]):     global routes     path.append(path[0])     distance += cities[path[-2]][path[0]]     routes.append([distance, path])     return     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]) 10 Ant colony optimization algorithm: Fig 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 11 Implementation (describe in Colab in this case) 12 CHƯƠ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 13 CHƯƠNG IV - REFERENCES  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) 14 PHỤ LỤC Phần bao gồm nội dung cần thiết nhằm minh họa hỗ trợ cho nội dung luận văn số liệu, biểu mẫu, tranh ảnh sử dụng câu trả lời cho bảng câu hỏi bảng câu hỏi mẫu phải đưa vào phần Phụ lục dạng nguyên dùng để điều tra, thăm dò ý kiến; khơng tóm tắt sửa đổi Các tính tốn mẫu trình bày tóm tắt biểu mẫu cần nêu Phụ lục luận văn Phụ lục khơng dày phần luận văn ... instance of TSP CHƯƠNG II - List all possible algorithm design strategies to solve the problem: Nearest-neighbor algorithm: Fig Solving TSP using NN Describe: The nearest neighbor algorithm was one of. .. is Traveling Salesman Problem? CHƯƠNG II - List all possible algorithm design strategies to solve the problem: .6 Nearest-neighbor algorithm: Brute force algorithm: .8...VIETNAM GENERAL CONFEDERATION OF LABOUR TON DUC THANG UNIVERSITY FACULTY OF INFORMATION TECHNOLOGY Final project of analysis and design of algorithms ESSAY Instructing Lecturer: Teacher

Ngày đăng: 25/04/2022, 17:06

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan