Exemple #1
0
        public MinPoint minSearch(LinkList p, double a, double b, double ee, int n, double r, Func <double, double> f)
        {
            PriorityQueue q  = new PriorityQueue();
            Interval      zk = new Interval();

            double mm, m = -1.0;
            int    k = 1;

            Point a0 = new Point(a, f(a));
            Point b0 = new Point(b, f(b));

            p.insertup(a0);
            p.insertup(b0);

            do
            {
                double mold = m;
                mm = p.Mfunc();

                if (mm > 0.0)
                {
                    m = r * mm;
                }
                else
                {
                    m = 1.0;
                }

                if (mold != m)
                {
                    p.addQueue(q, m, Rfunc);
                }

                zk = q.pop();

                double xk = searchxk(zk, m);

                Point t  = new Point(xk, f(xk));
                Point tt = p.insertup(t);

                Interval i1 = new Interval(Rfunc(zk.lp, tt, m), zk.lp, tt);
                Interval i2 = new Interval(Rfunc(tt, zk.rp, m), tt, zk.rp);

                q.push(i1);
                q.push(i2);

                k++;
            } while (bv(zk.rp.x, zk.lp.x, ee, k, n));

            MinPoint minp = new MinPoint(p.Min(), k, zk.rp.x - zk.lp.x);

            return(minp);
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int    n  = Convert.ToInt32(textBox5.Text);
            double ee = Convert.ToDouble(textBox6.Text);
            double r  = Convert.ToDouble(textBox7.Text);
            double a  = Convert.ToDouble(textBox8.Text);
            double b  = Convert.ToDouble(textBox9.Text);

            LinkList p = new LinkList();

            if (radioButton1.Checked)
            {
                AGP metod = new Strongin();

                MinPoint minp = metod.minSearch(p, a, b, ee, n, r, f);

                label1.Text  = "Min x = " + Convert.ToString(minp.x);
                label2.Text  = "Min z = " + Convert.ToString(minp.z);
                label8.Text  = "n = " + Convert.ToString(minp.k);
                label14.Text = "ee = " + Convert.ToString(minp.ee);
            }

            if (radioButton2.Checked)
            {
                AGP metod = new Piyavsky();

                MinPoint minp = metod.minSearch(p, a, b, ee, n, r, f);

                label1.Text  = "Min x = " + Convert.ToString(minp.x);
                label2.Text  = "Min z = " + Convert.ToString(minp.z);
                label8.Text  = "n = " + Convert.ToString(minp.k);
                label14.Text = "ee = " + Convert.ToString(minp.ee);
            }

            if (radioButton3.Checked)
            {
                AGP metod = new Scan();

                MinPoint minp = metod.minSearch(p, a, b, ee, n, r, f);

                label1.Text  = "Min x = " + Convert.ToString(minp.x);
                label2.Text  = "Min z = " + Convert.ToString(minp.z);
                label8.Text  = "n = " + Convert.ToString(minp.k);
                label14.Text = "ee = " + Convert.ToString(minp.ee);
            }

            p.art(zedGraphControl1);

            PointPairList list_zz = new PointPairList();

            double h = (b - a) / (double)n;

            for (int i = 0; i < n - 1; i++)
            {
                double x = a + i * h;
                double z = f(x);

                list_zz.Add(x, z);
            }

            list_zz.Add(b, f(b));

            LineItem Curve3 = zedGraphControl1.GraphPane.AddCurve("fun", list_zz, Color.Gray, SymbolType.None);

            zedGraphControl1.AxisChange();
            zedGraphControl1.Invalidate();
        }