#! heuristic = 0]: self.item = itemself . . . self, node]: x, y = node.itemreturn0#-*-mã hóa: utf-8-*-# intert = 0, heuristic = 0]: self.item = itemself.parent = pargeforelf.gscore = gscoreself.heuristic = heuristicdef__eq __ [tự, khác] .heuristicNode.gscore: left = bisect.b isect_left [hàng đợi, trùng lặp] phải = bisect.bisect_right [hàng đợi, trùng lặp] Queue.pop [Queue.index [trùng lặp, trái, phải]] nodeBisect.insort_left [hàng đợi, nút] returnPathClassd2 [astarpathfinding]: def__init __ [self, ma trận, hàng, cols]: self.matrix = matrixelf. .Itemx2, y2 = des.itemreturnabs [x1-x2] +abs [y1-y2] refgetchildren [self, node]: x, y = node.itemreturn [self.node [[x +1, y] , gscore = node.gscore+1], self.node [[x-1, y], Parent = node, gscore = node.gscore+1], self.node [[x, y+1], Parent = node , gscore = node.gscore+1], self.node [[x, y-1], Parent = node, gscore = node.gscore+1],] defavailable [self, node]: x, y = node.itemreturn0 # -*- coding: utf-8 -*- # import bisect class AStarPathfinding[object]: class Node[object]: # item must be hashable def __init__[self, item, parent=None, gscore=0, heuristic=0]: self.item = item self.parent = parent self.gscore = gscore self.heuristic = heuristic def __eq__[self, other]: return other.item == self.item def __lt__[self, other]: return self.gscore + self.heuristic node.gscore: left = bisect.bisect_left[queue, duplicated] right = bisect.bisect_right[queue, duplicated] queue.pop[queue.index[duplicated, left, right]] node.heuristic = self.heuristic[node, target] openpath[node.item] = node bisect.insort_left[queue, node] return path class D2[AStarPathfinding]: def __init__[self, matrix, rows, cols]: self.matrix = matrix self.rows = rows self.cols = cols def heuristic[self, src, des]: x1, y1 = src.item x2, y2 = des.item return abs[x1 - x2] + abs[y1 - y2] def getchildren[self, node]: x, y = node.item return [ self.Node[[x + 1, y], parent=node, gscore=node.gscore + 1], self.Node[[x - 1, y], parent=node, gscore=node.gscore + 1], self.Node[[x, y + 1], parent=node, gscore=node.gscore + 1], self.Node[[x, y - 1], parent=node, gscore=node.gscore + 1], ] def available[self, node]: x, y = node.item return 0
Hướng dẫn a algorithm python implementation - triển khai thuật toán python
Bài Viết Liên Quan
Toplist mới
#1
Top 7 sự tích hồ gươm - ngữ văn lớp 6 2023
6 tháng trước#2
Top 7 gdcd 6 bài 1 kết nối tri thức 2023
6 tháng trước#3
Top 7 ý nghĩa của xây dựng gia đình văn hóa 2023
6 tháng trước#4
Top 6 mẫu hợp đồng mượn đất làm nhà xưởng 2023
6 tháng trước#5
Top 3 tổng tài biến thái tôi yêu anh tập 27 2023
6 tháng trước#6
Top 6 kết thực phim mỹ nhân vô lệ 2023
6 tháng trước#7
#8
Top 8 đề tài và chủ de của tác phẩm tắt đèn 2023
6 tháng trước#9
Top 5 tiểu sử của thầy thích pháp hòa 2023
6 tháng trướcBài mới nhất
Chủ Đề
programming
Hỏi Đáp
Toplist
Là gì
Bài Tập
Địa Điểm Hay
Mẹo Hay
Học Tốt
Nghĩa của từ
Công Nghệ
Khỏe Đẹp
bao nhiêu
Top List
Tiếng anh
Bao nhiêu
Sản phẩm tốt
Xây Đựng
Ngôn ngữ
javascript
Ở đâu
Đại học
Hướng dẫn
Bài tập
Tại sao
Dịch
So Sánh
Máy tính
Món Ngon
mẹo hay
Bao lâu
Thế nào
So sánh
Khoa Học
Vì sao
Lớp 9
Lớp 10