Skip to content

Commit

Permalink
[BUGFIX] Unique IDs for DC-Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Strobel committed Apr 5, 2024
1 parent 0b730e7 commit ab37759
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ import kotlinx.serialization.Transient
import kotlin.math.exp
import kotlin.math.ln

/**
* Return unique IDs used for the destination choice functions.
* These IDs are used to cache a location's attraction value, as calculated with the function,
* inside the location itself.
*/
object IDDispenser {
var nextID = 0

fun next() : Int {
val id = nextID
nextID += 1
return id
}
}

/**
* Destination choice model. Parent class.
*/
Expand Down Expand Up @@ -37,16 +52,7 @@ sealed class LocationChoiceDCWeightFun {
abstract val coeffIndustrialUnits: Double

@Transient
private var id: Int? = null

fun getUniqueID() : Int {
id?.let {
return it
} ?: run {
id = hashCode()
return id!!
}
}
val id: Int = IDDispenser.next()

/**
* Calculates the natural logarithm of the deterrence function given the distance from the origin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Building (
val properties = it.properties
val point = transformer.toModelCRS( it.geometry.toJTS(geometryFactory) ).centroid

val attractions = dcFunctions.map { (_, v) -> v.getUniqueID() to v.calcAttraction(properties)}.toMap()
val attractions = dcFunctions.map { (_, v) -> v.id to v.calcAttraction(properties)}.toMap()

Building(
osmID = properties.osm_id,
Expand Down

0 comments on commit ab37759

Please sign in to comment.