From: Steinar H. Gunderson Date: Fri, 7 Apr 2006 15:22:28 +0000 (+0000) Subject: Use 0 and 1 for left and right side instead of 0 and 1. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=e1eca11fee8f1aa85e5ad89f39b63d81d205256e;p=nms Use 0 and 1 for left and right side instead of 0 and 1. --- diff --git a/tsp/tsp.cpp b/tsp/tsp.cpp index af6185e..587573b 100644 --- a/tsp/tsp.cpp +++ b/tsp/tsp.cpp @@ -68,10 +68,10 @@ int distance(int row_from, int switch_from, int side_from, int row_to, int switc } /* can we just switch sides? */ - if (row_from + 1 == row_to && side_from == 1 && side_to == -1) { + if (row_from + 1 == row_to && side_from == 1 && side_to == 0) { return distance_switch(switch_from, switch_to); } - if (row_from == row_to + 1 && side_from == -1 && side_to == 1) { + if (row_from == row_to + 1 && side_from == 0 && side_to == 1) { return distance_switch(switch_from, switch_to); } @@ -94,7 +94,7 @@ int optimistic_distance(int row_from, int switch_from, int row_to, int switch_to if (abs(row_from - row_to) == 1) return distance_switch(switch_from, switch_to); else - return distance(row_from, switch_from, -1, row_to, switch_to, -1); + return distance(row_from, switch_from, 0, row_to, switch_to, 0); } // extremely primitive O(V^2) prim @@ -139,7 +139,7 @@ void print_tour(std::vector > &points) } for (unsigned i = 0; i < points.size(); ++i) { - if (best_tour[i].side == -1) + if (best_tour[i].side == 0) printf("%2u-%u (left side) ", best_tour[i].row, best_tour[i].num); else printf("%2u-%u (right side) ", best_tour[i].row, best_tour[i].num); @@ -197,14 +197,14 @@ unsigned do_tsp(std::vector > &points, std::setfirst; temp[toi].num = i->second; - temp[toi].side = -1; - temp[toi].cost = distance(last_row, last_switch, last_side, i->first, i->second, -1); + temp[toi].side = 0; + temp[toi].cost = distance(last_row, last_switch, last_side, i->first, i->second, 0); ++toi; temp[toi].row = i->first; temp[toi].num = i->second; - temp[toi].side = +1; - temp[toi].cost = distance(last_row, last_switch, last_side, i->first, i->second, +1); + temp[toi].side = 1; + temp[toi].cost = distance(last_row, last_switch, last_side, i->first, i->second, 1); ++toi; } @@ -253,7 +253,7 @@ int main() /* always start at the first one, left side (hack) */ ord[0].row = points[0].first; ord[0].num = points[0].second; - ord[0].side = -1; + ord[0].side = 0; do_tsp(points, points_left, ord, temp, 1, 0); printf("All done.\n");