I'm trying to get Culturally Linked Starts to work on Mac. Mac BTS uses Python 2.3.5, which lacks some of the sorting functionality/formatting of 2.4 and later versions, sorted() in particular. The line below in bold is the one throwing an error and I'm not sure how to fix it in this situation:
Anyone able to help me rewrite that line in a 2.3.5 compatible way? I've learned how to fix some of these issues myself (thanks to several people here!) but this one I'm at a bit of a loss on.
Code:
def runAntColonyOptimization():
# constants
# NUM_RUNS = 50
# NUM_ANTS = 250
# NUM_BEST_ANTS = 5
# PHEROMON_UPDATE = 0.025
NUM_ANTS = iNumPlayers
NUM_BEST_ANTS = int(iNumPlayers / 10)
NUM_RUNS = iNumPlayers * 25
PHEROMON_UPDATE = 0.34 / iNumPlayers
# the best ant (permutation, error) we know
TheBestAnt = (None, 'inf')
# uniformly distributed pheromon at the beginning
fPheromonMatrix = SquareMatrix(iNumPlayers, 1 / iNumPlayers)
# the actual ACO:
for iRun in xrange(NUM_RUNS):
ants = {}
# get some random ants:
for i in xrange(NUM_ANTS):
permutation = randomList(iPlayersList, fPheromonMatrix)
error = evaluatePermutation(permutation)
ants[error] = permutation
bestants = []
# get the x best ants (smallest error):
[B]for error in sorted(ants)[:NUM_BEST_ANTS]:[/B]
ant = (ants[error], error)
bestants.append(ant)
# check if we have a new TheBestAnt:
if bestants[0][1] < TheBestAnt[1]:
TheBestAnt = bestants[0]
print "%s %.8f (%d)" % (TheBestAnt[0], TheBestAnt[1], iRun)
# let the x best ants update the pheromon matrix:
for i, pos in enumerate(fPheromonMatrix):
for ant in bestants:
value = ant[0][i]
fPheromonMatrix[i][value] = pos[value] + PHEROMON_UPDATE
# total probability for each pos has to be one:
fPheromonMatrix[i] = ScaleList(fPheromonMatrix[i])
return TheBestAnt
Anyone able to help me rewrite that line in a 2.3.5 compatible way? I've learned how to fix some of these issues myself (thanks to several people here!) but this one I'm at a bit of a loss on.