private void Button_Click(object sender, RoutedEventArgs e) { InputGraph data = new InputGraph(); data = ReadData(); Optimization(data); DrawGraph(); }
private InputGraph ReadData() { InputGraph _data = new InputGraph(); double _generations, _population, _crossoverProb, _mutationProb; double _featureAMax, _featureBMax, _featureCMax, _featureDMax; double _featureAMin, _featureBMin, _featureCMin, _featureDMin; double.TryParse(this.TextBoxGeneration.Text, out _generations); _data.generations = _generations; double.TryParse(this.TextBoxPopulation.Text, out _population); _data.population = _population; double.TryParse(this.TextBoxCrossover.Text, out _crossoverProb); _data.crossoverProb = _crossoverProb; double.TryParse(this.TextBoxMutation.Text, out _mutationProb); _data.mutationProb = _mutationProb; double.TryParse(this.TextBoxAMin.Text, out _featureAMin); _data.featureAMin = _featureAMin; double.TryParse(this.TextBoxAMax.Text, out _featureAMax); _data.featureAMax = _featureAMax; double.TryParse(this.TextBoxBMin.Text, out _featureBMin); _data.featureBMin = _featureBMin; double.TryParse(this.TextBoxBMax.Text, out _featureBMax); _data.featureBMax = _featureBMax; double.TryParse(this.TextBoxCMin.Text, out _featureCMin); _data.featureCMin = _featureCMin; double.TryParse(this.TextBoxCMax.Text, out _featureCMax); _data.featureCMax = _featureCMax; double.TryParse(this.TextBoxDMin.Text, out _featureDMin); _data.featureDMin = _featureDMin; double.TryParse(this.TextBoxDMax.Text, out _featureDMax); _data.featureDMax = _featureDMax; return(_data); }
public Results Optimization(InputGraph _data) { //double[,] rangeFeatures = new double[,] { { 10, 15 }, { 10, 15 }, { 8, 15 }, { 0.005, 1 } }; double[,] rangeFeatures = new double[, ] { { _data.featureAMin, _data.featureAMax }, { _data.featureBMin, _data.featureBMax }, { _data.featureCMin, _data.featureCMax }, { _data.featureDMin, _data.featureDMax } }; double[] rangeMeasurement = new double[100]; double aux = 0; for (int i = 0; i < rangeMeasurement.Length; i++) { rangeMeasurement[i] = aux + 0.1; aux = rangeMeasurement[i]; } Function evalTarget = new Function(rangeMeasurement); double[,] result = evalTarget.Evaluation(new double[] { 12, 12, 10.5, 0.01 }); ////Population, rangeFeatures, result, rangeMeasuremet //GA_1 = new GeneticAlgorithm(100, rangeFeatures, result, rangeMeasurement); ////Generation, Pcrossover, Pmutation //GA_1.Run(300, 0.9, 0.1); double[] xVar = rangeMeasurement; double[] yVar = new double[rangeMeasurement.Length]; for (int i = 0; i < rangeMeasurement.Length; i++) { yVar[i] = result[i, 1]; } //Population, rangeFeatures, xVat, YVar //GA_1 = new GeneticAlgorithm(1000, rangeFeatures, xVar, yVar); GA = new GeneticAlgorithm((int)_data.population, rangeFeatures, xVar, yVar); //Generation, Pcrossover, Pmutation //GA_1.Run(500, 0.9, 0.9); GA.Run(_data.generations, _data.crossoverProb, _data.mutationProb); return(GA.results); }