This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dijkstra | |
| fun <T> dijkstra(graph: Graph<T>, start: T): Map<T, T?> { | |
| val S: MutableSet<T> = mutableSetOf() // subset dari simpul yang kita ketahui jarak sebenarnya, contoh [A, B, C, D, E] | |
| /* | |
| * variable delta mewakili jumlah dari banyaknya jalur terpendek | |
| * Isi pertama adalah infinity dengan Int.MAX_VALUE untuk nanti dibandingkan | |
| */ | |
| val delta = graph.vertices.map { it to Double.MAX_VALUE }.toMap().toMutableMap() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlin.math.* | |
| // nilai default radius bumi | |
| const val earthRadiusKm: Double = 6372.8 | |
| // method untuk melakukan perhitungan dengan metode haversine | |
| fun haversine(latDest: Double, longDest: Double, latCurrent: Double, longCurrent: Double): Double { | |
| val dLat = Math.toRadians(latDest - latCurrent) | |
| val dLon = Math.toRadians(longDest - longCurrent) | |
| val originLat = Math.toRadians(latCurrent) |