algorithms/TwoOPT.py
def algorithm(self):
        """
        Calculate a path with the 2-opt algorithm
        """
        t = time.clock()
        self.calculateFirstPath()
        improve = True
        while improve and (self.allowedTime > (time.clock() - t)):
            improve = False

            for i in range(self.NB_OF_NODES):
                for j in range(self.NB_OF_NODES):
                    if j in [(i - 1) % self.NB_OF_NODES, i, (i + 1) % self.NB_OF_NODES]:
                        continue

                    if self.getDistance(i, i + 1) + self.getDistance(j, j + 1) > self.getDistance(i, j) + self.getDistance(i + 1, j + 1):
                        self.exchange(i, j)
                        improve = True

        Calculate a path with the 2-opt algorithm
        
Calculate a path with the 2-opt algorithm
Calculate a path with the 2 - opt algorithm
def algorithm(self):
        t = time.clock()
        self.calculateFirstPath()
        improve = True
        while improve and (self.allowedTime > (time.clock() - t)):
            improve = False
            for i in range(self.NB_OF_NODES):
                for j in range(self.NB_OF_NODES):
                    if j in [(i - 1) % self.NB_OF_NODES, i, (i + 1) % self.NB_OF_NODES]:
                        continue
                    if self.getDistance(i, i + 1) + self.getDistance(j, j + 1) > self.getDistance(i, j) + self.getDistance(i + 1, j + 1):
                        self.exchange(i, j)
                        improve = True
def algorithm ( self ) : t = time . clock ( ) self . calculateFirstPath ( ) improve = True while improve and ( self . allowedTime > ( time . clock ( ) - t ) ) : improve = False for i in range ( self . NB_OF_NODES ) : for j in range ( self . NB_OF_NODES ) : if j in [ ( i - 1 ) % self . NB_OF_NODES , i , ( i + 1 ) % self . NB_OF_NODES ] : continue if self . getDistance ( i , i + 1 ) + self . getDistance ( j , j + 1 ) > self . getDistance ( i , j ) + self . getDistance ( i + 1 , j + 1 ) : self . exchange ( i , j ) improve = True
Calculate a path with the 2-opt algorithm
Calculate a path with the 2 - opt algorithm
"""
        Calculate a path with the 2-opt algorithm
        """
self