mirror of
https://github.com/Assasinnys/ED-AStar-Galaxy-Router
synced 2025-04-13 23:07:19 +03:00
init: working concept
This commit is contained in:
parent
7e7a86cab3
commit
79b5ad0ec3
@ -36,7 +36,7 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
|||||||
|
|
||||||
fun activateAStarAlgorithm() {
|
fun activateAStarAlgorithm() {
|
||||||
|
|
||||||
multithreatingFindNeighbours(startStarPoint)
|
multithreatingFindNeighbours(startStarPoint, 1)
|
||||||
|
|
||||||
openedList.remove(startStarPoint.systemId64)
|
openedList.remove(startStarPoint.systemId64)
|
||||||
closedList[startStarPoint.systemId64] = startStarPoint
|
closedList[startStarPoint.systemId64] = startStarPoint
|
||||||
@ -55,7 +55,7 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
val selectedStarPoint = findStarPointWithMinCost()
|
val selectedStarPoint = findStarPointWithMinCost()
|
||||||
multithreatingFindNeighbours(selectedStarPoint)
|
multithreatingFindNeighbours(selectedStarPoint, 1)
|
||||||
openedList.remove(selectedStarPoint.systemId64)
|
openedList.remove(selectedStarPoint.systemId64)
|
||||||
closedList[selectedStarPoint.systemId64] = selectedStarPoint
|
closedList[selectedStarPoint.systemId64] = selectedStarPoint
|
||||||
|
|
||||||
@ -86,43 +86,52 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun multithreatingFindNeighbours(starPoint: StarPoint) {
|
private fun multithreatingFindNeighbours(starPoint: StarPoint, jumpModifier: Int) {
|
||||||
val maxRange = isNeutronDistance(starPoint.isNeutronStar)
|
val maxRange = isNeutronDistance(starPoint.isNeutronStar)
|
||||||
val sql = "select $C_ID64, $C_X, $C_Y, $C_Z, $C_SUBTYPE = 'Neutron Star' as isNeutronStar, " +
|
val sql = "select $C_ID64, $C_X, $C_Y, $C_Z, $C_SUBTYPE = 'Neutron Star' as isNeutronStar, " +
|
||||||
"$C_SYS_NAME, " +
|
"$C_SYS_NAME, " +
|
||||||
"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) between 0 and $maxRange" +
|
"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))}" +
|
||||||
"and not $C_ID64=${starPoint.systemId64}"
|
"and not $C_ID64=${starPoint.systemId64}"
|
||||||
|
|
||||||
threadPool.submit {
|
// threadPool.submit {
|
||||||
findNeighbours(starPoint, sql)
|
findNeighbours(starPoint, sql, jumpModifier)
|
||||||
}.get()
|
// }.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findNeighbours(starPoint: StarPoint, sql: String) {
|
private fun findNeighbours(starPoint: StarPoint, sql: String, jumpModifier: Int) {
|
||||||
checkConnection()
|
checkConnection()
|
||||||
|
var smartAdd = false
|
||||||
|
|
||||||
val sw = Stopwatch().apply { start() }
|
val sw = Stopwatch().apply { start() }
|
||||||
val resultSet = database.query(sql)
|
val resultSet = database.query(sql)
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
with(resultSet) {
|
with(resultSet) {
|
||||||
val newStarPoint = StarPoint(
|
val isNeutronStar = getBoolean("isNeutronStar")
|
||||||
starPoint, getLong(C_ID64), Coordinates(
|
val coords = Coordinates(getDouble(C_X), getDouble(C_Y), getDouble(C_Z))
|
||||||
getDouble(C_X), getDouble(C_Y),
|
|
||||||
getDouble(C_Z)
|
|
||||||
), getBoolean("isNeutronStar"), getDouble("dist"),
|
|
||||||
getString(C_SYS_NAME), starPoint.jumpCounter.plus(1), finishStarPoint.coords
|
|
||||||
)
|
|
||||||
if (closedList.notContains(newStarPoint.systemId64)) {
|
|
||||||
openedList.smartAdd2(newStarPoint)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (isNeutronStar || coords == finishStarPoint.coords) {
|
||||||
|
val newStarPoint = StarPoint(
|
||||||
|
starPoint, getLong(C_ID64), coords,
|
||||||
|
isNeutronStar, getDouble("dist"),
|
||||||
|
getString(C_SYS_NAME), starPoint.jumpCounter.plus(1), finishStarPoint.coords
|
||||||
|
)
|
||||||
|
if (closedList.notContains(newStarPoint.systemId64)) {
|
||||||
|
openedList.smartAdd2(newStarPoint)
|
||||||
|
smartAdd = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resultSet.close()
|
resultSet.close()
|
||||||
sw.stopWithConsoleOutput("Process time: ")
|
sw.stopWithConsoleOutput("Process time: ")
|
||||||
|
|
||||||
|
if (!smartAdd) {
|
||||||
|
multithreatingFindNeighbours(starPoint, jumpModifier.plus(1))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isNeutronDistance(isNeutron: Boolean) = if (isNeutron) NEUTRON_DISTANCE else USUAL_DISTANCE
|
private fun isNeutronDistance(isNeutron: Boolean) = if (isNeutron) NEUTRON_DISTANCE else USUAL_DISTANCE
|
||||||
@ -234,7 +243,7 @@ class AStarMain(private val startSystem: String, private val finishSystem: Strin
|
|||||||
)
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val CORRIDOR = "main"
|
const val CORRIDOR = "coridor3"
|
||||||
const val NEUTRON_DISTANCE = 240
|
const val NEUTRON_DISTANCE = 240
|
||||||
const val USUAL_DISTANCE = 60
|
const val USUAL_DISTANCE = 60
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class StarPoint(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val DISTANCE_MODIFIER = 100
|
const val DISTANCE_MODIFIER = 100
|
||||||
const val NEUTRON_COF = 340 // Default
|
const val NEUTRON_COF = 0 // Default
|
||||||
}
|
}
|
||||||
|
|
||||||
// division
|
// division
|
||||||
|
Loading…
x
Reference in New Issue
Block a user