Exemple #1
0
    def divideLine(self, start, end):
        line = [start]
        length = distanceBetween(start, end)
        divisions = 1
        while length / divisions > self.maxLineLength:
            divisions += 1

        pointsToIntroduce = divisions - 1
        pointsOnLine = self.getPointsInLine(start, end)
        pointOnLineStep = len(pointsOnLine) / divisions
        for i in range(1, pointsToIntroduce + 1):
            line.append(pointsOnLine[int(pointOnLineStep) * i])

        return line
    def calculateSolutionDistance(self, sol):
        solution = sol[:]
        totalDistance = 0
        currLine = solution.pop(0)
        nextLine = solution.pop(0)

        while len(solution):
            curEnd = currLine[-1]
            nextStart = nextLine[0]
            totalDistance += distanceBetween(curEnd, nextStart)
            currLine = nextLine
            nextLine = solution.pop(0)

        return totalDistance
Exemple #3
0
    def getCleanedDots(self):
        dots = self.dots[:]
        prev = dots.pop(0)
        cleanedDots = []

        while len(dots):
            curr = dots.pop(0)
            distance = distanceBetween(prev, curr)
            if distance > self.maxLineLength:
                line = self.divideLine(prev, curr)
                cleanedDots = cleanedDots + line
            elif distance < self.minLineLength:
                pass
            else:
                cleanedDots.append(prev)
            prev = curr

        cleanedDots.append(curr)

        return cleanedDots
 def generateDistanceMatrix(self):
     n = len(self.coords)
     distanceMatrix = [[
         distanceBetween(self.coords[i], self.coords[j]) for i in range(n)
     ] for j in range(n)]
     return distanceMatrix