public decimal GetValue2ForIndividual(FunctionStruct function1, FunctionStruct function2, List <double> args) { var f2 = new Parser(function2.GetFunctionBase(), function2.GetFunctionBody()); f2.SetArguments(args); return(Decimal.Round(Convert.ToDecimal(f2.GetResult()), 2)); }
public void Calculate(FunctionStruct function1, FunctionStruct function2) { var f1 = new Parser(function1.GetFunctionBase(), function1.GetFunctionBody()); var f2 = new Parser(function2.GetFunctionBase(), function2.GetFunctionBody()); f1.SetArguments(_args); f2.SetArguments(_args); _f1 = Decimal.Round(Convert.ToDecimal(f1.GetResult()), 2); _f2 = Decimal.Round(Convert.ToDecimal(f2.GetResult()), 2); }
public List <Individual> GeneratePopulationOfSize(FunctionStruct function1, FunctionStruct function2, Constraints constraints, int N) { for (var i = 0; i < N; i++) { var args = constraints.GenerateArguments(); var individual = new Individual(); individual.GenerateIndividual(function1, function2, args); _population.Add(individual); } return(_population); }
public Vega(int populationSize, int iterations, double crossingProbability, double mutationProbability, FunctionStruct function1, FunctionStruct function2, Constraints constraints) { _populationSize = populationSize; _crossingProbability = crossingProbability; _mutationProbability = mutationProbability; _function1 = function1; _function2 = function2; _constraints = constraints; _beginingPopulation = new Population(); _iterations = iterations; }
public void GenerateIndividual(FunctionStruct function1, FunctionStruct function2, List <double> x) { _args = x; var f1 = new Parser(function1.GetFunctionBase(), function1.GetFunctionBody()); var f2 = new Parser(function2.GetFunctionBase(), function2.GetFunctionBody()); f1.SetArguments(x); f2.SetArguments(x); var df1 = f1.GetResult(); var df2 = f2.GetResult(); try { _f1 = Decimal.Round((df1), 2); _f2 = Decimal.Round((df2), 2); } catch (OverflowException e) { MessageBox.Show(df1.ToString() + " | " + df2 + " : " + e); } }
private void button1_Click(object sender, EventArgs e) { FunctionStruct functionStruct1 = new FunctionStruct(comboBox1.SelectedItem.ToString(), func1.Text); FunctionStruct functionStruct2 = new FunctionStruct(comboBox1.SelectedItem.ToString(), func2.Text); Population nonDominatedPopulation = new Population(); //chart2.Visible = false; chart1.Series["Series1"].Points.Clear(); chart2.Series["Series1"].Points.Clear(); //chart1.ChartAreas[0].AxisX.RoundAxisValues(); dataGridView1.Rows.Clear(); int lo = 0; int up = 0; int[] lotab = new int[comboBox1.SelectedIndex + 1]; int[] uptab = new int[comboBox1.SelectedIndex + 1]; for (int i = 0; i <= comboBox1.SelectedIndex; i++) { switch (i) { case 0: lo = int.Parse(tbL1.Text); up = int.Parse(tbU1.Text); break; case 1: lo = int.Parse(tbL2.Text); up = int.Parse(tbU2.Text); break; case 2: lo = int.Parse(tbL3.Text); up = int.Parse(tbU3.Text); break; case 3: lo = int.Parse(tbL4.Text); up = int.Parse(tbU4.Text); break; case 4: lo = int.Parse(tbL5.Text); up = int.Parse(tbU5.Text); break; } lotab[i] = lo; uptab[i] = up; } Constraints constraints = new Constraints(lotab, uptab); Vega vega = new Vega(int.Parse(popSize.Text), int.Parse(iterations.Text), Double.Parse(crossingPb.Text, CultureInfo.InvariantCulture), Double.Parse(mutationPb.Text, CultureInfo.InvariantCulture), functionStruct1, functionStruct2, constraints); vega.Initialization(); var result = vega.Iterate(); var index = 0; if (result.GetIndividual(0).GetFitness2() < result.GetIndividual(1).GetFitness2()) { nonDominatedPopulation.Add(result.GetIndividual(0)); } else { nonDominatedPopulation.Add(result.GetIndividual(1)); index = 1; } result.SortF1(); chart2.Series["Series1"].ChartType = SeriesChartType.Point; for (var i = 0; i < result.Size(); i++) { chart2.Series["Series1"].Points.AddXY(result.GetIndividual(i).GetFitness1(), result.GetIndividual(i).GetFitness2()); } for (var i = 1; i < result.Size(); i++) { if (result.GetIndividual(i).GetFitness2() < nonDominatedPopulation.GetIndividual(nonDominatedPopulation.Size() - 1).GetFitness2()) { nonDominatedPopulation.Add(result.GetIndividual(i)); } } if (nonDominatedPopulation.GetIndividual(0).GetFitness1() > nonDominatedPopulation.GetIndividual(1).GetFitness1()) { nonDominatedPopulation.DeleteIndividual(0); } chart1.Series["Series1"].ChartType = SeriesChartType.Point; for (var i = 0; i < nonDominatedPopulation.Size(); i++) { string[] mystring = new string[] { "", "", "", "", "", "", "" }; chart1.Series["Series1"].Points.AddXY(nonDominatedPopulation.GetIndividual(i).GetFitness1(), nonDominatedPopulation.GetIndividual(i).GetFitness2()); mystring[0] = nonDominatedPopulation.GetIndividual(i).GetFitness1().ToString(); mystring[1] = nonDominatedPopulation.GetIndividual(i).GetFitness2().ToString(); for (var j = 0; j < nonDominatedPopulation.GetIndividual(i).GetArgsVector().Count; j++) { mystring[j + 2] = Math.Round(nonDominatedPopulation.GetIndividual(i).GetArgsVector()[j], 3).ToString(); } dataGridView1.Rows.Add(mystring); } }