title: 3-opt optimization code for TSP
body: <p>I have this code (tsp problem) that works for the 2-opt optimization and i'd like to change it for a 3-opt optimization. I know i must add a for, but don't really understand the range of the third for. Can you help me? </p>
  
  <pre><code>    double bestDecrement = tsp.infinite;
      // intial and final position are fixed (initial/final node remains 0)
      for ( uint a = 1 ; a &lt; currSol.sequence.size() - 2 ; a++ ) 
      {
          int h = currSol.sequence[a-1];
          int i = currSol.sequence[a];
          for ( uint b = a + 1 ; b &lt; currSol.sequence.size() - 1 ; b++ ) 
          {
              int j = currSol.sequence[b];
              int l = currSol.sequence[b+1];
              double neighDecrement = - tsp.cost[h][i] - tsp.cost[j][l] + tsp.cost[h][j] + tsp.cost[i][l] ;
              if ( neighDecrement &lt; bestDecrement ) 
              {
                  bestDecrement = neighDecrement;
                  move.from = a;
                  move.to = b;
              }
          }
      }
  </code></pre>