Пример #1
0
        public GA(AlgorithmParameters algorithmParameters, EvaluatedFunction evaluatedFunction)
        {
            this.algorithmParameters = algorithmParameters;
            this.evaluatedFunction   = evaluatedFunction;
            this.Chromosomes         = new BitArray[algorithmParameters.Generations, 2, algorithmParameters.Population];
            this.ChromosomeValues    = new double[algorithmParameters.Generations, 3, algorithmParameters.Population];

            this.BestValues   = new double[algorithmParameters.Generations];
            this.MeanValues   = new double[algorithmParameters.Generations];
            this.MedianValues = new double[algorithmParameters.Generations];
            this.random       = new Random();
            // generate first population

            for (int individualIndex = 0; individualIndex < algorithmParameters.Population; individualIndex++)
            {
                int x = generateRandomValue();
                int y = generateRandomValue();
                System.Diagnostics.Debug.WriteLine("X: " + x.ToString());
                System.Diagnostics.Debug.WriteLine("Y: " + y.ToString());
                BitArray x_genome = int2Binary(x, this.algorithmParameters.Precision);
                BitArray y_genome = int2Binary(y, this.algorithmParameters.Precision);
                this.Chromosomes[0, 0, individualIndex] = x_genome;
                this.Chromosomes[0, 1, individualIndex] = y_genome;
            }
        }
Пример #2
0
        private void Edit_Function(object sender, RoutedEventArgs e)
        {
            DlgAddFunction    dlg = new DlgAddFunction();
            EvaluatedFunction evaluatedFunction = FunctionGrid.SelectedItem as EvaluatedFunction;
            int indexOfFunction = evaluatedFunctionsList.IndexOf(evaluatedFunction);

            dlg.functionExpression.Text = evaluatedFunction.Function;
            dlg.xFirst.Value            = evaluatedFunction.xDomain.X;
            dlg.xLast.Value             = evaluatedFunction.xDomain.Y;
            dlg.yFirst.Value            = evaluatedFunction.yDomain.X;
            dlg.yLast.Value             = evaluatedFunction.yDomain.Y;
            if (dlg.ShowDialog() == true)
            {
                evaluatedFunction.setxDomain((double)dlg.xFirst.Value, (double)dlg.xLast.Value);
                evaluatedFunction.setyDomain((double)dlg.yFirst.Value, (double)dlg.yLast.Value);
                evaluatedFunctionsList[indexOfFunction] = evaluatedFunction;
                FunctionGrid.Items.Refresh();
            }
        }
Пример #3
0
        private void AddFunction(object sender, RoutedEventArgs e)
        {
            EvaluatedFunction evaluatedFunction;
            DlgAddFunction    dlg = new DlgAddFunction();

            if (dlg.ShowDialog() == true)
            {
                string functionExpression = dlg.functionExpression.Text;
                double xFirstValue        = (double)dlg.xFirst.Value;
                double xLastValue         = (double)dlg.xLast.Value;
                double yFirstValue        = (double)dlg.yFirst.Value;
                double yLastValue         = (double)dlg.yLast.Value;
                evaluatedFunction = new EvaluatedFunction(functionExpression, xFirstValue, xLastValue, yFirstValue, yLastValue);
                evaluatedFunctionsList.Add(evaluatedFunction);
                FunctionGrid.Items.Refresh();
                if (FunctionGrid.Columns.Count == 4)
                {
                    FunctionGrid.Columns[3].Visibility = Visibility.Hidden;
                }
            }
        }