From e9307b7b1d28bc8310a633fc21037dd694245b74 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Mar 2011 04:26:45 +0100 Subject: [PATCH] Regression test-bed for new path finder Define TEST_PATH_FIND to run both the new and the old code, and verify they yield the same path costs. --- src/lib/update/finish.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/lib/update/finish.c b/src/lib/update/finish.c index 9da4a8873..25b14d873 100644 --- a/src/lib/update/finish.c +++ b/src/lib/update/finish.c @@ -35,6 +35,8 @@ #include +#include +#include #include #include #include "distribute.h" @@ -122,7 +124,7 @@ finish_sects(int etu) } -#ifdef USE_PATH_FIND +#if defined(USE_PATH_FIND) || defined(TEST_PATH_FIND) static int distcmp(const void *p, const void *q) { @@ -147,7 +149,7 @@ assemble_dist_paths(double *import_cost) struct sctstr *sp; struct sctstr *dist; int n; -#ifdef USE_PATH_FIND +#if defined(USE_PATH_FIND) || defined(TEST_PATH_FIND) static int *job; int uid, i; coord dx = 1, dy = 0; /* invalid */ @@ -185,13 +187,16 @@ assemble_dist_paths(double *import_cost) } import_cost[uid] = path_find_to(sp->sct_x, sp->sct_y); } - path_find_print_stats(); -#else /* !USE_PATH_FIND */ +#endif /* USE_PATH_FIND || TEST_PATH_FIND */ +#if !defined(USE_PATH_FIND) || defined(TEST_PATH_FIND) char *path; double d; char buf[512]; for (n = 0; NULL != (sp = getsectid(n)); n++) { +#ifdef TEST_PATH_FIND + double new_imc = import_cost[n]; +#endif import_cost[n] = -1; if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y)) continue; @@ -206,6 +211,25 @@ assemble_dist_paths(double *import_cost) path = BestDistPath(buf, dist, sp, &d); if (path) import_cost[n] = d; +#ifdef TEST_PATH_FIND + if (fabs(import_cost[n] - new_imc) >= 1e-6) { + printf("%d,%d <- %d,%d %d: old %g, new %g, %g off\n", + sp->sct_dist_x, sp->sct_dist_y, + sp->sct_x, sp->sct_y, MOB_MOVE, + import_cost[n], new_imc, import_cost[n] - new_imc); + printf("\told: %s\n", path); + d = path_find(sp->sct_dist_x, sp->sct_dist_y, + sp->sct_x, sp->sct_y, dist->sct_own, MOB_MOVE); + assert(d - new_imc < 1e-6); + path_find_route(buf, sizeof(buf), + sp->sct_dist_x, sp->sct_dist_y, + sp->sct_x, sp->sct_y); + printf("\tnew: %s\n", buf); + } +#endif /* TEST_PATH_FIND */ } -#endif /* !USE_PATH_FIND */ +#endif /* !USE_PATH_FIND || TEST_PATH_FIND */ +#if defined(USE_PATH_FIND) || defined(TEST_PATH_FIND) + path_find_print_stats(); +#endif } -- 2.43.0