]> git.sesse.net Git - nms/commitdiff
Add gap calculation to the distances in the TSP solver.
authorSteinar H. Gunderson <sesse@samfundet.no>
Fri, 7 Apr 2006 21:49:53 +0000 (21:49 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Fri, 7 Apr 2006 21:49:53 +0000 (21:49 +0000)
tsp/tsp.cpp

index fb09e216497b3bbec3fa78fd25cd43862b69cb91..9fdeaedb2db38eb036b7bb439d19aadcc5e83e1c 100644 (file)
@@ -91,8 +91,20 @@ int distance_middle(unsigned sw, unsigned middle)
 
 int distance_row(unsigned from, unsigned to)
 {
+       /* 4.1m per double row, plus gaps */
+       unsigned base_cost = 41 * abs(from - to);
+       
+       if ((from <= 9) != (to <= 9))
+               base_cost += 25;
+       if ((from <= 17) != (to <= 17))
+               base_cost += 25;
+       if ((from <= 25) != (to <= 25))
+               base_cost += 25;
+       if ((from <= 34) != (to <= 34))
+               base_cost += 25;
+
        /* don't calculate gaps here just yet, just estimate 4.1m per double row */
-       return 41 * abs(from - to);
+       return base_cost;
 }
 
 int pessimistic_distance(int row_from, int switch_from, int row_to, int switch_to)