Skip to content

Commit 1777e33

Browse files
committed
Dynamic connectivity
1 parent 9cc2ff4 commit 1777e33

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

common/src/main/kotlin/com/lambda/pathing/incremental/DStarLite.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class DStarLite(
4747
var start: FastVector,
4848
val goal: FastVector,
4949
val heuristic: (FastVector, FastVector) -> Double,
50+
private val connectivity: GraphUtil.Connectivity = GraphUtil.Connectivity.N26,
5051
) {
5152
// gMap[u], rhsMap[u] store g(u) and rhs(u) or default to ∞ if not present
5253
private val gMap = mutableMapOf<FastVector, Double>()
@@ -150,7 +151,7 @@ class DStarLite(
150151
*/
151152
fun invalidate(u: FastVector, prune: Boolean = false) {
152153
val modified = mutableSetOf(u)
153-
(GraphUtil.n26(u).keys + u).forEach { v ->
154+
(GraphUtil.neighborhood(u, connectivity).keys + u).forEach { v ->
154155
val current = graph.neighbors(v)
155156
val updated = graph.nodeInitializer(v)
156157
val removed = current.filter { w -> w !in updated }

common/src/main/kotlin/com/lambda/util/GraphUtil.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ object GraphUtil {
6666
}
6767
}
6868

69+
fun neighborhood(o: FastVector, conn: Connectivity) = neighborhood(o, conn.minDistSq, conn.maxDistSq)
6970
fun n6(o: FastVector) = neighborhood(o, minDistSq = 1, maxDistSq = 1)
7071
fun n18(o: FastVector) = neighborhood(o, minDistSq = 1, maxDistSq = 2)
7172
fun n26(o: FastVector) = neighborhood(o, minDistSq = 1, maxDistSq = 3)
@@ -94,4 +95,10 @@ object GraphUtil {
9495

9596
private const val COST_SQRT_2 = 1.4142135623730951
9697
private const val COST_SQRT_3 = 1.7320508075688772
98+
99+
enum class Connectivity(val minDistSq: Int, val maxDistSq: Int) {
100+
N6(minDistSq = 1, maxDistSq = 1),
101+
N18(minDistSq = 1, maxDistSq = 2),
102+
N26(minDistSq = 1, maxDistSq = 3);
103+
}
97104
}

0 commit comments

Comments
 (0)