Skip to content

Commit

Permalink
add pruning based on distance from any defined stopStations
Browse files Browse the repository at this point in the history
if there isn't enough jumps to reach any of the destinations, there's no point in continuing with that route.
  • Loading branch information
tKe committed Mar 28, 2015
1 parent b19113d commit c277813
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,29 @@ def run(results, cmdenv, tdb):
if cmdenv.maxRoutes and len(routes) > cmdenv.maxRoutes:
routes = routes[:cmdenv.maxRoutes]

if cmdenv.destPlace:
remainingDistance = (numHops - hopNo) * cmdenv.maxJumpsPer * cmdenv.maxLyPer
remainingDistanceSq = remainingDistance * remainingDistance

def canReachStopStation(r):
stopSystems = {stopStation.system
for stopStation in stopStations}
reachableSystems = [stopSystem.name()
for stopSystem in stopSystems
if r.lastSystem.distToSq(stopSystem) <= remainingDistanceSq]
if len(reachableSystems):
cmdenv.DEBUG1("Route {} can still reach: {}", r.str(), ', '.join(reachableSystems))
return True
else:
cmdenv.DEBUG1("Route {} too far from all end stations", r.str())
return False

preCrop = len(routes)
routes[:] = [x for x in routes if canReachStopStation(x)]
pruned = preCrop - len(routes)
if pruned:
cmdenv.NOTE("Pruned {} origins too far from any end stations", pruned)

if cmdenv.progress:
print("* Hop {:3n}: {:.>10n} origins".format(hopNo+1, len(routes)))
elif cmdenv.debug:
Expand Down

0 comments on commit c277813

Please sign in to comment.