Exemplo n.º 1
0
    public NEAT LoadBrain()
    {
        NEAT network = new NEAT(0, 0);

        network.SetSize(inputs, outputs);

        //create all nodes
        for (int i = 0; i < floatNodes.Length; i += 5)
        {
            Node current = new Node((int)floatNodes[i + 1], (int)floatNodes[i], (NodeType)(int)floatNodes[i + 2]);
            current.activation = floatNodes[i + 3];
            current.sum        = floatNodes[i + 4];
            network.AddNode(current);
        }

        //create all connections
        for (int i = 0; i < floatConnections.Length; i += 5)
        {
            bool       enable  = floatConnections[i + 3] == 1 ? true : false;
            Connection current = new Connection((int)floatConnections[i], (int)floatConnections[i + 1], floatConnections[i + 2], enable, (int)floatConnections[i + 4]);
            Debug.Log(current.inNode + "Innode id, " + current.outNode + "outnode id, " + current.weight + "weight, " + current.innovation + "innovation");
            network.AddConnection(current);
        }

        //add all connections to nodes
        foreach (var connection in network.GetConnetionGenom())
        {
            Node currentNode = network.GetNodeGenom().Find(x => x.nodeID == connection.inNode);
            if (currentNode != null)
            {
                currentNode.AddConnection(connection);
            }
        }

        network.SetInnovation(innovation);

        return(network);
    }