Add path length statistic

main
Bryson Zimmerman 11 months ago
parent 1efb03fc1f
commit bc6a4a5231

@ -14,10 +14,10 @@ import kotlin.math.abs
object ArrayBackedPathfinder { object ArrayBackedPathfinder {
var gVals = TileNavigatedArray<Int>(World.sizeX, World.sizeY, false) var gVals = TileNavigatedArray<Int>(World.sizeX, World.sizeY, false)
var pathLength = 0
//work along the path, marking tiles with VISITED along the way //work along the path, marking tiles with VISITED along the way
//if marking with visited is too expensive, just make the path and finalize it //if marking with visited is too expensive, just make the path and finalize it
fun generatePath(start: Tile, end: Tile) { fun generatePath(start: Tile, end: Tile) {
if(!start.isInBounds() || !end.isInBounds()) { if(!start.isInBounds() || !end.isInBounds()) {
throw IndexOutOfBoundsException("Cannot generate a path to or from an out of bounds tile") throw IndexOutOfBoundsException("Cannot generate a path to or from an out of bounds tile")
} }
@ -26,6 +26,8 @@ object ArrayBackedPathfinder {
println("Ouroboros detected") println("Ouroboros detected")
return return
} }
pathLength = 0
gVals = TileNavigatedArray<Int>(World.sizeX, World.sizeY, false) gVals = TileNavigatedArray<Int>(World.sizeX, World.sizeY, false)
val frontier = TileHeap(end, this::fValue) val frontier = TileHeap(end, this::fValue)
@ -74,6 +76,7 @@ object ArrayBackedPathfinder {
} }
} }
current = lowestCost current = lowestCost
pathLength++
} }
World.update(start, start.getProperties() + Directions.INPATH) World.update(start, start.getProperties() + Directions.INPATH)
} }

@ -2,8 +2,6 @@ package technology.zim
import technology.zim.data.Tile import technology.zim.data.Tile
import java.io.File import java.io.File
import java.text.NumberFormat
import java.util.Locale
import kotlin.time.measureTime import kotlin.time.measureTime
class HierarchicalPathfinding { class HierarchicalPathfinding {
@ -26,7 +24,7 @@ class HierarchicalPathfinding {
val ns = arrayListOf(50, 100, 250, 500, 750, 1000) val ns = arrayListOf(50, 100, 250, 500, 750, 1000)
val iterations = 10 val iterations = 10
val file = File("performance.csv") val file = File("performance.csv")
file.writeText("n, build, bfs, astar-array, astar-hashmap\n") file.writeText("n,path-length,build,bfs,astar-array,astar-hashmap\n")
if(benchmarking) { if(benchmarking) {
for (n in ns) { for (n in ns) {
@ -70,7 +68,7 @@ class HierarchicalPathfinding {
var mapBackedPathfinderTime = measureTime { var mapBackedPathfinderTime = measureTime {
MapBackedPathfinder.generatePath(Tile(0, 0), Tile(n - 1, n - 1)) MapBackedPathfinder.generatePath(Tile(0, 0), Tile(n - 1, n - 1))
} }
file.appendText("${n},${buildMazeTime.inWholeMilliseconds},${bfsPathfinderTime.inWholeMilliseconds},${arrayBackedPathfinderTime.inWholeMilliseconds},${mapBackedPathfinderTime.inWholeMilliseconds}\n") file.appendText("${n},${buildMazeTime.inWholeMilliseconds},${ArrayBackedPathfinder.pathLength},${bfsPathfinderTime.inWholeMilliseconds},${arrayBackedPathfinderTime.inWholeMilliseconds},${mapBackedPathfinderTime.inWholeMilliseconds}\n")
} }

Loading…
Cancel
Save