コード例 #1
0
ファイル: Form1.cs プロジェクト: oyvind-kjerland/Flatland
        private void buttonShowSimulation_Click(object sender, EventArgs e)
        {
            FlatlandFitnessEvaluator evaluator = (FlatlandFitnessEvaluator)eaLoop.FitnessEvaluator;
            Board board = evaluator.boards[0];

            board.ResetBoard();

            SimulationForm simulationForm = new SimulationForm(board);

            simulationForm.bestIndividual = eaLoop.best;
            simulationForm.ShowDialog();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: oyvind-kjerland/Flatland
        private void SetupProblem()
        {
            if (comboBoxProblem.SelectedIndex == ANN_INDEX)
            {
                // Setup ANN

                // These settings are currently hardcoded
                int numSensorNodes = 6;
                int numMotorNodes  = 3;

                // Number of hidden layers
                int numHiddenLayers = listBoxANN.Items.Count;

                // The array containing the number of nodes for each hidden layer
                int[] numNodesPerLayer = listBoxANN.Items.OfType <int>().ToArray();

                // Setup the actication function (currently hardcoded)
                //ActivationFunction activationFunction = new SigmoidActivation();
                ActivationFunction activationFunction = new HyperbolicTangentActivation();

                bool useBiasNode = checkBoxBiasNode.Checked;

                ANN ann = new ANN(numSensorNodes, numMotorNodes, numHiddenLayers, numNodesPerLayer, activationFunction, useBiasNode);

                int numWeights = ann.GetNumberOfWeights();

                // Setup child population
                int childCount = (int)numericChildCount.Value;
                eaLoop.ChildCount = childCount;

                // Setup genotype (TODO Remove hardcoding)
                int numBitsPerWeight = (int)numericBitsPerWeight.Value;
                int numBits          = numBitsPerWeight * numWeights;
                eaLoop.Genotype = new BinaryGenotype(numBits);

                // Setup phenotype developer
                BinaryToANNWeightsDeveloper developer = new BinaryToANNWeightsDeveloper();
                developer.NumBitsPerWeight = numBitsPerWeight;
                developer.NumWeights       = numWeights;
                eaLoop.PhenotypeDeveloper  = developer;


                // Setup fitness evaluator
                FlatlandFitnessEvaluator evaluator = new FlatlandFitnessEvaluator();
                evaluator.ann = ann;
                evaluator.changeBoardBetweenGenerations = checkBoxDynamic.Checked;
                evaluator.numBoards  = (int)numericNumBoards.Value;
                evaluator.dimensions = new int[] { 10, 10 };
                evaluator.FPD        = new float[] { 0.33f, 0.33f };
                evaluator.timeSteps  = 60;

                eaLoop.FitnessEvaluator = evaluator;


                // Set Genetic operator
                eaLoop.GeneticOperator = new BinaryGeneticOperator();
                eaLoop.GeneticOperator.MutationRate  = (float)mutationNumeric.Value;
                eaLoop.GeneticOperator.CrossoverRate = (float)crossoverNumeric.Value;


                eaLoop.goal = int.MaxValue;
            }
        }