]> git.sesse.net Git - nms/commitdiff
Use 0 and 1 for left and right side instead of 0 and 1.
authorSteinar H. Gunderson <sesse@samfundet.no>
Fri, 7 Apr 2006 15:22:28 +0000 (15:22 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Fri, 7 Apr 2006 15:22:28 +0000 (15:22 +0000)
tsp/tsp.cpp

index af6185e4953786481bf8bb294898eb0560fb44fb..587573ba6fa93966ab341e80ec17ec733a38752b 100644 (file)
@@ -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<std::pair<unsigned, unsigned> > &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<std::pair<unsigned, unsigned> > &points, std::set<st
                /* try both sides */
                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 = 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");