Exemplo n.º 1
0
def deltheworst_clonethebest(population, action, MODlimit, ID=None):
    POP_SCORETABLE = []
    MEDIUMSCORE = 0
    VALIDPOP = 0
    REMOVED = []
    for k in range(len(population)):
        if population[k].PARAMETERS[0].value == 0:
            POP_SCORETABLE.append(-1)
            continue
        SCORE = population[k].ELO

        POP_SCORETABLE.append(SCORE)
        MEDIUMSCORE += SCORE
        VALIDPOP += 1

    if VALIDPOP > 0:
        MEDIUMSCORE = MEDIUMSCORE / VALIDPOP
        print('mediumscore = %i' % MEDIUMSCORE)
        if action < 0:
            action = -action

            for D in range(action):
                CURRENT_SCORE = [0, 66666]
                for k in range(len(population)):
                    if population[k] != 0:
                        if (population[k].ELO > -1):
                            if (population[k].ELO < MEDIUMSCORE * MODlimit):
                                if population[k].ELO < CURRENT_SCORE[1]:
                                    CURRENT_SCORE[0] = k
                                    CURRENT_SCORE[1] = population[k].ELO

                try:
                    delname = population[CURRENT_SCORE[0]].filename
                    print("subject deleted. %s" % delname)
                    bareDeleteMachine(machine_dir, delname)
                except AttributeError:
                    print("ERROR on Delete the Worst/Clone the Best")
                    pass
                """try:
                    os.remove(machine_dir+'/'+population[CURRENT_SCORE[0]].filename)
                except FileNotFoundError:
                    print("can't find machine file, but it's ok.")"""
                population[CURRENT_SCORE[0]] = 0
                population = [x for x in population if x != 0]

        elif action > 0:
            NEWINDS = []
            for k in range(len(POP_SCORETABLE)):
                if (POP_SCORETABLE[k] > MEDIUMSCORE * 1.1):
                    print('subject cloned. ' + population[k].filename)
                    NEWINDS.append(population[k])
                    NEWINDS[-1].filename = NewMacName(ID=ID)

            mutatemachines(6, NEWINDS)
            for I in NEWINDS:
                population.append(I)

    return population
Exemplo n.º 2
0
def deltheworst_clonethebest(population, action, MODlimit, ID=None):
    INFINITE = 6669990001
    POP_SCORETABLE = []
    MEDIUMSCORE = 0
    VALIDPOP = 0
    REMOVED = []
    for k in range(len(population)):
        if population[k].PARAMETERS[0].value == 0:
            POP_SCORETABLE.append(-1)
            continue
        SCORE = population[k].ELO

        POP_SCORETABLE.append(SCORE)
        MEDIUMSCORE += SCORE
        VALIDPOP += 1

    if VALIDPOP > 0:
        MEDIUMSCORE = MEDIUMSCORE / VALIDPOP
        print('mediumscore = %i' % MEDIUMSCORE)
        if action < 0:
            action = -action

            for D in range(action):
                CURRENT_SCORE = [0, INFINITE]
                for k in range(len(population)):
                    if population[k] != 0:
                        if (population[k].ELO > -1):
                            if (population[k].ELO < MEDIUMSCORE * MODlimit):
                                if population[k].ELO < CURRENT_SCORE[1]:
                                    CURRENT_SCORE[0] = k
                                    CURRENT_SCORE[1] = population[k].ELO

                try:
                    delname = population[CURRENT_SCORE[0]].filename
                    print("subject deleted. %s" % delname)
                    bareDeleteMachine(settings.machineDIR, delname)
                except AttributeError:
                    print("ERROR on Delete the Worst/Clone the Best")
                    pass

                population[CURRENT_SCORE[0]] = 0
                population = [x for x in population if x != 0]

        elif action > 0:
            NEWINDS = []
            for k in range(len(POP_SCORETABLE)):
                if (POP_SCORETABLE[k] > MEDIUMSCORE * 1.1):
                    print('subject cloned. ' + population[k].filename)
                    NEWINDS.append(population[k])
                    NEWINDS[-1].filename = NewMacName(ID=ID)

            mutatemachines(6, NEWINDS)
            for I in NEWINDS:
                population.append(I)

    return population
Exemplo n.º 3
0
 def KillEmAllCheckDead(self, Score, Round):
     for MACHINE in range(len(Round)):
         if Score[1-MACHINE] - Score[MACHINE] >= 2:
             deadmac = Round[MACHINE]
             self.log("%s dies. [%i]" % (deadmac.filename,
                 deadmac.ELO))
             try:
                 self.Competitors.pop(self.Competitors.index(deadmac))
             except:
                 print("Tried to kill %s but it's already deleted." % deadmac.filename)
                 return
             bareDeleteMachine(settings.TOPmachineDIR, deadmac.filename)
             
             print("%s dies." % deadmac.filename)
             self.TotalDead += 1
Exemplo n.º 4
0
    def KillEmAllCheckDead(self, Score, Round):
        for MACHINE in range(len(Round)):
            if Score[1 - MACHINE] - Score[MACHINE] >= 2:
                deadmac = Round[MACHINE]
                self.log("%s dies. [%i]" % (deadmac.filename, deadmac.ELO))
                try:
                    self.Competitors.pop(self.Competitors.index(deadmac))
                except:
                    print("Tried to kill %s but it's already deleted." %
                          deadmac.filename)
                    return
                bareDeleteMachine(settings.HoFmachineDIR, deadmac.filename)

                print("%s dies." % deadmac.filename)
                self.TotalDead += 1
Exemplo n.º 5
0
def EliminateEquals(population, Range, delete=True):
    blacklist = []
    for I in range(Range, len(population)):
        if population[I] == 0:
            continue
        for T in range(I + 1, len(population)):
            if population[T] == 0:
                continue
            if IsEqual(population[I], population[T]):
                blacklist.append(population[T].filename)
                population[T] = 0
    if delete:
        for Name in blacklist:
            bareDeleteMachine(settings.machineDIR, Name)

    return list(filter((0).__ne__, population))
Exemplo n.º 6
0
    def DeleteLosers(self):
        for machine in self.Competitors:
            print("%s: %s" % (machine.filename, machine.TournamentScore))

        self.Deaths = 1 if not self.Deaths else self.Deaths

        for k in range(self.Deaths):
            Worst = ["", 666]

            for K in self.Competitors:
                if K.TournamentScore < Worst[1]:
                    Worst[0] = K.filename
                    Worst[1] = K.TournamentScore


            print("Deleting %s; %i points." % (Worst[0], Worst[1]))

            bareDeleteMachine(settings.TOPmachineDIR, Worst[0])
            self.Competitors = [
                    x for x in self.Competitors if x.filename != Worst[0] ]
            self.TotalDead += 1
Exemplo n.º 7
0
    def DeleteLosers(self):
        for machine in self.Competitors:
            print("%s: %s" % (machine.filename, machine.TournamentScore))

        self.Deaths = 1 if not self.Deaths else self.Deaths

        for k in range(self.Deaths):
            Worst = ["", 666]

            for K in self.Competitors:
                if K.TournamentScore < Worst[1]:
                    Worst[0] = K.filename
                    Worst[1] = K.TournamentScore

            print("Deleting %s; %i points." % (Worst[0], Worst[1]))

            bareDeleteMachine(settings.HoFmachineDIR, Worst[0])
            self.Competitors = [
                x for x in self.Competitors if x.filename != Worst[0]
            ]
            self.TotalDead += 1
Exemplo n.º 8
0
        ]))
        pop = core.loadmachines(DIR=_machineDIR)
        if result:
            for scoreNumber in range(1,
                                     round(max([result[x] for x in result]))):
                for MAC in ApprovedMachines:
                    #if scoreNumber < result[MAC] < scoreNumber +1: # ?????????????
                    print("%s: %i" % (MAC, result[MAC]))

            BestScoreOnGroup = max([result[x] for x in ApprovedMachines])
            NumberOfBestScorers = sum(
                [1 for x in ApprovedMachines if result[x] == BestScoreOnGroup])
            for IND in range(len(pop)):
                NAME = pop[IND].filename
                if NAME not in ApprovedMachines or result[NAME] < 0:
                    management.bareDeleteMachine(_machineDIR, NAME)
                    print("Deleting machine %s." % NAME)
                    pop[IND] = None
            pop = [x for x in pop if x]

            for IND in pop:
                #if FullTestLen * 10 - result[IND.filename] < 20:
                #    core.sendtoHallOfFame(IND)
                if result[IND.filename] == BestScoreOnGroup:
                    if NumberOfBestScorers < len(pop) / 6:
                        core.Mate([IND, random.choice(pop)], 2, ID="POS")

        if options.Mutate:
            stock_popsize = 16
            while len(pop) < stock_popsize / 2 and pop:
                pop += core.Mate(pop, 2, ID="pos")