示例#1
0
    def mutateAddNode(self):
        newNode = THGene.THNodeGene(0, "Hidden", False, False)

        connIndex = random.randint(0, self.numConns - 1)
        existingConn = self.connGenes[connIndex]
        self.connGenes[connIndex].disable()  #disable existing conn

        # add new incoming nodes
        #newNode.incoming.append(self.connGenes[connIndex].input)
        #self.connGenes[connIndex].output.incoming.append(newNode)
        self.addNodeGene(newNode)  #append the newNodeGene

        print("MUTATE LOCALID BELOW")
        print(newNode.localID)

        # create 2 new ConnGenes
        newInputConn = THGene.THConnGene(existingConn.input, newNode,
                                         existingConn.weight, True)
        newOutputConn = THGene.THConnGene(newNode, existingConn.output, 1,
                                          True)

        self.addConnGene(newInputConn)
        self.addConnGene(newOutputConn)

        self.fitness = 0
示例#2
0
def generateNodes(width, length):
    #nodes = []

    right = THGene.THNodeGene(0, "right", False, True)
    #nodes.append(right)
    NNDatabase.outputs.append(right)

    left = THGene.THNodeGene(1, "left", False, True)
    #nodes.append(left)
    NNDatabase.outputs.append(left)

    up = THGene.THNodeGene(2, "up", False, True)
    #nodes.append(up)
    NNDatabase.outputs.append(up)

    down = THGene.THNodeGene(3, "down", False, True)
    #nodes.append(down)
    NNDatabase.outputs.append(down)

    none = THGene.THNodeGene(4, "idle", False, True)
    NNDatabase.outputs.append(none)

    # from [0][0] to [83][97]
    for i in range(0, width):
        lNodes = []
        for j in range(0, length):
            newGene = THGene.THNodeGene(i, "input", True, False)
            newGene.screenPosX = i
            newGene.screenPosY = j
            lNodes.append(newGene)
            #nodes.append(newGene)
        #print(len(lNodes))
        NNDatabase.inputs.append(lNodes)
from Controller import Controller
from NEATAlgorithm import GeneratePopulation
from NEATAlgorithm import THNetwork
from NEATAlgorithm import THGene
from NNData import NNDatabase

GeneratePopulation.generateNodes(84, 98)

testNetwork = THNetwork.THNetwork(0, 0)

#create nodes
input1 = NNDatabase.inputs[10][35]
input2 = NNDatabase.inputs[53][65]
input3 = NNDatabase.inputs[61][45]

hidden1 = THGene.THNodeGene(0, "hidden", False, False)

output1 = NNDatabase.outputs[3]
output2 = NNDatabase.outputs[0]

#add nodes
testNetwork.addNodeGene(input1)
testNetwork.addNodeGene(input2)
testNetwork.addNodeGene(input3)
testNetwork.addNodeGene(output1)
testNetwork.addNodeGene(hidden1)
testNetwork.addNodeGene(output2)

#create conns
conn1 = THGene.THConnGene(testNetwork.nodeGenes[0], testNetwork.nodeGenes[3],
                          0.7, True)