Don't like ads? PRO users don't see any ads ;-)
Guest

2-opt pseudocode

By: a guest on May 7th, 2012  |  syntax: C#  |  size: 0.47 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //2-opt kż
  2. bool poprawione = false;
  3. while poprawione
  4. {
  5.   poprawione = false;
  6.   foreach(vertex x_i in cykl)
  7.   {
  8.     foreach(vertex x_j in cykl)
  9.     {
  10.       if(j!= i-1 && j!=i+1)
  11.       {
  12.         if(dystans(x_i,x_i+1) + dystans(x_j,x_j+1) > dystans(x_i,x_j) + dystans(x_i+1,x_j+1))
  13.         {
  14.           Podmień edge(x_i,x_i+1) przez edge(x_i,x_j)
  15.           Podmień edge(x_j,x_j+1) przez edge(x_i+1,x_j+1)
  16.           poprawione = true;
  17.         }
  18.       }
  19.     }
  20.   }
  21. }