社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

试图让我的python代码计算csv中点之间的距离

Lilly Mayo-099 • 3 年前 • 324 次点击  

我正在编写一些读取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")
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129959
 
324 次点击