Permit disabling of A* path cache at compile-time
Mostly to measure its effectiveness. Compile with AS_NO_PATH_CACHE defined to disable it. Turns out the path cache is quite effective. For my continental test case (Hvy Metal 2 updates), it reduces the number of searches by a factor of 18.5, speeding up distribution path assembly by a factor of 7. The price is memory: it uses 135 times more memory than the A* library. For my island test case (Hvy Plastic 2 updates), I get 4 times search reduction, 3.5 times faster distribution path assembly, 36 times more memory.
This commit is contained in:
parent
0385c67a8f
commit
a02d3e9fc1
1 changed files with 18 additions and 1 deletions
|
@ -26,7 +26,6 @@
|
||||||
* ---
|
* ---
|
||||||
*
|
*
|
||||||
* path.c: Empire/A* Interface code.
|
* path.c: Empire/A* Interface code.
|
||||||
* Define AS_STATS for A* statistics.
|
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Phil Lapsley, 1991
|
* Phil Lapsley, 1991
|
||||||
|
@ -35,6 +34,14 @@
|
||||||
* Steve McClure, 1997
|
* Steve McClure, 1997
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define AS_STATS for A* statistics on stderr.
|
||||||
|
*
|
||||||
|
* Define AS_NO_PATH_CACHE to disable the path cache. The path cache
|
||||||
|
* saves a lot of work, but uses lots of memory. It should be a
|
||||||
|
* significant net win, unless you run out of memory.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -103,7 +110,11 @@ best_path(struct sctstr *from, struct sctstr *to, char *path, int mob_type)
|
||||||
if (!mybestpath)
|
if (!mybestpath)
|
||||||
mybestpath = bp_init();
|
mybestpath = bp_init();
|
||||||
adp = mybestpath->adp;
|
adp = mybestpath->adp;
|
||||||
|
#ifdef AS_NO_PATH_CACHE
|
||||||
|
ap = NULL;
|
||||||
|
#else
|
||||||
ap = as_find_cachepath(from->sct_x, from->sct_y, to->sct_x, to->sct_y);
|
ap = as_find_cachepath(from->sct_x, from->sct_y, to->sct_x, to->sct_y);
|
||||||
|
#endif
|
||||||
if (ap == NULL) {
|
if (ap == NULL) {
|
||||||
adp->from.x = from->sct_x;
|
adp->from.x = from->sct_x;
|
||||||
adp->from.y = from->sct_y;
|
adp->from.y = from->sct_y;
|
||||||
|
@ -278,19 +289,25 @@ bp_coord_hash(struct as_coord c)
|
||||||
void
|
void
|
||||||
bp_enable_cachepath(void)
|
bp_enable_cachepath(void)
|
||||||
{
|
{
|
||||||
|
#ifndef AS_NO_PATH_CACHE
|
||||||
as_enable_cachepath();
|
as_enable_cachepath();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bp_disable_cachepath(void)
|
bp_disable_cachepath(void)
|
||||||
{
|
{
|
||||||
|
#ifndef AS_NO_PATH_CACHE
|
||||||
as_disable_cachepath();
|
as_disable_cachepath();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bp_clear_cachepath(void)
|
bp_clear_cachepath(void)
|
||||||
{
|
{
|
||||||
|
#ifndef AS_NO_PATH_CACHE
|
||||||
as_clear_cachepath();
|
as_clear_cachepath();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue