Skip to content

Commit

Permalink
added --loop option
Browse files Browse the repository at this point in the history
  • Loading branch information
tKe committed Mar 28, 2015
1 parent c277813 commit 029dcd3
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
metavar='SYSTEM',
default=None,
),
ParseArgument('--loop',
help='Return to the starting station.',
action='store_true',
default=False,
),
),
ParseArgument('--via',
help='Require specified systems/stations to be en-route.',
Expand Down Expand Up @@ -734,6 +739,9 @@ def validateRunArguments(tdb, cmdenv, calc):
if cmdenv.insurance >= (cmdenv.credits + arbitraryInsuranceBuffer):
raise CommandLineError("Insurance leaves no margin for trade")

if cmdenv.loop and cmdenv.unique:
raise CommandLineError("Cannot use --unique and --loop together")

checkOrigins(tdb, cmdenv, calc)
checkDestinations(tdb, cmdenv, calc)

Expand Down Expand Up @@ -1012,6 +1020,7 @@ def run(results, cmdenv, tdb):

pruneMod = cmdenv.pruneScores / 100

loopRoutes = []
for hopNo in range(numHops):
restrictTo = None
if hopNo == lastHop and stopStations:
Expand All @@ -1031,13 +1040,16 @@ def run(results, cmdenv, tdb):
if cmdenv.maxRoutes and len(routes) > cmdenv.maxRoutes:
routes = routes[:cmdenv.maxRoutes]

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

def canReachStopStation(r):
stopSystems = {stopStation.system
for stopStation in stopStations}
if cmdenv.loop:
stopSystems = {r.firstSystem}
else:
stopSystems = {stopStation.system
for stopStation in stopStations}
reachableSystems = [stopSystem.name()
for stopSystem in stopSystems
if r.lastSystem.distToSq(stopSystem) <= remainingDistanceSq]
Expand Down Expand Up @@ -1126,6 +1138,18 @@ def canReachStopStation(r):
routes = routes[:1]
break

if cmdenv.loop:
for route in routes:
if route.lastStation == route.firstStation:
loopRoutes.append(route)

if cmdenv.loop:
routes = loopRoutes

# normalise the scores for fairness...
for route in routes:
route.score /= len(route.hops)

if not routes:
raise NoDataError(
"No profitable trades matched your critera, "
Expand Down

0 comments on commit 029dcd3

Please sign in to comment.