Пример #1
0
        protected CPPNetwork(CPPNetwork s)
        {
            Nodes = new List <Node>();

            Connections = new List <Connection>();

            Inputs  = new List <Node>();
            Outputs = new List <Node>();

            foreach (Node n in s.Inputs)
            {
                Inputs.Add(n);
            }

            foreach (Node n in s.Outputs)
            {
                Outputs.Add(n);
            }

            for (var i = 0; i < s.Nodes.Count; i++)
            {
                Nodes.Add(s.Nodes[i]);
            }

            for (var i = 0; i < s.Connections.Count; i++)
            {
                Connections.Add(new Connection(s.Connections[i]));
            }
        }
Пример #2
0
        public void Genome4_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            population[0, 0] = CPPNetwork.Mutate(population[1, 1]);
            population[0, 1] = CPPNetwork.Mutate(population[1, 1]);
            population[1, 0] = CPPNetwork.Mutate(population[1, 1]);

            RenderPopulation();
        }
Пример #3
0
 public void InitializePopulation()
 {
     for (var x = 0; x < 2; x++)
     {
         for (var y = 0; y < 2; y++)
         {
             population[x, y] = new CPPNetwork(5, 1);
         }
     }
 }
Пример #4
0
        protected void SaveImage(CPPNetwork n)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            if (sfd.ShowDialog() ?? true)
            {
                IsEnabled = false;

                var encoder = new PngBitmapEncoder();

                encoder.Frames.Add(BitmapFrame.Create((BitmapSource)CPPNRenderEngine.Render(n, CPPNSettings.RenderWidth, CPPNSettings.RenderHeight)));

                using (var stream = sfd.OpenFile())
                {
                    encoder.Save(stream);
                }

                IsEnabled = true;
            }
        }
Пример #5
0
        public static CPPNetwork Mutate(CPPNetwork s)
        {
            var t = new CPPNetwork(s);

            var c = Utilities.ThreadSafeRandom.Next(t.Connections.Count);

            var w = t.Connections[c].Weight + Utilities.ThreadSafeRandom.NextUniform();

            t.Connections[c] = Connection.UpdateWeight(t.Connections[c], w);

            if (Utilities.ThreadSafeRandom.NextDouble() < .4)
            {
                if (Utilities.ThreadSafeRandom.NextDouble() < .5)
                {
                    t.AddNode();
                }
                else
                {
                    t.AddConnection();
                }
            }

            return(t);
        }