Exemplo n.º 1
0
 public GoldenRatio(Dictionary <double, double> obj, ModelBuilding modelData)
 {
     this.obj       = obj;
     this.modelData = modelData;
 }
Exemplo n.º 2
0
        private void buildButton_Click(object sender, EventArgs e)
        {
            if (originalObject == null)
            {
                MessageBox.Show("Объект не был сгенерирован", "Ошибка");
                return;
            }

            double x1, x2, delta;
            int    n;

            try
            {
                n  = Convert.ToInt32(nTextBox.Text);
                x1 = Convert.ToDouble(x1TextBox.Text);
                x2 = Convert.ToDouble(x2TextBox.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Введены некорректные данные.", "Ошибка ввода");
                return;
            }

            delta = Math.Abs(x1 - x2) / n;

            types  = new List <ModelBuilding.CoreType>();
            models = new List <Dictionary <double, double> >();

            if (rectCheckBox.Checked)
            {
                types.Add(ModelBuilding.CoreType.Recatangle);
            }
            if (triCheckBox.Checked)
            {
                types.Add(ModelBuilding.CoreType.Triangle);
            }
            if (parCheckBox.Checked)
            {
                types.Add(ModelBuilding.CoreType.Parabola);
            }
            if (cubeCheckBox.Checked)
            {
                types.Add(ModelBuilding.CoreType.Cube);
            }

            foreach (var type in types)
            {
                ModelBuilding modelBuilding = new ModelBuilding(delta, type);
                GoldenRatio   goldenRatio   = new GoldenRatio(originalObject, modelBuilding);
                var           model         = new Dictionary <double, double>();

                modelBuilding.B = goldenRatio.FindMin(0.00001, 0, 0.9);

                double coreXN, reg, temp = 0;
                int    tempIndL = 0, tempIndJ = 0;
                bool   flag = false;
                for (int i = 0; i < originalObject.Count; i++)
                {
                    coreXN = 0; reg = 0;
                    flag   = false;

                    for (int l = tempIndL; l < originalObject.Count; l++)
                    {
                        temp = modelBuilding.CoreFunction(originalObject.ElementAt(i).Key, originalObject.ElementAt(l).Key);
                        if (temp != 0 && !flag)
                        {
                            flag     = true;
                            tempIndL = l;
                            coreXN  += temp;
                        }
                        else if (temp != 0)
                        {
                            coreXN += temp;
                        }
                        else if (temp == 0 && flag)
                        {
                            break;
                        }
                    }

                    flag = false;

                    for (int j = tempIndJ; j < originalObject.Count; j++)
                    {
                        temp = modelBuilding.CoreFunction(originalObject.ElementAt(i).Key, originalObject.ElementAt(j).Key);

                        if (temp != 0 && !flag)
                        {
                            flag     = true;
                            tempIndJ = j;
                            reg     += (temp / coreXN) * originalObject.ElementAt(j).Value;
                        }
                        else if (temp != 0)
                        {
                            reg += (temp / coreXN) * originalObject.ElementAt(j).Value;
                        }
                        else if (temp == 0 && flag)
                        {
                            break;
                        }
                    }

                    model.Add(originalObject.ElementAt(i).Key, reg);
                }

                models.Add(model);
            }
        }