Skip to content

Commit

Permalink
Raise NoHopsError when getBestHops is asked to find routes with no re…
Browse files Browse the repository at this point in the history
…achable destinations
  • Loading branch information
Oliver Smith committed Mar 3, 2015
1 parent 786a7c7 commit ea4f74f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tradecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def __str__(self):
)


class NoHopsError(TradeException):
pass

######################################################################
# Stuff that passes for classes (but isn't)

Expand Down Expand Up @@ -805,6 +808,7 @@ def station_iterator(srcStation):
)

prog = pbar.Progress(len(routes), 25)
connections = 0
getSelling = self.stationsSelling.get
for route in routes:
if tdenv.progress:
Expand Down Expand Up @@ -899,6 +903,8 @@ def considerStation(dstStation, dest, multiplier):
if reqBlackMarket and dstStation.blackMarket != 'Y':
continue

connections += 1

if maxAge:
stnDataAge = dstStation.dataAge
if stnDataAge is None or stnDataAge > maxAge:
Expand Down Expand Up @@ -948,6 +954,11 @@ def considerStation(dstStation, dest, multiplier):

prog.clear()

if connections == 0:
raise NoHopsError(
"No destinations could be reached within the constraints."
)

result = []
for (dst, route, trade, jumps, ly, score) in bestToDest.values():
result.append(route.plus(dst, trade, jumps, score))
Expand Down

0 comments on commit ea4f74f

Please sign in to comment.