From: Steinar H. Gunderson Date: Fri, 7 Apr 2006 21:49:53 +0000 (+0000) Subject: Add gap calculation to the distances in the TSP solver. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f7a057db941c923ab02e8889dd0b68ef53999f18;p=nms Add gap calculation to the distances in the TSP solver. --- diff --git a/tsp/tsp.cpp b/tsp/tsp.cpp index fb09e21..9fdeaed 100644 --- a/tsp/tsp.cpp +++ b/tsp/tsp.cpp @@ -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)