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.
This commit is contained in:
parent
d8bef8e806
commit
e9307b7b1d
1 changed files with 29 additions and 5 deletions
|
@ -35,6 +35,8 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include "distribute.h"
|
#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
|
static int
|
||||||
distcmp(const void *p, const void *q)
|
distcmp(const void *p, const void *q)
|
||||||
{
|
{
|
||||||
|
@ -147,7 +149,7 @@ assemble_dist_paths(double *import_cost)
|
||||||
struct sctstr *sp;
|
struct sctstr *sp;
|
||||||
struct sctstr *dist;
|
struct sctstr *dist;
|
||||||
int n;
|
int n;
|
||||||
#ifdef USE_PATH_FIND
|
#if defined(USE_PATH_FIND) || defined(TEST_PATH_FIND)
|
||||||
static int *job;
|
static int *job;
|
||||||
int uid, i;
|
int uid, i;
|
||||||
coord dx = 1, dy = 0; /* invalid */
|
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);
|
import_cost[uid] = path_find_to(sp->sct_x, sp->sct_y);
|
||||||
}
|
}
|
||||||
path_find_print_stats();
|
#endif /* USE_PATH_FIND || TEST_PATH_FIND */
|
||||||
#else /* !USE_PATH_FIND */
|
#if !defined(USE_PATH_FIND) || defined(TEST_PATH_FIND)
|
||||||
char *path;
|
char *path;
|
||||||
double d;
|
double d;
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
for (n = 0; NULL != (sp = getsectid(n)); n++) {
|
for (n = 0; NULL != (sp = getsectid(n)); n++) {
|
||||||
|
#ifdef TEST_PATH_FIND
|
||||||
|
double new_imc = import_cost[n];
|
||||||
|
#endif
|
||||||
import_cost[n] = -1;
|
import_cost[n] = -1;
|
||||||
if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
|
if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
|
||||||
continue;
|
continue;
|
||||||
|
@ -206,6 +211,25 @@ assemble_dist_paths(double *import_cost)
|
||||||
path = BestDistPath(buf, dist, sp, &d);
|
path = BestDistPath(buf, dist, sp, &d);
|
||||||
if (path)
|
if (path)
|
||||||
import_cost[n] = d;
|
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 /* !USE_PATH_FIND */
|
#endif /* TEST_PATH_FIND */
|
||||||
|
}
|
||||||
|
#endif /* !USE_PATH_FIND || TEST_PATH_FIND */
|
||||||
|
#if defined(USE_PATH_FIND) || defined(TEST_PATH_FIND)
|
||||||
|
path_find_print_stats();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue