mirror of
https://github.com/Assasinnys/ED-AStar-Galaxy-Router
synced 2025-04-13 23:07:19 +03:00
feat: change main formula, work only with neutron stars
This commit is contained in:
parent
79b5ad0ec3
commit
3e8d0b9c30
@ -13,7 +13,7 @@ import elite.utils.*
|
|||||||
import java.sql.ResultSet
|
import java.sql.ResultSet
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
//TODO check for neutron as a second star
|
//TODO check for neutron as a second star -> [future 0%]
|
||||||
//TODO check neighbors StarPoint's for better way (lower cost) [ready 50%]
|
//TODO check neighbors StarPoint's for better way (lower cost) [ready 50%]
|
||||||
|
|
||||||
class AStarMain(private val startSystem: String, private val finishSystem: String) {
|
class AStarMain(private val startSystem: String, private val finishSystem: String) {
|
||||||
@ -93,7 +93,7 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
|||||||
"sqrt((${starPoint.coords.x}-x)^2+(${starPoint.coords.y}-y)^2+(${starPoint.coords.z}-z)^2) as dist\n" +
|
"sqrt((${starPoint.coords.x}-x)^2+(${starPoint.coords.y}-y)^2+(${starPoint.coords.z}-z)^2) as dist\n" +
|
||||||
"from $CORRIDOR\n" +
|
"from $CORRIDOR\n" +
|
||||||
"where sqrt((${starPoint.coords.x}-x)^2+(${starPoint.coords.y}-y)^2+(${starPoint.coords.z}-z)^2) " +
|
"where sqrt((${starPoint.coords.x}-x)^2+(${starPoint.coords.y}-y)^2+(${starPoint.coords.z}-z)^2) " +
|
||||||
"between 0 and ${maxRange.plus(jumpModifier.minus(1).times(60))}" +
|
"between 0 and ${maxRange.plus(jumpModifier.minus(1).times(USUAL_DISTANCE))}" +
|
||||||
"and not $C_ID64=${starPoint.systemId64}"
|
"and not $C_ID64=${starPoint.systemId64}"
|
||||||
|
|
||||||
// threadPool.submit {
|
// threadPool.submit {
|
||||||
@ -103,7 +103,7 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
|||||||
|
|
||||||
private fun findNeighbours(starPoint: StarPoint, sql: String, jumpModifier: Int) {
|
private fun findNeighbours(starPoint: StarPoint, sql: String, jumpModifier: Int) {
|
||||||
checkConnection()
|
checkConnection()
|
||||||
var smartAdd = false
|
var isNoResult = true
|
||||||
|
|
||||||
val sw = Stopwatch().apply { start() }
|
val sw = Stopwatch().apply { start() }
|
||||||
val resultSet = database.query(sql)
|
val resultSet = database.query(sql)
|
||||||
@ -117,11 +117,11 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
|||||||
val newStarPoint = StarPoint(
|
val newStarPoint = StarPoint(
|
||||||
starPoint, getLong(C_ID64), coords,
|
starPoint, getLong(C_ID64), coords,
|
||||||
isNeutronStar, getDouble("dist"),
|
isNeutronStar, getDouble("dist"),
|
||||||
getString(C_SYS_NAME), starPoint.jumpCounter.plus(1), finishStarPoint.coords
|
getString(C_SYS_NAME), starPoint.jumpCounter.plus(jumpModifier), finishStarPoint.coords
|
||||||
)
|
)
|
||||||
if (closedList.notContains(newStarPoint.systemId64)) {
|
if (closedList.notContains(newStarPoint.systemId64)) {
|
||||||
openedList.smartAdd2(newStarPoint)
|
openedList.smartAdd2(newStarPoint)
|
||||||
smartAdd = true
|
isNoResult = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
|||||||
resultSet.close()
|
resultSet.close()
|
||||||
sw.stopWithConsoleOutput("Process time: ")
|
sw.stopWithConsoleOutput("Process time: ")
|
||||||
|
|
||||||
if (!smartAdd) {
|
if (isNoResult) {
|
||||||
multithreatingFindNeighbours(starPoint, jumpModifier.plus(1))
|
multithreatingFindNeighbours(starPoint, jumpModifier.plus(1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,7 +232,7 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
|||||||
starPoint = starPoint.previousStarPoint!!
|
starPoint = starPoint.previousStarPoint!!
|
||||||
counter++
|
counter++
|
||||||
}
|
}
|
||||||
println("${consoleStringCounter()} Total jumps counter = $counter, distance = $fullDistance ly, replaces = $replaces, cof = ${StarPoint.NEUTRON_COF}")
|
println("${consoleStringCounter()} Total jumps counter = ${finishStarPoint.previousStarPoint?.jumpCounter}, distance = $fullDistance ly, replaces = $replaces, cof = ${StarPoint.NEUTRON_COF}")
|
||||||
return counter
|
return counter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class StarPoint(
|
|||||||
|
|
||||||
val previousCostG = previousStarPoint?.costG ?: 0.0
|
val previousCostG = previousStarPoint?.costG ?: 0.0
|
||||||
val costGForStarPoint = if (isNeutronStar)
|
val costGForStarPoint = if (isNeutronStar)
|
||||||
DISTANCE_MODIFIER.minus(distance).minus(NEUTRON_COF)
|
DISTANCE_MODIFIER.div(distance)
|
||||||
// DISTANCE_MODIFIER.div(distance).minus(NEUTRON_COF)
|
// DISTANCE_MODIFIER.div(distance).minus(NEUTRON_COF)
|
||||||
else
|
else
|
||||||
DISTANCE_MODIFIER.minus(distance)
|
DISTANCE_MODIFIER.minus(distance)
|
||||||
@ -67,7 +67,7 @@ class StarPoint(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val DISTANCE_MODIFIER = 100
|
const val DISTANCE_MODIFIER = 10000 // 10k
|
||||||
const val NEUTRON_COF = 0 // Default
|
const val NEUTRON_COF = 0 // Default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import elite.replaces
|
|||||||
import elite.utils.*
|
import elite.utils.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
//TODO check for neutron as a second star
|
//TODO check for neutron as a second star -> [future 0%]
|
||||||
//TODO check neighbors StarPoint's for better way (lower cost) [ready 50%]
|
//TODO check neighbors StarPoint's for better way (lower cost) [ready 50%]
|
||||||
|
|
||||||
class AStarMainFile {
|
class AStarMainFile {
|
||||||
@ -23,15 +23,16 @@ class AStarMainFile {
|
|||||||
private val stopwatch = Stopwatch()
|
private val stopwatch = Stopwatch()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
openedList[startStarPoint.systemId64] = startStarPoint
|
// openedList[startStarPoint.systemId64] = startStarPoint
|
||||||
|
closedList[startStarPoint.systemId64] = startStarPoint
|
||||||
}
|
}
|
||||||
|
|
||||||
fun activateAStarAlgorithm() {
|
fun activateAStarAlgorithm() {
|
||||||
|
|
||||||
findNeighbours(startStarPoint)
|
findNeighbours(startStarPoint, 1)
|
||||||
|
|
||||||
|
// openedList.remove(startStarPoint.systemId64)
|
||||||
|
|
||||||
openedList.remove(startStarPoint.systemId64)
|
|
||||||
closedList[startStarPoint.systemId64] = startStarPoint
|
|
||||||
|
|
||||||
if (openedList.isEmpty()) {
|
if (openedList.isEmpty()) {
|
||||||
println("${consoleStringCounter()}Unable to complete task. No neighbors found near startStarPoint. =(")
|
println("${consoleStringCounter()}Unable to complete task. No neighbors found near startStarPoint. =(")
|
||||||
@ -47,7 +48,7 @@ class AStarMainFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val selectedStarPoint = findStarPointWithMinCost()
|
val selectedStarPoint = findStarPointWithMinCost()
|
||||||
findNeighbours(selectedStarPoint)
|
findNeighbours(selectedStarPoint, 1)
|
||||||
openedList.remove(selectedStarPoint.systemId64)
|
openedList.remove(selectedStarPoint.systemId64)
|
||||||
closedList[selectedStarPoint.systemId64] = selectedStarPoint
|
closedList[selectedStarPoint.systemId64] = selectedStarPoint
|
||||||
|
|
||||||
@ -73,11 +74,12 @@ class AStarMainFile {
|
|||||||
"Min cost star point: G = ${it.costG}, F = ${it.costF}, " +
|
"Min cost star point: G = ${it.costG}, F = ${it.costF}, " +
|
||||||
"dist = ${it.distance}, start = ${it.previousStarPoint == startStarPoint}"
|
"dist = ${it.distance}, start = ${it.previousStarPoint == startStarPoint}"
|
||||||
)
|
)
|
||||||
stopwatch.stopWithConsoleOutput("Min cost find time: ")
|
stopwatch.stopWithConsoleOutput("openList size = ${openedList.size}; Min cost find time: ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findNeighbours(starPoint: StarPoint) {
|
private fun findNeighbours(starPoint: StarPoint, jumpModifier: Int) {
|
||||||
|
var isNoResult = true
|
||||||
val reader = file.bufferedReader().lines()
|
val reader = file.bufferedReader().lines()
|
||||||
reader.forEach { line ->
|
reader.forEach { line ->
|
||||||
val sArray = line.split(" ")
|
val sArray = line.split(" ")
|
||||||
@ -94,35 +96,34 @@ class AStarMainFile {
|
|||||||
coords.z,
|
coords.z,
|
||||||
starPoint.coords.z
|
starPoint.coords.z
|
||||||
)
|
)
|
||||||
|
val maxRange = NEUTRON_DISTANCE.plus(jumpModifier.minus(1).times(USUAL_DISTANCE))
|
||||||
|
val isNeutronStar = sArray[4].toBoolean()
|
||||||
|
|
||||||
if (starPoint.isNeutronStar && distance <= NEUTRON_DISTANCE) {
|
if ((isNeutronStar || coords == finishStarPoint.coords) &&
|
||||||
|
distance <= maxRange
|
||||||
|
) {
|
||||||
val newStarPoint = StarPoint(
|
val newStarPoint = StarPoint(
|
||||||
starPoint, sArray[0].toLong(),
|
starPoint, sArray[0].toLong(),
|
||||||
coords,
|
coords,
|
||||||
sArray[4].toBoolean(),
|
isNeutronStar,
|
||||||
distance,
|
distance,
|
||||||
null,
|
null,
|
||||||
starPoint.jumpCounter.plus(1),
|
starPoint.jumpCounter.plus(jumpModifier),
|
||||||
finishStarPoint.coords
|
|
||||||
)
|
|
||||||
if (closedList.notContains(newStarPoint.systemId64))
|
|
||||||
openedList.smartAdd2(newStarPoint)
|
|
||||||
|
|
||||||
} else if (!starPoint.isNeutronStar && distance <= USUAL_DISTANCE) {
|
|
||||||
val newStarPoint = StarPoint(
|
|
||||||
starPoint, sArray[0].toLong(),
|
|
||||||
coords,
|
|
||||||
sArray[4].toBoolean(),
|
|
||||||
distance,
|
|
||||||
null,
|
|
||||||
starPoint.jumpCounter.plus(1),
|
|
||||||
finishStarPoint.coords
|
finishStarPoint.coords
|
||||||
)
|
)
|
||||||
|
|
||||||
if (closedList.notContains(newStarPoint.systemId64))
|
if (closedList.notContains(newStarPoint.systemId64) && newStarPoint != starPoint) {
|
||||||
openedList.smartAdd2(newStarPoint)
|
openedList.smartAdd2(newStarPoint)
|
||||||
|
isNoResult = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNoResult) {
|
||||||
|
reader.close()
|
||||||
|
findNeighbours(starPoint, jumpModifier.plus(1))
|
||||||
|
}
|
||||||
|
|
||||||
reader.close()
|
reader.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +147,7 @@ class AStarMainFile {
|
|||||||
counter++
|
counter++
|
||||||
}
|
}
|
||||||
// db.closeDB()
|
// db.closeDB()
|
||||||
println("${consoleStringCounter()} Total jumps counter = $counter, distance = $fullDistance ly, replaces = $replaces, cof = ${StarPoint.NEUTRON_COF}")
|
println("${consoleStringCounter()} Total jumps counter = ${finishStarPoint.previousStarPoint?.jumpCounter}, distance = $fullDistance ly, replaces = $replaces, cof = ${StarPoint.NEUTRON_COF}")
|
||||||
return counter
|
return counter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user