Ejemplo n.º 1
0
    public void AddNodeMutation()
    {
        ConnectionGene connection = connections.ElementAt(rand.Next(0, connections.Count)).Value;

        NodeGene inNode  = nodes[connection.getInNode()];
        NodeGene outNode = nodes[connection.getOutNode()];

        connection.Disable();

        //NodeGene newNode = new NodeGene(NodeGene.TYPE.HIDDEN, nodes.Count + 1);
        NodeGene       newNode  = new NodeGene(NodeGene.TYPE.HIDDEN, History.NodeInnovate());
        ConnectionGene inToNew  = new ConnectionGene(inNode.getId(), newNode.getId(), 1f, true, History.Innovate());
        ConnectionGene newToOut = new ConnectionGene(newNode.getId(), outNode.getId(), connection.getWeight(), true, History.Innovate());

        nodes.Add(newNode.getId(), newNode);
        //connections.Add(inToNew.getInnovation(), inToNew);
        //connections.Add(newToOut.getInnovation(), newToOut);
        AddConnectionGene(inToNew);
        AddConnectionGene(newToOut);

        //newNode.AddInNode(GetNodes()[inToNew.getInNode()]);
        //GetNodes()[newToOut.getOutNode()].AddInNode(newNode);

        // remove old in-node from out gene
        outNode.RemoveInNode(inNode);
    }
Ejemplo n.º 2
0
 public void AddConnectionGene(ConnectionGene gene)
 {
     connections.Add(gene.getInnovation(), gene);
     GetNodes()[gene.getOutNode()].AddInNode(GetNodes()[gene.getInNode()], gene);
 }