main.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Travelling-salesman-problem-using-Ant-colony-optimization 作者: Ahsaan-566 项目源码 文件源码
def initGraph(self, name):
        #file reading using pandas
        df = pd.read_excel(name, sheetname='Sheet1')
        dim = df['Dimension']
        x = df['X']
        y = df['Y']
        #print x,y
        self.numCities = len(dim)
        #set and fill the adjMatrix
        self.adjMatrix = [[1.0 for i in range(self.numCities)] for j in range(self.numCities) ]
        for i in range(self.numCities):
            for j in range(self.numCities):
        #fill the adjmatrix with city coordinates and calculate euclidean distances
                self.adjMatrix[i][j] = self.calEdge(x[i], x[j], y[i], y[j])

    #calculating edge weights using euclidean distances
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号