示例#1
0
 public Point(OptimizationModel optModel, double x1, double x2)
 {
     Accuracy = optModel.Accuracy;
     //////////Доделать округление
     X1 = x1;
     X2 = x2;
 }
示例#2
0
 private void button1_Click(object sender, EventArgs e)
 {
     richTextBox1.Text = "";
         desc.Clear();
         alg = new PGA();
         OptimizationModel optModel = new OptimizationModel(func);
         AlgorithmSettings settings = new AlgorithmSettings()
         {
             InitialLoadType = (InitialLoadType)comboBox1.SelectedItem,
             OptModel = optModel,
             InitialPointCount = (int)numericUpDown1.Value,
             SelectionType = (SelectionType)comboBox2.SelectedItem,
             EndCondition = (EndCondition)comboBox3.SelectedItem,
             MaxGenerationCount = (int)numericUpDown2.Value,
             SurvivedCount = (int)numericUpDown3.Value,
             MutationChance = (double)numericUpDown4.Value,
             CrossingGenNumber = (int)numericUpDown5.Value,
             Tolerance = (double)numericUpDown6.Value,
             MutationChanceAfterCrossing = (double)numericUpDown7.Value,
             MutationType = (MutationType)comboBox4.SelectedItem
         };
         alg.Run(settings);
         DrawRezult(alg);
         WriteRezult(alg);
 }
示例#3
0
 public Point(OptimizationModel optModel,double x1,double x2)
 {
     Accuracy = optModel.Accuracy;
     //////////Доделать округление
     X1 = x1;
     X2 = x2;
 }
示例#4
0
 public Chromosome(OptimizationModel optModel, bool[] genes)
 {
     m_OptModel = optModel;
     m_Genes    = new bool[14];
     for (int i = 0; i < 14; i++)
     {
         m_Genes[i] = genes[i];
     }
     Id = identity;
     identity++;
 }
示例#5
0
 public Chromosome(OptimizationModel optModel, bool[] genes)
 {
     m_OptModel = optModel;
     m_Genes = new bool[14];
     for (int i = 0; i < 14; i++)
     {
         m_Genes[i] = genes[i];
     }
     Id = identity;
     identity++;
 }
示例#6
0
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        int progress = 0;
            optrez.Clear();
            finalRez.Clear();
            alg = new PGA();
            OptimizationModel optModel = new OptimizationModel(func);
            EnumConverter InitialLoadTypeCollection = new EnumConverter(typeof(InitialLoadType));
            EnumConverter EndConditionTypeCollecton = new EnumConverter(typeof(EndCondition));
            EnumConverter MutationTypeCollecton = new EnumConverter(typeof(MutationType));
            EnumConverter SelectionTypeCollection = new EnumConverter(typeof(SelectionType));
            foreach (InitialLoadType il in InitialLoadTypeCollection.GetStandardValues())
            {
                foreach (EndCondition ec in EndConditionTypeCollecton.GetStandardValues())
                {
                    foreach (MutationType mt in MutationTypeCollecton.GetStandardValues())
                    {
                        foreach (SelectionType st in SelectionTypeCollection.GetStandardValues())
                        {
                            double[] f1m = new double[(int)numericUpDown8.Value];
                            double[] f2m = new double[(int)numericUpDown8.Value];
                            double[] fm = new double[(int)numericUpDown8.Value];
                            double[] x1m = new double[(int)numericUpDown8.Value];
                            double[] x2m = new double[(int)numericUpDown8.Value];
                            for (int i = 0; i < (int)numericUpDown8.Value; i++)
                            {
                                AlgorithmSettings settings = new AlgorithmSettings()
                                {
                                    InitialLoadType = il,
                                    OptModel = optModel,
                                    InitialPointCount = (int)numericUpDown1.Value,
                                    SelectionType = st,
                                    EndCondition = ec,
                                    MaxGenerationCount = (int)numericUpDown2.Value,
                                    SurvivedCount = (int)numericUpDown3.Value,
                                    MutationChance = (double)numericUpDown4.Value,
                                    CrossingGenNumber = (int)numericUpDown5.Value,
                                    Tolerance = (double)numericUpDown6.Value,
                                    MutationChanceAfterCrossing = (double)numericUpDown7.Value,
                                    MutationType = mt
                                };
                                alg.Run(settings);
                                double x1 = alg.Best.X1;
                                double x2 = alg.Best.X2;
                                double f1 = alg.Best.F;
                                double f2 = alg.CallCount;
                                double f = GetCriterion(f1, f2);
                                f1m[i] = f1;
                                f2m[i] = f2;
                                fm[i] = f;
                                x1m[i] = x1;
                                x2m[i] = x2;
                                optrez.Add(new OptRezult()
                                {
                                    I = il,
                                    E = ec,
                                    S = st,
                                    M = mt,
                                    F1 = f1,
                                    F2 = f2,
                                    X1 = x1,
                                    X2 = x2,
                                    F = f
                                });
                            }
                            progress++;
                            backgroundWorker1.ReportProgress(progress * 100 / 24);
                            finalRez.Add(new OptRezult()
                            {
                                I = il,
                                E = ec,
                                S = st,
                                M = mt,
                                X1 = x1m.Average(),
                                X2 = x2m.Average(),
                                F1 = f1m.Average(),
                                F2 = f2m.Average(),
                                F = fm.Average()

                            });
                        }
                    }
                }
            }
    }
示例#7
0
        public Chromosome(OptimizationModel optModel, double x1, double x2)
        {
            m_OptModel = optModel;
            m_Genes    = new bool[14];
            for (int i = 0; i < m_Genes.Length; i++)
            {
                m_Genes[i] = false;
            }


            if (x1 < 0)
            {
                m_Genes[0] = true;
            }
            if (x2 < 0)
            {
                m_Genes[7] = true;
            }

            int fx1 = (int)Math.Floor(Math.Abs(x1));
            int fx2 = (int)Math.Floor(Math.Abs(x2));

            if (fx1 > 10)
            {
                throw new ArgumentOutOfRangeException("x1", x1, "x1 must be [-10;10]");
            }

            if (fx1 >= 8)
            {
                m_Genes[1] = true;
            }
            if ((fx1 >= 4) && (fx1 <= 7))
            {
                m_Genes[2] = true;
            }
            if ((fx1 == 2) || (fx1 == 3) || (fx1 == 6) || (fx1 == 7) || (fx1 == 10))
            {
                m_Genes[3] = true;
            }
            if (fx1 % 2 == 1)
            {
                m_Genes[4] = true;
            }

            if (fx2 >= 8)
            {
                m_Genes[8] = true;
            }
            if ((fx2 >= 4) && (fx2 <= 7))
            {
                m_Genes[9] = true;
            }
            if ((fx2 == 2) || (fx2 == 3) || (fx2 == 6) || (fx2 == 7) || (fx2 == 10))
            {
                m_Genes[10] = true;
            }
            if (fx2 % 2 == 1)
            {
                m_Genes[11] = true;
            }

            double dec1 = Math.Abs(x1) - fx1;
            double dec2 = Math.Abs(x2) - fx2;

            if ((dec1 > 0.15) && (dec1 < 0.35))
            {
                m_Genes[6] = true;
            }
            if ((dec1 > 0.35) && (dec1 < 0.6))
            {
                m_Genes[5] = true;
            }
            if (dec1 > 0.6)
            {
                m_Genes[6] = true;
                m_Genes[5] = true;
            }

            if ((dec2 > 0.15) && (dec2 < 0.35))
            {
                m_Genes[13] = true;
            }
            if ((dec2 > 0.35) && (dec2 < 0.6))
            {
                m_Genes[12] = true;
            }
            if (dec2 > 0.6)
            {
                m_Genes[13] = true;
                m_Genes[12] = true;
            }
            Id = identity;
            identity++;
        }
示例#8
0
        public Chromosome(OptimizationModel optModel, double x1, double x2)
        {
            m_OptModel = optModel;
            m_Genes = new bool[14];
            for (int i = 0; i < m_Genes.Length; i++)
            {
                m_Genes[i] = false;
            }

            if (x1 < 0)
                m_Genes[0] = true;
            if (x2 < 0)
                m_Genes[7] = true;

            int fx1 = (int)Math.Floor(Math.Abs(x1));
            int fx2 = (int)Math.Floor(Math.Abs(x2));
            if (fx1 > 10)
                throw new ArgumentOutOfRangeException("x1", x1, "x1 must be [-10;10]");

            if (fx1 >= 8)
                m_Genes[1] = true;
            if ((fx1 >= 4) && (fx1 <= 7))
                m_Genes[2] = true;
            if ((fx1 == 2) || (fx1 == 3) || (fx1 == 6) || (fx1 == 7) || (fx1 == 10))
                m_Genes[3] = true;
            if (fx1 % 2 == 1)
                m_Genes[4] = true;

            if (fx2 >= 8)
                m_Genes[8] = true;
            if ((fx2 >= 4) && (fx2 <= 7))
                m_Genes[9] = true;
            if ((fx2 == 2) || (fx2 == 3) || (fx2 == 6) || (fx2 == 7) || (fx2 == 10))
                m_Genes[10] = true;
            if (fx2 % 2 == 1)
                m_Genes[11] = true;

            double dec1 = Math.Abs(x1) - fx1;
            double dec2 = Math.Abs(x2) - fx2;

            if ((dec1 > 0.15) && (dec1 < 0.35))
                m_Genes[6] = true;
            if ((dec1 > 0.35) && (dec1 < 0.6))
                m_Genes[5] = true;
            if (dec1 > 0.6)
            {
                m_Genes[6] = true;
                m_Genes[5] = true;
            }

            if ((dec2 > 0.15) && (dec2 < 0.35))
                m_Genes[13] = true;
            if ((dec2 > 0.35) && (dec2 < 0.6))
                m_Genes[12] = true;
            if (dec2 > 0.6)
            {
                m_Genes[13] = true;
                m_Genes[12] = true;
            }
            Id = identity;
            identity++;
        }