def fileRead(self,fname): heroDict = heroes() clusterFile = open(fname) self.cost = float(clusterFile.readline().split('\n')[0]) self.num_cluster = int(clusterFile.readline().split('\n')[0]) fileLine = clusterFile.readline().split('\n')[0] while fileLine != '': try: clust = int(fileLine) except ValueError: self.cluster[heroDict[fileLine]-1] = clust fileLine = clusterFile.readline().split('\n')[0]
def fileWrite(self,fname): heroDict = heroes() heroIndDict = {ind-1:key for key,ind in heroDict.items()} clusterFile = open(fname,'w') clusterFile.write(str(self.cost) + '\n') clusterFile.write(str(self.num_cluster) + '\n') for i in range(self.num_cluster): clusterFile.write(str(i) + '\n') for j in range(self.maxHero): if self.cluster[j] == i: try: clusterFile.write(heroIndDict[j] + '\n') except KeyError: pass clusterFile.close()
def __init__(self, num_cluster): ''' Constructor ''' self.maxHero = 112 self.num_cluster = num_cluster self.cluster = [int(random.random()*num_cluster) for x in range(self.maxHero)] self.baseStats = [logit(x) for x in loadStats('baseStats.csv')[0]] allyStats = loadStats('allyStats.csv') self.groupStat = [] for i in range(self.maxHero): tempStat = [] for j in range(i): tempStat.append(logit(allyStats[i][j]) - self.baseStats[i] - self.baseStats[j]) self.groupStat.append(tempStat) self.cost = self.clusterCost() self.heroIndDict = {ind-1:key for key,ind in heroes().items()}