mirror of
https://github.com/Assasinnys/ED-AStar-Galaxy-Router
synced 2025-04-12 06:30:01 +03:00
fix: accept changes to AStarMainFile
This commit is contained in:
parent
f740e9663f
commit
7e7a86cab3
@ -38,14 +38,14 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
||||
|
||||
multithreatingFindNeighbours(startStarPoint)
|
||||
|
||||
openedList.remove(startStarPoint.systemId64)
|
||||
closedList[startStarPoint.systemId64] = startStarPoint
|
||||
|
||||
if (openedList.isEmpty()) {
|
||||
println("${consoleStringCounter()}Unable to complete task. No neighbors found near startStarPoint. =(")
|
||||
return
|
||||
}
|
||||
|
||||
openedList.remove(startStarPoint.systemId64)
|
||||
closedList[startStarPoint.systemId64] = startStarPoint
|
||||
|
||||
do {
|
||||
|
||||
if (checkForFinish()) {
|
||||
|
@ -1,19 +1,16 @@
|
||||
package elite.alternative
|
||||
|
||||
import elite.algorithm.StarPoint
|
||||
import elite.database.Database
|
||||
import elite.pojo.Coordinates
|
||||
import elite.replaces
|
||||
import elite.utils.*
|
||||
import java.io.File
|
||||
import java.sql.ResultSet
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
//TODO check for neutron as a second star
|
||||
//TODO check neighbors StarPoint's for better way (lower cost) [ready 50%]
|
||||
|
||||
class AStarMainFile {
|
||||
/* private val coords = Coordinates(-2275.3125, -1140.5312, 1284.9688)
|
||||
private val coords = Coordinates(-2275.3125, -1140.5312, 1284.9688)
|
||||
private val finishStarPoint = StarPoint(null, 216165812715L, coords, true, 0.0, null, 0, coords)
|
||||
|
||||
private val startStarPoint =
|
||||
@ -21,19 +18,20 @@ class AStarMainFile {
|
||||
|
||||
private val file = File(FILENAME)
|
||||
|
||||
private val openedList = mutableListOf<StarPoint>()
|
||||
private val closedList = mutableListOf<StarPoint>()
|
||||
private val openedList = hashMapOf<Long, StarPoint>()
|
||||
private val closedList = hashMapOf<Long, StarPoint>()
|
||||
private val stopwatch = Stopwatch()
|
||||
|
||||
init {
|
||||
openedList.add(startStarPoint)
|
||||
openedList[startStarPoint.systemId64] = startStarPoint
|
||||
}
|
||||
|
||||
fun activateAStarAlgorithm() {
|
||||
|
||||
findNeighbours(startStarPoint)
|
||||
|
||||
openedList.remove(startStarPoint)
|
||||
closedList.add(startStarPoint)
|
||||
openedList.remove(startStarPoint.systemId64)
|
||||
closedList[startStarPoint.systemId64] = startStarPoint
|
||||
|
||||
if (openedList.isEmpty()) {
|
||||
println("${consoleStringCounter()}Unable to complete task. No neighbors found near startStarPoint. =(")
|
||||
@ -50,8 +48,8 @@ class AStarMainFile {
|
||||
|
||||
val selectedStarPoint = findStarPointWithMinCost()
|
||||
findNeighbours(selectedStarPoint)
|
||||
openedList.remove(selectedStarPoint)
|
||||
closedList.add(selectedStarPoint)
|
||||
openedList.remove(selectedStarPoint.systemId64)
|
||||
closedList[selectedStarPoint.systemId64] = selectedStarPoint
|
||||
|
||||
} while (openedList.isNotEmpty())
|
||||
|
||||
@ -59,19 +57,23 @@ class AStarMainFile {
|
||||
}
|
||||
|
||||
private fun checkForFinish(): Boolean {
|
||||
openedList.forEach { point ->
|
||||
if (point == finishStarPoint) {
|
||||
finishStarPoint.previousStarPoint = point
|
||||
return true
|
||||
}
|
||||
if (openedList.containsKey(finishStarPoint.systemId64)) {
|
||||
finishStarPoint.previousStarPoint = openedList[finishStarPoint.systemId64]
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun findStarPointWithMinCost(): StarPoint {
|
||||
return openedList.minBy { starPoint -> starPoint.costF }!!.also { nextStarPoint ->
|
||||
println("Min cost star point: G = ${nextStarPoint.costG}, F = ${nextStarPoint.costF}, H = ${nextStarPoint.costH} " +
|
||||
"dist = ${nextStarPoint.distance}, start = ${nextStarPoint.previousStarPoint == startStarPoint}")
|
||||
stopwatch.start()
|
||||
return openedList.minBy {
|
||||
it.value.costF
|
||||
}!!.value.also {
|
||||
println(
|
||||
"Min cost star point: G = ${it.costG}, F = ${it.costF}, " +
|
||||
"dist = ${it.distance}, start = ${it.previousStarPoint == startStarPoint}"
|
||||
)
|
||||
stopwatch.stopWithConsoleOutput("Min cost find time: ")
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +105,7 @@ class AStarMainFile {
|
||||
starPoint.jumpCounter.plus(1),
|
||||
finishStarPoint.coords
|
||||
)
|
||||
if (closedList.notContains(newStarPoint))
|
||||
if (closedList.notContains(newStarPoint.systemId64))
|
||||
openedList.smartAdd2(newStarPoint)
|
||||
|
||||
} else if (!starPoint.isNeutronStar && distance <= USUAL_DISTANCE) {
|
||||
@ -117,7 +119,7 @@ class AStarMainFile {
|
||||
finishStarPoint.coords
|
||||
)
|
||||
|
||||
if (closedList.notContains(newStarPoint))
|
||||
if (closedList.notContains(newStarPoint.systemId64))
|
||||
openedList.smartAdd2(newStarPoint)
|
||||
}
|
||||
}
|
||||
@ -146,7 +148,7 @@ class AStarMainFile {
|
||||
// db.closeDB()
|
||||
println("${consoleStringCounter()} Total jumps counter = $counter, distance = $fullDistance ly, replaces = $replaces, cof = ${StarPoint.NEUTRON_COF}")
|
||||
return counter
|
||||
}*/
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NEUTRON_DISTANCE = 240
|
||||
|
Loading…
x
Reference in New Issue
Block a user