Wednesday, April 26, 2017

4-opt* – general idea, part 2

The second crucial part of 4-opt* idea is to examine only a specific cases of potentially improving moves.

Any k-opt move that improves a tour move must fulfill the condition:

addLength < delLength

Sum of length of links added must be less than sum of links removed from tour. It is therefore necessary (though insufficient) that at least one of added links is shorter than one of removed links. Lengths of all four links removed in 4-opt* procedure are (see schemes below):

delLen_1 = distance(tour[i], tour[(i+1) mod N])
delLen_2 = distance(tour[j], tour[(j+1) mod N])
delLen_3 = distance(tour[k], tour[(k+1) mod N])
delLen_4 = distance((k+1) mod N], tour[(k+2) mod N])

We take the length of the longest of them:

delLenMax = max(delLen_1, max (delLen_2, max(delLen_3, delLen_4)))

We determine that to reconnect the cities we always add the link to city in position k+1 either from city in position i+1 or from city in j and that we take the shorter of these two links:

addLen_1 = distance(tour[(i+1) mod N], tour[(k+1) mod N])
addLen_2 = distance(tour[(j) mod N], tour[(k+1) mod N])

addLenMin = min(addLen1, addLen2)

Possible cases of reconnection and gain from them are tested only if:

addLenMin < delLenMax

This test guarantees that at least this added link is shorter than at least one of the links removed. If the condition is not met, then cases of 4-opt* move are not examined. This way we examine only one of two classes of moves:

Fixed links in 4-opt* moves
Class A Class B
i i+1 j j+1 k k+1 k+2 i i+1 j j+1 k k+1 k+2

So for given i, j, k we consider only one class of reconnections: A or B. Either class have only 8 cases of reconnection (see below), as opposed to 48 cases in standard 4-opt. Moreover, since the scheme of class B is symmetrical to the scheme of class A, then cases of reconnection for class B will be also symmetrical to cases for class A.

4-opt* move: reconnection cases of class A
2-opt move
3-opt moves
4-opt moves

Tuesday, April 25, 2017

4-opt* – general idea, part 1

Since full 4-opt is rather complex and time comsuming, Renaud, Boctor and Laporte (1996) proposed a tour improving procedure caled 4-opt*, based on using a specific subset of 4-opt moves. Its main goal is to extend searching for improving moves beyond 2-opt moves, but keep this searching fast.

Elements of 4-opt move Elements of 4-opt* move
i j m k i j k

As we can see, the first difference between standard 4-opt and 4-opt* is that while the scheme of general 4-opt move involves four non-overlapping segments with eight endpoints, the scheme of 4-opt* involves only three segments and seven points; fourth segment is reduced to one point between endpoints of two other segments. The layout for standard 4-opt requires four parameters (i, j, k, m), but for 4-opt* it is only three parameters (i, j, k). This allows us to reduce number of corresponding nested loops in searching for an improvement, each of O(N). (There is additional advantage: reduction of possible cases of reconnection. In 4-opt move they result from its four parameters, but 4-opt* cases result from only three parameters. Therefore number of cases (types of reconnection) of a move in 4-opt* is reduced compared to the number of cases in standard 4-opt. For example double bridge cannot be made in 4-opt*).

Moreover, value of j is obtained from: j = i + u, where u <= w and w is some arbitrary number chosen by the developer or a user and usually relatively small compared to N (for example: 10, 15 or 20). Therefore for given u the procedure considers only O(N2) choices, changing values of i and k. This way we consider links at the ends of two not overlaping chains: from position i to i+u+1, and from position k to k+2.

i i+1 i+u i+u+1 k k+1 k+2

The 4-opt* algorithm starts with u=1 and considers all choices of such two chains of cities. If an improvement is found then it is immediately applied and searching is repeated. When no improvement is found then u is incremented by 1 and the same process is repeated. When the process of improvimg for u==w is finished, then u is reset to 1 and the same procedure is applied once again, until there is no improvement in such full round.

improved = false
while not improved:
  u = 1
  improved = false
  while u <= w:
    block two_loops:
      for i in ... :
        j = i + u
        ...
        for k in ... :
          ...
          # additional speed-up
          ...
          for case_of_move in ... :
            gain = Gain_From_4optAsterisk(i, j, k, case_of_move)
            if gain > 0:
              Make_4optAsterisk_Move(i, j, k, case_of_move)
              improved = true
              break two_loops
    #end_block two_loops
    u = u + 1
  #end_while u loop

Saturday, April 22, 2017

4-opt and Double Bridge

Replacing 3-optic moves in the local optimization with 4-opt moves increases the time complexity the algorithm from O(N3) to O(N4), or, in the case of using lists of candidates (neighbors), from O(N * m2) to O (N * m3), where m is number of neighbors in the list.

However, the problem does not lie only in much greater time of execution. Applying 4-opt moves gives tours only slightly shorter than those from 3-optimization. Moreover, while for 3-opt there are 8 types (cases) of move, for 4-opt this number increases to 48, so considering all of them becomes much more complicated. As in 3-opt, one of them gives the tour identical with the tour before the move. Analogically to 3-opt, many of them are equal to a single 2-opt or a single 3-opt move; there are only 25 pure 4-opt moves. But something new appears in 4-opt moves: most known 4-opt move, called double bridge move.

The simplicity and symmetry of the double bridge scheme make it particularly easy to recognize and remember:

Double bridge, as the simplest non-sequential move (idea of so called sequenctial moves is described later), plays important role even in algorithms that do not use full 4-optimization. By definition given tour after full 3-optimization cannot be further improved by 3-opt, but it does not mean that there are no similar but shorter tours. Instead of trying to search or build such tours from scratch, we often use 3-optimized tour and perturb it to obtain a new good initial tour, that we can then optimize, perhaps getting better result. Double bridge is used as simple and effective perturbation.

Double bridge and other non-sequential 4-opt moves are discussed in detail later.