fix: accept changes to AStarMainFile

This commit is contained in:
Assasinnys 2020-05-19 03:02:18 +03:00
parent f740e9663f
commit 7e7a86cab3
2 changed files with 27 additions and 25 deletions

View File

@ -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()) {

View File

@ -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