Skip to content

Commit

Permalink
Fix for distance calculations that broke in 4.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Oct 27, 2014
1 parent 3892ff0 commit 5414236
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def getDestinations(self, maxJumps=None, maxLyPer=None, avoiding=None):
avoiding = avoiding or []
maxJumps = maxJumps or sys.maxsize
maxLyPer = maxLyPer or float("inf")
maxLyPerSq = maxLyPer ** 2

# The open list is the list of nodes we should consider next for
# potential destinations.
Expand All @@ -120,7 +119,7 @@ def getDestinations(self, maxJumps=None, maxLyPer=None, avoiding=None):
# The closed list is the list of nodes we've already been to (so
# that we don't create loops A->B->C->A->B->C->...)

Node = namedtuple('Node', [ 'system', 'via', 'distLySq' ])
Node = namedtuple('Node', [ 'system', 'via', 'distLy' ])

openList = [ Node(self.system, [], 0) ]
pathList = { system.ID: Node(system, None, -1.0)
Expand All @@ -142,18 +141,18 @@ def getDestinations(self, maxJumps=None, maxLyPer=None, avoiding=None):
jumps += 1

for node in ring:
for (destSys, destDistSq) in node.system.links.items():
if destDistSq > maxLyPerSq: continue
distSq = node.distLySq + destDistSq
for (destSys, destDist) in node.system.links.items():
if destDist > maxLyPer: continue
dist = node.distLy + destDist
# If we already have a shorter path, do nothing
try:
if distSq >= pathList[destSys.ID].distLySq: continue
if dist >= pathList[destSys.ID].distLy: continue
except KeyError: pass
# Add to the path list
pathList[destSys.ID] = Node(destSys, node.via, distSq)
pathList[destSys.ID] = Node(destSys, node.via, dist)
# Add to the open list but also include node to the via
# list so that it serves as the via list for all next-hops.
openList += [ Node(destSys, node.via + [destSys], distSq) ]
openList += [ Node(destSys, node.via + [destSys], dist) ]

Destination = namedtuple('Destination', [ 'system', 'station', 'via', 'distLy' ])

Expand All @@ -169,10 +168,10 @@ def getDestinations(self, maxJumps=None, maxLyPer=None, avoiding=None):
avoidStations = [ station for station in avoiding if isinstance(station, Station) ]
epsilon = sys.float_info.epsilon
for node in pathList.values():
if node.distLySq >= 0.0: # Values indistinguishable from zero are avoidances
if node.distLy >= 0.0: # Values indistinguishable from zero are avoidances
for station in node.system.stations:
if not station in avoidStations:
destStations += [ Destination(node.system, station, [self.system] + node.via + [station.system], math.sqrt(node.distLySq)) ]
destStations += [ Destination(node.system, station, [self.system] + node.via + [station.system], node.distLy) ]

return destStations

Expand Down

0 comments on commit 5414236

Please sign in to comment.