Skip to content

Commit

Permalink
Incremental enhancements to jump limits
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Aug 11, 2014
1 parent 71c84bd commit 1569462
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run(dst=None, stn=None, cr=None, cap=None, maxJumps=None, maxLy=None):
return calc.getBestHopFrom(srcStn, withCr, capacity=cap, maxJumps=None, maxLy=None)
dstStn = dst if isinstance(dst, Station) else tdb.getStation(dst)
print(srcStn, dstStn, withCr, cap)
return calc.getBestTrade(srcStn, dstStn, withCr, capacity=cap)
return calc.getBestTrade(srcStn, dstStn, withCr, capacity=cap, maxJumps=maxJumps, maxLy=maxLy)

def links(stn=None, maxJumps=None, maxLy=None):
srcStn = stn if stn else curStation
Expand All @@ -39,3 +39,32 @@ def links(stn=None, maxJumps=None, maxLy=None):
srcStn = tdb.getStation(srcStn)
return srcStn.stations.getDestinations(maxJumps=maxJumps, maxLy=maxLy)

def routes(maxHops=2, stn=None, cr=None, cap=None, maxJumps=None, maxLy=None, maxRoutes=1, maxJumpsPer=None):
global calc
srcStn = stn if stn else curStation
withCr = cr if cr else curCredits
routes = [ Route([srcStn], [], withCr, 0, 0) ]
lastHop = numHops - 1

print("From %s via %s to %s with %d credits for %d hops" % (srcStn, "None", "Any", withCr, numHops))

for hopNo in range(numHops):
if calc.debug: print("# Hop %d" % hopNo)
restrictTo = None
# if hopNo == 0 and viaStation:
# restrictTo = viaStation
# elif hopNo == lastHop:
# restrictTo = finalStation
# if viaStation:
# # Cull to routes that include the viaStation
# routes = [ route for route in routes if viaStation in route.route[1:] ]
routes = calc.getBestHops(routes, withCr, restrictTo=restrictTo, maxJumps=maxJumps, maxJumpsPer=maxJumpsPer, maxLy=maxLy)

if not routes:
print("No routes match your selected criteria.")
return

routes.sort()

for i in range(0, min(len(routes), maxRoutes)):
print(routes[i])
4 changes: 2 additions & 2 deletions tradecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ def getBestHops(self, routes, credits, restrictTo=None, maxJumps=None, maxLy=Non
bestToDest = {}
safetyMargin = 1.0 - self.margin
unique = self.unique
perJumpLimit = maxJumpsPer if maxJumpsPer > 0 else 0
perJumpLimit = maxJumpsPer if (maxJumpsPer or 0) > 0 else 0
for route in routes:
src = route.route[-1]
startCr = credits + int(route.gainCr * safetyMargin)
routeJumps = route.jumps
jumpLimit = perJumpLimit
if maxJumps and maxJumps > 0:
if (maxJumps or 0) > 0:
jumpLimit = min(maxJumps - routeJumps, perJumpLimit) if perJumpLimit > 0 else maxJumps - routeJumps
if jumpLimit == 0:
continue
Expand Down

0 comments on commit 1569462

Please sign in to comment.