예제 #1
0
    public void MutateAgent_Weight_Test()
    {
        MutationLog mutationLog = new MutationLog();

        AgentObject customAgent = new CustomAgent(populationManager, parent2Genome, 10);

        Assert.AreEqual(6, customAgent.Genome.Nodes.Count);
        Assert.AreEqual(9, customAgent.Genome.Connections.Count);

        Dictionary <int, double> weights = new Dictionary <int, double>();

        foreach (int key in customAgent.Genome.Connections.Keys)
        {
            weights.Add(key, customAgent.Genome.Connections[key].Weight);
        }

        //Mutate weights
        populationManager.MutateAgent(customAgent, 0f, 0f, 1f, nodeInnovationCounter, connectionInnovationCounter, mutationLog);

        //Nodes should not have changed
        Assert.AreEqual(6, customAgent.Genome.Nodes.Count);
        Assert.AreEqual(9, customAgent.Genome.Connections.Count);
        Assert.AreEqual(14, connectionInnovationCounter.GetNewNumber());
        Assert.AreEqual(11, nodeInnovationCounter.GetNewNumber());


        foreach (int key in weights.Keys)
        {
            Assert.AreNotEqual(weights[key], customAgent.Genome.Connections[key].Weight);
        }
    }