我正在编写一些读取csv的代码,并从该csv计算沿已选择的2个点之间的所有可能路径进行穷举搜索的最小成本,以及打印出选择的顺序点列表,以分割给出最小成本的路线
我现时的守则如下:
import csv import sys
size = 100 class PointGrabber:
locationList = []
def __init__(self, size):
self.locationList = [] #Square brackets are an indexing operator
self.matrix = [[0 for x in range(size)] for y in range (size)]
self.points = []
self.readData()
self.storeDist()
def readData(self):
with open('/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/Locations.csv') as f:
csv_reader = csv.reader(f)
index = 0
next(csv_reader)
for line in csv_reader:
pointName = line[0]
x = line[1]
y = line[2]
number = line[3]
edge = line[4]
water=False
if line[5] == "W":
water=True
self.locationList.append( [pointName, x, y, number, edge, water] ) # etc
if not pointName in self.points:
self.points.append(pointName)
index += 1
f.close()
def storeDist(self):
for index in range(0, len(self.locationList)-1):
if self.locationList[index][4] !="":
start = self.locationList[index][0]
end = self.locationList[index][4]
for indexA in range(0, len(self.points)-1):
if self.points[indexA] == start:
indexPointA = indexA
for indexB in range(0, len(self.points)-1):
if self.points[indexB] == end:
indexPointB =indexB
distance = self.computeDist(start, end)
break
break
def computePathDist(self, path):
dist = 0
return distance
def findPath(self, a, b):
path = []
return path
def computeCost(self, a, b):
path = []
costing = 0
return costing, path
def computeDist(self, a, b):
dist = 0
return dist
def improveDist(self, a, b):
point=0
scaledImprovement=0
return point, scaledImprovement
def findScope(self, a, b):
pointList = [a, b]
for index in range(0, size-1):
if self.points[index ]== a:
indexa=index
if self.points[index] == b:
indexb = index
return pointList
if __name__ == '__main__':
pg = PointGrabber(size)
print(pg.locationList)
pg.computeCost("15", "18")
pg.improveDist("15", "18")
目前没有回答
相关问题 更多 >
编程相关推荐