//вещественная кодировка private void Test_VeshPopultion() { VeshPopulation test = new VeshPopulation(Aa); // создание популяции //int Namber0, int nIters0, double pMut0, double pInv0 // ( (int L, float Mut, float Inv, int point, int point2, int Namber0, int nIters0) VeshIndivid test_Ind = test.Turnir(test.Popul_all); // MtextBox.Text = MtextBox.Text + "------- + 0 + -------" + Environment.NewLine; // MtextBox.Text = MtextBox.Text + test.Print( point, point2) + Environment.NewLine; // MtextBox.Text = MtextBox.Text + test_Ind.Fank_out + Environment.NewLine; // MtextBox.Text = MtextBox.Text + test_Ind.Prin_Fen(Aa) + Environment.NewLine; MtextBox.Text = MtextBox.Text + "------- + 0 + -------" + Environment.NewLine // + test.Print(Aa) //; + Environment.NewLine + "Min " + test_Ind.Fank_out + Environment.NewLine; double minu; for (int i = 0; i < 50; i++) //Aa.Itertion { minu = test.TurnirMax(test.Popul_all).Fank_out - test.Turnir(test.Popul_all).Fank_out; if (minu > Aa.Itertion) { test.Select(Aa); test_Ind = test.Turnir(test.Popul_all); MtextBox.Text = MtextBox.Text + //"-------" + (i+1) + "-------" + Environment.NewLine + // test.Print(point, point2)+ Environment.NewLine + "-----" + Environment.NewLine + // test_Ind.Fank_out + Environment.NewLine; // test.Print(Aa) + Environment.NewLine + "Min " + (i + 1) + " " + test_Ind.Fank_out + Environment.NewLine; test.Mut_all(Aa); //MtextBox.Text = MtextBox.Text + test_Ind.Prin_Fen() + Environment.NewLine; } else { break; } } //test_Ind = test.Turnir(test.Popul_all); MtextBox.Text = MtextBox.Text + "-------END-------" + Environment.NewLine + // test.Print(point, point2) + Environment.NewLine + "-----" + Environment.NewLine + test_Ind.Prin_Fen(Aa) + Environment.NewLine; // MtextBox.Text = MtextBox.Text + test_Ind.Prin_Fen() + Environment.NewLine; MtextBox.Text = MtextBox.Text + "-------------" + Environment.NewLine + test_Ind.xrom[0].Prin() + Environment.NewLine + test_Ind.xrom[1].Prin() + Environment.NewLine; /////для 4 x1 = test_Ind.xrom[0].chrom; x2 = test_Ind.xrom[1].chrom; }
private void XD() { //test_Ind; VeshIndivid t0, t1, t2, t3, t4; t0 = new VeshIndivid(Aa); t1 = new VeshIndivid(Aa); t2 = new VeshIndivid(Aa); t3 = new VeshIndivid(Aa); t4 = new VeshIndivid(Aa); double f0, alf = 0.1; int pr = 0; VeshPopulation F = new VeshPopulation(Aa); // t0.xrom[0]= test_Ind /////для 4 t0.xrom[0].chrom = x1; t0.xrom[1].chrom = x2; t0.xrom[2].chrom = x3; t0.xrom[3].chrom = x4; f0 = t0.Fank_out = F.Fank_(t0, Aa); //MtextBox.Text = MtextBox.Text + Environment.NewLine // + f0 + Environment.NewLine; //// for (int i = 0; i < 1000 && pr != 1; i++) { t1.xrom[0].chrom = t0.Fenotip_1(Aa) + alf; t1.xrom[1].chrom = t0.Fenotip_2(Aa); t1.Fank_out = F.Fank_(t1, Aa); if (Math.Abs(t1.Fank_out) < Math.Abs(t0.Fank_out)) { t2.xrom[0].chrom = t0.xrom[0].chrom + alf; t2.xrom[1].chrom = t0.xrom[1].chrom + alf; t2.Fank_out = F.Fank_(t2, Aa); if (Math.Abs(t2.Fank_out) < Math.Abs(t1.Fank_out)) { t0.xrom[0].chrom = t2.xrom[0].chrom; t0.xrom[1].chrom = t2.xrom[1].chrom; f0 = t0.Fank_out = t2.Fank_out; } else { t3.xrom[0].chrom = t0.xrom[0].chrom + alf; t3.xrom[1].chrom = t0.xrom[1].chrom - alf; t3.Fank_out = F.Fank_(t3, Aa); if (Math.Abs(t3.Fank_out) < Math.Abs(t1.Fank_out)) { t0.xrom[0].chrom = t3.xrom[0].chrom; t0.xrom[1].chrom = t3.xrom[1].chrom; f0 = t0.Fank_out = t3.Fank_out; } else { t0.xrom[0].chrom = t1.xrom[0].chrom; t0.xrom[1].chrom = t1.xrom[1].chrom; f0 = t0.Fank_out = t1.Fank_out; } } } else { t2.xrom[0].chrom = t0.xrom[0].chrom - alf; t2.xrom[1].chrom = t0.xrom[1].chrom; t2.Fank_out = F.Fank_(t2, Aa); if (Math.Abs(t2.Fank_out) < Math.Abs(t0.Fank_out)) { t3.xrom[0].chrom = t0.xrom[0].chrom - alf; t3.xrom[1].chrom = t0.xrom[1].chrom + alf; t3.Fank_out = F.Fank_(t3, Aa); if (Math.Abs(t3.Fank_out) < Math.Abs(t2.Fank_out)) { t0.xrom[0].chrom = t3.xrom[0].chrom; t0.xrom[1].chrom = t3.xrom[1].chrom; f0 = t0.Fank_out = t3.Fank_out; } else { t4.xrom[0].chrom = t0.xrom[0].chrom - alf; t4.xrom[1].chrom = t0.xrom[1].chrom - alf; t4.Fank_out = F.Fank_(t4, Aa); if (Math.Abs(t4.Fank_out) < Math.Abs(t2.Fank_out)) { t0.xrom[0].chrom = t4.xrom[0].chrom; t0.xrom[1].chrom = t4.xrom[1].chrom; f0 = t0.Fank_out = t4.Fank_out; } else { t0.xrom[0].chrom = t2.xrom[0].chrom; t0.xrom[1].chrom = t2.xrom[1].chrom; f0 = t0.Fank_out = t2.Fank_out; } } } // 2+ else //2- { t3.xrom[0].chrom = t0.xrom[0].chrom; t3.xrom[1].chrom = t0.xrom[1].chrom + alf; t3.Fank_out = F.Fank_(t3, Aa); if (Math.Abs(t3.Fank_out) < Math.Abs(t0.Fank_out)) { t0.xrom[0].chrom = t3.xrom[0].chrom; t0.xrom[1].chrom = t3.xrom[1].chrom; f0 = t0.Fank_out = t3.Fank_out; } else { t4.xrom[0].chrom = t0.xrom[0].chrom; t4.xrom[1].chrom = t0.xrom[1].chrom - alf; t4.Fank_out = F.Fank_(t4, Aa); if (Math.Abs(t4.Fank_out) < Math.Abs(t0.Fank_out)) { t0.xrom[0].chrom = t4.xrom[0].chrom; t0.xrom[1].chrom = t4.xrom[1].chrom; f0 = t0.Fank_out = t4.Fank_out; } else { pr = 1; // } } } //els -1 } if (pr == 1) { alf = alf / 10; if (alf > 0.000001) { pr = 0; } } } MtextBox.Text = MtextBox.Text + Environment.NewLine + Environment.NewLine + "Метод ХД "; //MtextBox.Text = MtextBox.Text + Environment.NewLine + f0 + Environment.NewLine; MtextBox.Text = MtextBox.Text + Environment.NewLine + t0.xrom[0].Prin() + Environment.NewLine + t0.xrom[1].Prin() + Environment.NewLine + t0.xrom[2].Prin() + Environment.NewLine + t0.xrom[3].Prin() + Environment.NewLine; double Xx = t0.xrom[0].chrom * Aa.y1 * Aa.y1 + t0.xrom[1].chrom * Aa.y1 + t0.xrom[2].chrom; MtextBox.Text = MtextBox.Text + "a1*" + Aa.y1 * Aa.y1 + "+a2*" + Aa.y1 + "+ a3=0" + Environment.NewLine + t0.xrom[0].chrom + " * " + Aa.y1 * Aa.y1 + " + " + t0.xrom[1].chrom + " * " + Aa.y1 + " + " + t0.xrom[2].chrom + " = " + Environment.NewLine + // x1 + " * " + Aa.y1 * Aa.y1 + " + " + x2 + " * " + Aa.y1 + " + " + x3 + " = " + Environment.NewLine + Xx; }