Exemple #1
0
        public override void AddedToContainer()
        {
            base.AddedToContainer();

            var builder = new FieldBuilder();

            builder.BuildSessionStart(this);

            var isFirstGeneration = builder.AddCheckBoxField("IsFirstGeneration: ");

            isFirstGeneration.Checked        = genome.IsFirstGeneration;
            isFirstGeneration.CanChangeValue = false;

            var parent1 = builder.AddIntegerField("Parent1: ");

            parent1.Value          = genome.Parent1;
            parent1.CanChangeValue = false;

            var parent2 = builder.AddIntegerField("Parent2: ");

            parent2.Value          = genome.Parent2;
            parent2.CanChangeValue = false;

            builder.AddResizableButtonField("Edit Body-genes", delegate(object sender)
            {
                EditDoubleGeneListForm.ShowDialogue(Parent, genome.BodyGenes);
            }, FieldBuilder.ResizableButtonOrientation.FillWidth);

            builder.AddResizableButtonField("Edit Mutation-genes", delegate(object sender)
            {
                EditDoubleGeneListForm.ShowDialogue(Parent, genome.MutationGenes);
            }, FieldBuilder.ResizableButtonOrientation.FillWidth);

            var crossoverTypes = Globals.GetAllTypesDeriving(typeof(CrossoverFunction), Assembly.GetExecutingAssembly());
            var crossoverNames = new List <string>(crossoverTypes.Select(s => s.Name));

            var crossoverComboBox = builder.AddComboBoxField("Crossover Function: ", crossoverNames);

            if (genome.CrossoverFunction != null)
            {
                var crossoverType = genome.CrossoverFunction.GetType();
                foreach (var type in crossoverTypes)
                {
                    if (type.IsEquivalentTo(crossoverType))
                    {
                        crossoverComboBox.Index = crossoverTypes.IndexOf(type);
                    }
                }
            }

            crossoverComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex)
            {
                genome.CrossoverFunction = (CrossoverFunction)Activator.CreateInstance(crossoverTypes[newItemIndex]);
            };
            var globalSigmoidEditButton = builder.AddResizableButtonField("Edit Crossover Function", delegate(object sender)
            {
                if (genome.CrossoverFunction == null)
                {
                    return;
                }

                var crossoverFunc = genome.CrossoverFunction;
                crossoverTypes[crossoverComboBox.Index].InvokeMember("GUI_Edit", BindingFlags.Default | BindingFlags.InvokeMethod, null, null, new object[] { Parent, crossoverFunc });
            });

            builder.BuildSessionEnd();
        }
Exemple #2
0
        public static Func <bool> GUI_Edit(SingleSlotBox container, RMP_Chromosome chromosome)
        {
            var builder = new FieldBuilder();

            builder.BuildSessionStart(container);

            Dictionary <string, object> valueHolder = new Dictionary <string, object>();

            valueHolder.Add("RMP_Chromosome", chromosome);

            var inhibitoryConnectionChance = builder.AddDoubleField("Inhibitory Connection-Chance: ");

            inhibitoryConnectionChance.Value = chromosome.InhibitoryConnectionChance;
            var connectionChance = builder.AddDoubleField("Connection-Chance: ");

            connectionChance.Value = chromosome.ConnectionChance;

            var newConnectionsCanForm = builder.AddCheckBoxField("NewConnectionsCanForm: ");

            newConnectionsCanForm.Checked = chromosome.NewConnectionsCanForm;
            var connectionsCanDie = builder.AddCheckBoxField("ConnectionsCanDie: ");

            connectionsCanDie.Checked = chromosome.ConnectionsCanDie;
            var newNeuronsCanForm = builder.AddCheckBoxField("NewNeuronsCanForm: ");

            newNeuronsCanForm.Checked = chromosome.NewNeuronsCanForm;
            var neuronsCanDie = builder.AddCheckBoxField("NeuronsCanDie: ");

            neuronsCanDie.Checked = chromosome.NeuronsCanDie;

            Action reloadChromosome = delegate()
            {
                chromosome.InhibitoryConnectionChance = inhibitoryConnectionChance.Value;
                chromosome.ConnectionChance           = connectionChance.Value;

                chromosome.NewConnectionsCanForm = newConnectionsCanForm.Checked;
                chromosome.ConnectionsCanDie     = connectionsCanDie.Checked;
                chromosome.NewNeuronsCanForm     = newNeuronsCanForm.Checked;
                chromosome.NeuronsCanDie         = neuronsCanDie.Checked;
            };

            if (chromosome.MutationGenes.Count == 0)
            {
                //Mutation Genes
                chromosome.MutationGenes.Add(new DoubleGene("NeuronAddChance", 0, 1, 0.1));
                chromosome.MutationGenes.Add(new DoubleGene("NeuronRemoveChance", 0, 1, 0.1));
                chromosome.MutationGenes.Add(new DoubleGene("MaxNeuronRemoving", 0, 1, 0.1));
                chromosome.MutationGenes.Add(new DoubleGene("MaxNeuronAdding", 0, 1, 0.1));
                chromosome.MutationGenes.Add(new DoubleGene("ConnectionAddChance", 0, 1, 0.05));
                chromosome.MutationGenes.Add(new DoubleGene("ConnectionRemoveChance", 0, 1, 0.05));
            }
            builder.AddResizableButtonField("Edit Mutation Genes", delegate(object sender)
            {
                EditDoubleGeneListForm.ShowDialogue(container.Parent, chromosome.MutationGenes);
            });

            var sigmoidTypes = Globals.GetAllTypesDeriving(typeof(SigmoidFunction), Assembly.GetExecutingAssembly());
            var sigmoidNames = new List <string>(sigmoidTypes.Select(s => s.Name));

            var globalSigmoidComboBox = builder.AddComboBoxField("GlobalSigmoid: ", sigmoidNames);

            if (chromosome.GlobalSigmoidFunction != null)
            {
                var globalSigmoidType = chromosome.GlobalSigmoidFunction.GetType();
                foreach (var type in sigmoidTypes)
                {
                    if (type.IsEquivalentTo(globalSigmoidType))
                    {
                        globalSigmoidComboBox.Index = sigmoidTypes.IndexOf(type);
                    }
                }
            }

            globalSigmoidComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex)
            {
                chromosome.GlobalSigmoidFunction = (SigmoidFunction)Activator.CreateInstance(sigmoidTypes[newItemIndex]);
            };
            var globalSigmoidEditButton = builder.AddResizableButtonField("Edit GlobalSigmoid", delegate(object sender)
            {
                if (chromosome.GlobalSigmoidFunction == null)
                {
                    return;
                }

                var sigmoid = chromosome.GlobalSigmoidFunction;
                sigmoidTypes[globalSigmoidComboBox.Index].InvokeMember("GUI_Edit", BindingFlags.Default | BindingFlags.InvokeMethod, null, null, new object[] { container.Parent, sigmoid });
            });

            var globalOutputSigmoidComboBox = builder.AddComboBoxField("GlobalOutputSigmoid: ", sigmoidNames);

            if (chromosome.GlobalOutputSigmoidFunction != null)
            {
                var globalOutputSigmoidType = chromosome.GlobalOutputSigmoidFunction.GetType();
                foreach (var type in sigmoidTypes)
                {
                    if (type.IsEquivalentTo(globalOutputSigmoidType))
                    {
                        globalOutputSigmoidComboBox.Index = sigmoidTypes.IndexOf(type);
                    }
                }
            }

            globalOutputSigmoidComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex)
            {
                chromosome.GlobalOutputSigmoidFunction = (SigmoidFunction)Activator.CreateInstance(sigmoidTypes[newItemIndex]);
            };
            var globalOutputSigmoidEditButton = builder.AddResizableButtonField("Edit GlobalOutputSigmoid", delegate(object sender)
            {
                if (chromosome.GlobalOutputSigmoidFunction == null)
                {
                    return;
                }

                var sigmoid = chromosome.GlobalOutputSigmoidFunction;
                sigmoidTypes[globalOutputSigmoidComboBox.Index].InvokeMember("GUI_Edit", BindingFlags.Default | BindingFlags.InvokeMethod, null, null, new object[] { container.Parent, sigmoid });
            });

            builder.AddResizableButtonField("Randomize", delegate(object sender)
            {
                reloadChromosome();

                if (chromosome.GlobalSigmoidFunction == null ||
                    chromosome.GlobalOutputSigmoidFunction == null)
                {
                    AlertForm.ShowDialogue(container.Parent, null, "Can't randomize before choosing a sigmoid function.");
                }
                else
                {
                    RandomizeForm.ShowDialogue(container.Parent, chromosome);
                }
            });

            builder.AddResizableButtonField("Edit Neuron-genes", delegate(object sender)
            {
                reloadChromosome();

                EditChromosomeNeuronsForm.ShowDialogue(container.Parent, valueHolder);
            });

            container.IsClosing += delegate(object sender)
            {
                reloadChromosome();
            };

            builder.BuildSessionEnd();

            return(delegate()
            {
                return chromosome.GlobalSigmoidFunction != null && chromosome.GlobalOutputSigmoidFunction != null;
            });
        }