Update cable heuristics
This commit is contained in:
parent
3f87459f35
commit
8544368ab2
@ -3,15 +3,12 @@ package ru.dbotthepony.mc.otm.block.entity.cable
|
|||||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
|
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
|
||||||
import it.unimi.dsi.fastutil.objects.ReferenceArraySet
|
import it.unimi.dsi.fastutil.objects.ReferenceArraySet
|
||||||
import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet
|
import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet
|
||||||
import net.minecraft.core.BlockPos
|
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.mc.otm.SERVER_IS_LIVE
|
import ru.dbotthepony.mc.otm.SERVER_IS_LIVE
|
||||||
import ru.dbotthepony.mc.otm.UNIVERSE_TICKS
|
import ru.dbotthepony.mc.otm.UNIVERSE_TICKS
|
||||||
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
||||||
import ru.dbotthepony.mc.otm.config.CablesConfig
|
import ru.dbotthepony.mc.otm.config.CablesConfig
|
||||||
import ru.dbotthepony.mc.otm.core.addAll
|
|
||||||
import ru.dbotthepony.mc.otm.core.collect.map
|
import ru.dbotthepony.mc.otm.core.collect.map
|
||||||
import ru.dbotthepony.mc.otm.core.collect.max
|
|
||||||
import ru.dbotthepony.mc.otm.core.collect.reduce
|
import ru.dbotthepony.mc.otm.core.collect.reduce
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.RelativeSide
|
import ru.dbotthepony.mc.otm.core.math.RelativeSide
|
||||||
@ -493,17 +490,18 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
val maxSearches = CablesConfig.SEARCHES_PER_TICK
|
val maxSearches = CablesConfig.SEARCHES_PER_TICK
|
||||||
|
|
||||||
if (!list.saturated && lastTickSearches <= maxSearches) {
|
if (!list.saturated && lastTickSearches <= maxSearches) {
|
||||||
var maxThroughput = list.paths.iterator().map { it.availableThroughput }.reduce(Decimal.ZERO, Decimal::plus)
|
var maxThroughput = list.paths.maxOfOrNull { it.availableThroughput } ?: Decimal.ZERO
|
||||||
|
var combinedThroughput = list.paths.iterator().map { it.availableThroughput }.reduce(Decimal.ZERO, Decimal::plus)
|
||||||
|
|
||||||
while (maxThroughput < energyToTransfer && !list.saturated && ++lastTickSearches <= maxSearches) {
|
while (combinedThroughput < energyToTransfer && !list.saturated && ++lastTickSearches <= maxSearches) {
|
||||||
// TODO: Heuristics here is wrong
|
|
||||||
val find = findPath(a, b, list.paths, maxThroughput)
|
val find = findPath(a, b, list.paths, maxThroughput)
|
||||||
|
|
||||||
if (find == null || find in list.paths) {
|
if (find == null || find in list.paths) {
|
||||||
list.saturated = true
|
list.saturated = true
|
||||||
} else {
|
} else {
|
||||||
list.paths.add(find)
|
list.paths.add(find)
|
||||||
maxThroughput += find.availableThroughput
|
combinedThroughput += find.availableThroughput
|
||||||
|
maxThroughput = maxOf(maxThroughput, find.availableThroughput)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,7 +523,6 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
|
|
||||||
node.segment.paths.forEach {
|
node.segment.paths.forEach {
|
||||||
pathCache.remove(it.a to it.b)
|
pathCache.remove(it.a to it.b)
|
||||||
pathCache.remove(it.b to it.a)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node.segment.paths = ReferenceLinkedOpenHashSet()
|
node.segment.paths = ReferenceLinkedOpenHashSet()
|
||||||
|
Loading…
Reference in New Issue
Block a user