@@ -69,11 +69,6 @@ def __init__(self, ID, dbname, posX, posY, posZ):
69
69
self .stations = []
70
70
71
71
72
- @staticmethod
73
- def linkSystems (lhs , rhs , distSq ):
74
- lhs .links [rhs ] = rhs .links [lhs ] = math .sqrt (distSq )
75
-
76
-
77
72
def addStation (self , station ):
78
73
if not station in self .stations :
79
74
self .stations .append (station )
@@ -116,6 +111,7 @@ def getDestinations(self, maxJumps=None, maxLyPer=None, avoiding=None):
116
111
avoiding = avoiding or []
117
112
maxJumps = maxJumps or sys .maxsize
118
113
maxLyPer = maxLyPer or float ("inf" )
114
+ maxLyPerSq = maxLyPer ** 2
119
115
120
116
# The open list is the list of nodes we should consider next for
121
117
# potential destinations.
@@ -124,13 +120,13 @@ def getDestinations(self, maxJumps=None, maxLyPer=None, avoiding=None):
124
120
# The closed list is the list of nodes we've already been to (so
125
121
# that we don't create loops A->B->C->A->B->C->...)
126
122
127
- Node = namedtuple ('Node' , [ 'system' , 'via' , 'distLy ' ])
123
+ Node = namedtuple ('Node' , [ 'system' , 'via' , 'distLySq ' ])
128
124
129
125
openList = [ Node (self .system , [], 0 ) ]
130
- pathList = { system .ID : Node (system , None , 0 .0 )
126
+ pathList = { system .ID : Node (system , None , - 1 .0 )
131
127
# include avoids so we only have
132
128
# to consult one place for exclusions
133
- for system in avoiding + [ self ]
129
+ for system in avoiding
134
130
# the avoid list may contain stations,
135
131
# which affects destinations but not vias
136
132
if isinstance (system , System ) }
@@ -146,18 +142,18 @@ def getDestinations(self, maxJumps=None, maxLyPer=None, avoiding=None):
146
142
jumps += 1
147
143
148
144
for node in ring :
149
- for (destSys , destDist ) in node .system .links .items ():
150
- if destDist > maxLyPer : continue
151
- dist = node .distLy + destDist
145
+ for (destSys , destDistSq ) in node .system .links .items ():
146
+ if destDistSq > maxLyPerSq : continue
147
+ distSq = node .distLySq + destDistSq
152
148
# If we already have a shorter path, do nothing
153
149
try :
154
- if dist >= pathList [destSys .ID ].distLy : continue
150
+ if distSq >= pathList [destSys .ID ].distLySq : continue
155
151
except KeyError : pass
156
152
# Add to the path list
157
- pathList [destSys .ID ] = Node (destSys , node .via , dist )
153
+ pathList [destSys .ID ] = Node (destSys , node .via , distSq )
158
154
# Add to the open list but also include node to the via
159
155
# list so that it serves as the via list for all next-hops.
160
- openList += [ Node (destSys , node .via + [destSys ], dist ) ]
156
+ openList += [ Node (destSys , node .via + [destSys ], distSq ) ]
161
157
162
158
Destination = namedtuple ('Destination' , [ 'system' , 'station' , 'via' , 'distLy' ])
163
159
@@ -173,10 +169,10 @@ def getDestinations(self, maxJumps=None, maxLyPer=None, avoiding=None):
173
169
avoidStations = [ station for station in avoiding if isinstance (station , Station ) ]
174
170
epsilon = sys .float_info .epsilon
175
171
for node in pathList .values ():
176
- if node .distLy > epsilon : # Values indistinguishable from zero are avoidances
172
+ if node .distLySq >= 0.0 : # Values indistinguishable from zero are avoidances
177
173
for station in node .system .stations :
178
174
if not station in avoidStations :
179
- destStations += [ Destination (node .system , station , [self .system ] + node .via + [station .system ], node .distLy ) ]
175
+ destStations += [ Destination (node .system , station , [self .system ] + node .via + [station .system ], math . sqrt ( node .distLySq ) ) ]
180
176
181
177
return destStations
182
178
@@ -468,8 +464,8 @@ def buildLinks(self):
468
464
dX , dY , dZ = rhs .posX - lhs .posX , rhs .posY - lhs .posY , rhs .posZ - lhs .posZ
469
465
distSq = (dX * dX ) + (dY * dY ) + (dZ * dZ )
470
466
if distSq <= longestJumpSq :
471
- System . linkSystems ( lhs , rhs , distSq )
472
- self .numLinks += 1
467
+ lhs . links [ rhs ] = rhs . links [ lhs ] = distSq
468
+ self .numLinks += 1
473
469
474
470
if self .debug > 2 : print ("# Number of links between systems: %d" % self .numLinks )
475
471
0 commit comments