Example #1
0
def loadPopForAnalysis(param, pop, caracs):
    txtpop = []
    with open('population.txt', 'r') as txt:
        for l in txt:
            txtpop.append(l)

    for i in range(len(txtpop)):
        if txtpop[i][:4] == 'nom:':

            ind = classes.indiv(param, caracs)
            ind.nom = int(txtpop[i].split()[1][:-1])
            ind.espece = int(txtpop[i].split()[9][:-1])
            ind.score = float(txtpop[i].split()[15][:-1])
            ind.classement = int(txtpop[i].split()[17])

            j = i + 1
            while txtpop[j] != '\n':

                g = classes.gene()

                g.inNode = int(txtpop[j].split()[0][:-1])
                g.outNode = int(txtpop[j].split()[1][:-1])
                g.weight = float(txtpop[j].split()[2][:-1])
                g.active = bool(txtpop[j].split()[3][:-1] == 'True')
                g.code = int(txtpop[j].split()[4])

                ind.ADN.addGene(g)

                j += 1

            pop.addIndiv(ind)
Example #2
0
def replayPopFromText(param, pop, caracs):
    txtpop = []
    with open('replay.txt', 'r') as txt:
        for l in txt:
            txtpop.append(l)

    for i in range(len(txtpop)):
        if txtpop[i][:4] == 'nom:':

            ind = classes.indiv(param, caracs)
            ind.ADN.setNbNodeInt(int(txtpop[i].split()[13][:-1]))

            j = i + 1
            while txtpop[j] != '\n':

                g = classes.gene()

                g.inNode = int(txtpop[j].split()[0][:-1])
                g.outNode = int(txtpop[j].split()[1][:-1])
                g.weight = float(txtpop[j].split()[2][:-1])
                g.active = bool(txtpop[j].split()[3][:-1] == 'True')
                g.code = int(txtpop[j].split()[4])

                ind.ADN.addGene(g)

                ind.ADN.siInLibre[g.inNode] = False
                if g.outNode < ind.ADN.encOffset:
                    ind.ADN.siOutLibre[g.outNode] = False
                else:
                    ind.ADN.siEncrLibre[g.outNode] = False
                j += 1

            ind.nom = pop.getProchNom()
            pop.addIndiv(ind)
Example #3
0
def creerPopulation(param, pop, caracs):
    for i in range(param['nbIndiv']):

        ind = classes.indiv(param, caracs)

        for connexion in range(param['connexInit']):

            g = classes.gene()

            unique = False
            while not unique:

                if connexion == 0:
                    inNode = 0
                else:
                    inNode = random.randrange(param['nbInput'])
                outNode = random.randrange(param['nbOutput'])

                if pop.arbreGen[inNode][outNode] == 0:
                    unique = True
                elif not ind.ADN.tellSiGene(pop.arbreGen[inNode][outNode]):
                    unique = True

            g.inNode = inNode
            g.outNode = outNode
            g.weight = random.uniform(-1, 1)
            g.active = True

            if pop.arbreGen[inNode][outNode] == 0:
                pop.setGeneCode(inNode, outNode)
            g.code = pop.arbreGen[inNode][outNode]

            ind.ADN.addGene(g)
            ind.ADN.siInLibre[inNode] = False
            ind.ADN.siOutLibre[outNode] = False

        ind.nom = pop.getProchNom()
        pop.addIndiv(ind)
Example #4
0
def siCreationBoucle(param, ind, inNode, outNode, caracs):
    mannequin = classes.indiv(param, caracs)
    for g in ind.ADN.seqGene:
        gmanq = classes.gene()
        g.copyTo(gmanq)
        mannequin.ADN.addGene(gmanq)

    gmanq = classes.gene()
    gmanq.inNode = inNode
    gmanq.outNode = outNode
    gmanq.active = True
    mannequin.ADN.addGene(gmanq)

    boolCreationBoucle = False

    for node in range(param['nbOutput']):
        boolCreationBoucle = boolCreationBoucle or\
         recSiBoucle(param, mannequin, node, 1)

    for encrNode in range(mannequin.ADN.encOffset, mannequin.maxOutputTotal):
        boolCreationBoucle = boolCreationBoucle or\
         recSiBoucle(param, mannequin, encrNode, 1)

    return boolCreationBoucle
Example #5
0
def creerPopulationAvecCouches(param, pop, caracs):
    for i in range(param['nbIndiv']):
        ind = classes.indiv(param, caracs)

        for transverse in range(param['transversesInit']):

            unique = False
            while not unique:

                if transverse == 0:
                    inNode = 0
                else:
                    inNode = random.randrange(param['nbInput'])
                outNode = random.randrange(param['nbOutput'])

                if pop.arbreGen[inNode][outNode] == 0:
                    unique = True
                elif not ind.ADN.tellSiGene(pop.arbreGen[inNode][outNode]):
                    unique = True

            for couche in range(param['couchesInit']):
                g = classes.gene()
                g.inNode = inNode
                g.outNode = param['nbOutput'] + ind.ADN.nbNodeInt
                g.weight = random.uniform(-1, 1)
                g.active = True

                if pop.arbreGen[g.inNode][g.outNode] == 0:
                    pop.setGeneCode(g.inNode, g.outNode)
                g.code = pop.arbreGen[g.inNode][g.outNode]

                ind.ADN.addGene(g)

                inNode = param['nbInput'] + ind.ADN.nbNodeInt
                ind.ADN.addNodeInt()

            g = classes.gene()
            g.inNode = inNode
            g.outNode = outNode
            g.weight = random.uniform(-1, 1)
            g.active = True

            if pop.arbreGen[g.inNode][g.outNode] == 0:
                pop.setGeneCode(g.inNode, g.outNode)
            g.code = pop.arbreGen[g.inNode][g.outNode]

            ind.ADN.addGene(g)

            ind.ADN.siInLibre[inNode] = False
            ind.ADN.siOutLibre[outNode] = False

        for nvlInput in range(param['inputSupInit']):
            mutation.creationInput(pop, ind)
            ind.ADN.seqGene[ind.ADN.compteGene() - 1].weight = random.uniform(
                -1, 1)

        for connexion in range(param['connexInit']):
            mutation.creationConnexion(param, pop, ind, caracs)
            ind.ADN.seqGene[ind.ADN.compteGene() - 1].weight = random.uniform(
                -1, 1)

        for encryption in range(param['encrInit']):
            mutation.creationEncryption(param, pop, ind, caracs)
            ind.ADN.seqGene[ind.ADN.compteGene() - 1].weight = random.uniform(
                -1, 1)

        for connexion in range(param['connexInit']):
            mutation.creationConnexion(param, pop, ind, caracs)
            ind.ADN.seqGene[ind.ADN.compteGene() - 1].weight = random.uniform(
                -1, 1)

        print(i)
        #for g in ind.ADN.seqGene:
        #	print(str(g.inNode) + '; ' + str(g.outNode) + '; ' + str(g.weight) + '; ' + str(g.active) + '; ' + str(g.code))

        ind.nom = pop.getProchNom()
        pop.addIndiv(ind)
Example #6
0
def seedPopFromCore(param, pop, caracs):
    txtpop = []
    with open('core.txt', 'r') as txt:
        for l in txt:
            txtpop.append(l)

    for i in range(len(txtpop)):
        if txtpop[i][:4] == 'nom:':

            ind = classes.indiv(param, caracs)
            ind.ADN.setNbNodeInt(int(txtpop[i].split()[13][:-1]))

            j = i + 1
            while txtpop[j] != '\n':

                g = classes.gene()

                g.inNode = int(txtpop[j].split()[0][:-1])
                g.outNode = int(txtpop[j].split()[1][:-1])
                g.weight = float(txtpop[j].split()[2][:-1])
                g.active = bool(txtpop[j].split()[3][:-1] == 'True')
                g.code = int(txtpop[j].split()[4])

                if pop.arbreGen[g.inNode][g.outNode] == 0:
                    pop.arbreGen[g.inNode][g.outNode] = g.code
                    if g.code > pop.prochCode:
                        pop.prochCode = g.code

                ind.ADN.addGene(g)

                ind.ADN.siInLibre[g.inNode] = False
                if g.outNode < ind.ADN.encOffset:
                    ind.ADN.siOutLibre[g.outNode] = False
                else:
                    ind.ADN.siEncrLibre[g.outNode] = False

                j += 1

            ind.nom = pop.getProchNom()
            pop.addIndiv(ind)

    for i in range(param['nbIndiv'] - 1):

        clone = classes.indiv(param, caracs)
        clone.ADN.setNbNodeInt(ind.ADN.nbNodeInt)

        for g0 in ind.ADN.seqGene:

            g = classes.gene()
            g0.copyTo(g)
            clone.ADN.addGene(g)

            clone.ADN.siInLibre[g.inNode] = False
            if g.outNode < clone.ADN.encOffset:
                clone.ADN.siOutLibre[g.outNode] = False
            else:
                clone.ADN.siEncrLibre[g.outNode] = False

        for nvlInput in range(param['inputSupInit']):
            mutation.creationInput(pop, clone)
        for nvlOutput in range(param['outputSupInit']):
            mutation.creationOutput(param, pop, clone, caracs)
        for connexion in range(param['connexInit']):
            mutation.creationConnexion(param, pop, clone, caracs)
        for encryption in range(param['encrInit']):
            mutation.creationEncryption(param, pop, clone, caracs)
        for chgtPoids in range(param['chgtPoidsInit']):
            mutation.changementPoids(clone)

        clone.nom = pop.getProchNom()
        pop.addIndiv(clone)
        print(clone.nom)