C#,数值计算——完全VEGAS编码的蒙特·卡洛计算方法与源程序

news2024/10/6 18:21:30

1 文本格式

using System;

namespace Legalsoft.Truffer
{
    /// <summary>
    /// Complete VEGAS Code
    /// adaptive/recursive Monte Carlo
    /// </summary>
    public abstract class VEGAS
    {
        const int NDMX = 50;
        const int MXDIM = 10;
        const int RANSEED = 5330;
        const double ALPH = 1.5;
        const double TINY = 1.0e-30;
        private Ran ran_vegas = new Ran(RANSEED);

        //public static delegateFuncVectorDouble func_v_d { get; set; } = null;
        public VEGAS()
        {
        }

        public abstract double fxn(double[] x, double wgt);

        public static void rebin(double rc, int nd, double[] r, double[] xin, double[,] xi, int j)
        {
            //int i;
            int k = 0;
            double dr = 0.0;
            //double xn = 0.0;
            double xo = 0.0;

            for (int i = 0; i < nd - 1; i++)
            {
                while (rc > dr)
                {
                    dr += r[(++k) - 1];
                }
                if (k > 1)
                {
                    xo = xi[j, k - 2];
                }
                double xn = xi[j, k - 1];
                dr -= rc;
                xin[i] = xn - (xn - xo) * dr / r[k - 1];
            }
            for (int i = 0; i < nd - 1; i++)
            {
                xi[j, i] = xin[i];
            }
            xi[j, nd - 1] = 1.0;
        }

        /// <summary>
        /// Performs Monte Carlo integration of a user-supplied ndim-dimensional
        /// function fxn over a rectangular volume specified by regn[0..2 * ndim - 1], a
        /// vector consisting of ndim "lower left" coordinates of the region followed
        /// by ndim "upper right" coordinates.The integration consists of itmx
        /// iterations, each with approximately ncall calls to the function.After each
        /// iteration the grid is refined; more than 5 or 10 iterations are rarely
        /// useful.The input flag init signals whether this call is a new start or a
        /// subsequent call for additional iterations(see comments in the code). The
        /// input flag nprn(normally 0) controls the amount of diagnostic output.
        /// Returned answers are tgral (the best estimate of the integral), sd(its
        /// standard deviation), and chi2a(X^2 per degree of freedom, an indicator of
        /// whether consistent results are being obtained).
        /// </summary>
        /// <param name="regn"></param>
        /// <param name="init"></param>
        /// <param name="ncall"></param>
        /// <param name="itmx"></param>
        /// <param name="nprn"></param>
        /// <param name="tgral"></param>
        /// <param name="sd"></param>
        /// <param name="chi2a"></param>
        public void vegas(double[] regn, int init, int ncall, int itmx, int nprn, ref double tgral, ref double sd, ref double chi2a)
        {
            int mds = 0;
            int ndo = 0;
            double schi = 0.0;
            double si = 0.0;
            double swgt = 0.0;
            int[] ia = new int[MXDIM];
            int[] kg = new int[MXDIM];
            double[] dt = new double[MXDIM];
            double[] dx = new double[MXDIM];
            double[] r = new double[NDMX];
            double[] x = new double[MXDIM];
            double[] xin = new double[NDMX];
            double[,] d = new double[NDMX, MXDIM];
            double[,] di = new double[NDMX, MXDIM];
            double[,] xi = new double[MXDIM, NDMX];

            //Ran ran_vegas = new Ran(RANSEED);

            int ndim = regn.Length / 2;
            if (init <= 0)
            {
                mds = ndo = 1;
                for (int j = 0; j < ndim; j++)
                {
                    xi[j, 0] = 1.0;
                }
            }
            if (init <= 1)
            {
                si = swgt = schi = 0.0;
            }
            if (init <= 2)
            {
                int nd = NDMX;
                int ng = 1;
                if (mds != 0)
                {
                    ng = (int)Math.Pow(ncall / 2.0 + 0.25, 1.0 / ndim);
                    mds = 1;
                    if ((2 * ng - NDMX) >= 0)
                    {
                        mds = -1;
                        int n1pg = ng / NDMX + 1;
                        nd = ng / n1pg;
                        ng = n1pg * nd;
                    }
                }
                int k = 1;
                for (int i = 0; i < ndim; i++)
                {
                    k *= ng;
                }
                int npg = Math.Max((int)(ncall / k), 2);
                double calls = (double)npg * (double)k;
                double dxg = 1.0 / ng;
                double dv2g = 1.0;
                for (int i = 0; i < ndim; i++)
                {
                    dv2g *= dxg;
                }
                dv2g = Globals.SQR(calls * dv2g) / npg / npg / (npg - 1.0);
                int xnd = nd;
                dxg *= xnd;
                double xjac = 1.0 / calls;
                for (int j = 0; j < ndim; j++)
                {
                    dx[j] = regn[j + ndim] - regn[j];
                    xjac *= dx[j];
                }
                if (nd != ndo)
                {
                    for (int i = 0; i < Math.Max(nd, ndo); i++)
                    {
                        r[i] = 1.0;
                    }
                    for (int j = 0; j < ndim; j++)
                    {
                        rebin(ndo / xnd, nd, r, xin, xi, j);
                    }
                    ndo = nd;
                }
                if (nprn >= 0)
                {
                    /*
                    Console.Write(" Input parameters for vegas");
                    Console.Write("  ndim= ");
                    Console.Write("{0,4}", ndim);
                    Console.Write("{0,4}", "  ncall= ");
                    Console.Write("{0,8}", calls);
                    Console.Write("{0}", "\n");
                    Console.Write("{0,34}", "  it=");
                    Console.Write("{0,5}", it);
                    Console.Write("{0,5}", "  itmx=");
                    Console.Write("{0,5}", itmx);
                    Console.Write("{0}", "\n");
                    Console.Write("{0,34}", "  nprn=");
                    Console.Write("{0,5}", nprn);
                    Console.Write("{0,5}", "  ALPH=");
                    Console.Write("{0,9}", ALPH);
                    Console.Write("{0}", "\n");
                    Console.Write("{0,34}", "  mds=");
                    Console.Write("{0,5}", mds);
                    Console.Write("{0,5}", "  nd=");
                    Console.Write("{0,5}", nd);
                    Console.Write("{0}", "\n");
                    for (j = 0; j < ndim; j++)
                    {
                        Console.Write("{0,30}", " x1[");
                        Console.Write("{0,2}", j);
                        Console.Write("{0,2}", "]= ");
                        Console.Write("{0,11}", regn[j]);
                        Console.Write("{0}", " xu[");
                        Console.Write("{0,2}", j);
                        Console.Write("{0}", "]= ");
                        Console.Write("{0,11}", regn[j + ndim]);
                        Console.Write("{0}", "\n");
                    }
                    */
                    for (int it = 0; it < itmx; it++)
                    {
                        double ti = 0.0;
                        double tsi = 0.0;
                        for (int j = 0; j < ndim; j++)
                        {
                            kg[j] = 1;
                            for (int i = 0; i < nd; i++)
                            {
                                d[i, j] = di[i, j] = 0.0;
                            }
                        }
                        for (; ; )
                        {
                            double fb = 0.0;
                            double f2b = 0.0;
                            for (k = 0; k < npg; k++)
                            {
                                double w1gt = xjac;
                                for (int j = 0; j < ndim; j++)
                                {
                                    double xn = (kg[j] - ran_vegas.doub()) * dxg + 1.0;
                                    ia[j] = Math.Max(Math.Min((int)xn, NDMX), 1);
                                    double xo;
                                    double rc;
                                    if (ia[j] > 1)
                                    {
                                        xo = xi[j, ia[j] - 1] - xi[j, ia[j] - 2];
                                        rc = xi[j, ia[j] - 2] + (xn - ia[j]) * xo;
                                    }
                                    else
                                    {
                                        xo = xi[j, ia[j] - 1];
                                        rc = (xn - ia[j]) * xo;
                                    }
                                    x[j] = regn[j] + rc * dx[j];
                                    w1gt *= xo * xnd;
                                }
                                double f = w1gt * fxn(x, w1gt);
                                double f2 = f * f;
                                fb += f;
                                f2b += f2;
                                for (int j = 0; j < ndim; j++)
                                {
                                    di[ia[j] - 1, j] += f;
                                    if (mds >= 0)
                                    {
                                        d[ia[j] - 1, j] += f2;
                                    }
                                }
                            }
                            f2b = Math.Sqrt(f2b * npg);
                            f2b = (f2b - fb) * (f2b + fb);
                            if (f2b <= 0.0)
                            {
                                f2b = TINY;
                            }
                            ti += fb;
                            tsi += f2b;
                            if (mds < 0)
                            {
                                for (int j = 0; j < ndim; j++)
                                {
                                    d[ia[j] - 1, j] += f2b;
                                }
                            }
                            for (k = ndim - 1; k >= 0; k--)
                            {
                                kg[k] %= ng;
                                if (++kg[k] != 1)
                                {
                                    break;
                                }
                            }
                            if (k < 0)
                            {
                                break;
                            }
                        }
                        tsi *= dv2g;
                        double wgt = 1.0 / tsi;
                        si += wgt * ti;
                        schi += wgt * ti * ti;
                        swgt += wgt;
                        tgral = si / swgt;
                        chi2a = (schi - si * tgral) / (it + 0.0001);
                        if (chi2a < 0.0)
                        {
                            chi2a = 0.0;
                        }
                        sd = Math.Sqrt(1.0 / swgt);
                        tsi = Math.Sqrt(tsi);
                    }

                    if (nprn >= 0)
                    {
                        /*
                        Console.Write(" iteration no. ");
                        Console.Write("{0,3}", (it + 1));
                        Console.Write("{0,3}", " : integral = ");
                        Console.Write("{0,14}", ti);
                        Console.Write("{0,14}", " +/- ");
                        Console.Write("{0,9}", tsi);
                        Console.Write("{0}", "\n");
                        Console.Write("{0}", " all iterations:  ");
                        Console.Write("{0}", " integral =");
                        Console.Write("{0,14}", tgral);
                        Console.Write("{0}", "+-");
                        Console.Write("{0,9}", sd);
                        Console.Write("{0,9}", " chi**2/IT n =");
                        Console.Write("{0,9}", chi2a);
                        Console.Write("{0}", "\n");
                        if (nprn != 0)
                        {
                            for (j = 0; j < ndim; j++)
                            {
                                Console.Write("{0}", " DATA FOR axis  ");
                                Console.Write("{0,2}", j);
                                Console.Write("{0}", "\n");
                                Console.Write("{0}", "     X      delta i          X      delta i");
                                Console.Write("{0}", "          X       deltai");
                                Console.Write("{0}", "\n");
                                for (i = nprn / 2; i < nd - 2; i += nprn + 2)
                                {
                                    Console.Write("{0,8}", xi[j, i]);
                                    Console.Write("{0,12}", di[i, j]);
                                    Console.Write("{0,12}", xi[j, i + 1]);
                                    Console.Write("{0,12}", di[i + 1, j]);
                                    Console.Write("{0,12}", xi[j, i + 2]);
                                    Console.Write("{0,12}", di[i + 2, j]);
                                    Console.Write("{0,12}", "\n");
                                }
                            }
                        }
                        */
                    }
                    for (int j = 0; j < ndim; j++)
                    {
                        double xo = d[0, j];
                        double xn = d[1, j];
                        d[0, j] = (xo + xn) / 2.0;
                        dt[j] = d[0, j];
                        for (int i = 2; i < nd; i++)
                        {
                            double rc = xo + xn;
                            xo = xn;
                            xn = d[i, j];
                            d[i - 1, j] = (rc + xn) / 3.0;
                            dt[j] += d[i - 1, j];
                        }
                        d[nd - 1, j] = (xo + xn) / 2.0;
                        dt[j] += d[nd - 1, j];
                    }
                    for (int j = 0; j < ndim; j++)
                    {
                        double rc = 0.0;
                        for (int i = 0; i < nd; i++)
                        {
                            if (d[i, j] < TINY)
                            {
                                d[i, j] = TINY;
                            }
                            r[i] = Math.Pow((1.0 - d[i, j] / dt[j]) / (Math.Log(dt[j]) - Math.Log(d[i, j])), ALPH);
                            rc += r[i];
                        }
                        rebin(rc / xnd, nd, r, xin, xi, j);
                    }
                }
            }
        }
    }
}
 

2 代码格式

using System;

namespace Legalsoft.Truffer
{
    /// <summary>
    /// Complete VEGAS Code
    /// adaptive/recursive Monte Carlo
    /// </summary>
    public abstract class VEGAS
    {
        const int NDMX = 50;
        const int MXDIM = 10;
        const int RANSEED = 5330;
        const double ALPH = 1.5;
        const double TINY = 1.0e-30;
        private Ran ran_vegas = new Ran(RANSEED);

        //public static delegateFuncVectorDouble func_v_d { get; set; } = null;
        public VEGAS()
        {
        }

        public abstract double fxn(double[] x, double wgt);

        public static void rebin(double rc, int nd, double[] r, double[] xin, double[,] xi, int j)
        {
            //int i;
            int k = 0;
            double dr = 0.0;
            //double xn = 0.0;
            double xo = 0.0;

            for (int i = 0; i < nd - 1; i++)
            {
                while (rc > dr)
                {
                    dr += r[(++k) - 1];
                }
                if (k > 1)
                {
                    xo = xi[j, k - 2];
                }
                double xn = xi[j, k - 1];
                dr -= rc;
                xin[i] = xn - (xn - xo) * dr / r[k - 1];
            }
            for (int i = 0; i < nd - 1; i++)
            {
                xi[j, i] = xin[i];
            }
            xi[j, nd - 1] = 1.0;
        }

        /// <summary>
        /// Performs Monte Carlo integration of a user-supplied ndim-dimensional
        /// function fxn over a rectangular volume specified by regn[0..2 * ndim - 1], a
        /// vector consisting of ndim "lower left" coordinates of the region followed
        /// by ndim "upper right" coordinates.The integration consists of itmx
        /// iterations, each with approximately ncall calls to the function.After each
        /// iteration the grid is refined; more than 5 or 10 iterations are rarely
        /// useful.The input flag init signals whether this call is a new start or a
        /// subsequent call for additional iterations(see comments in the code). The
        /// input flag nprn(normally 0) controls the amount of diagnostic output.
        /// Returned answers are tgral (the best estimate of the integral), sd(its
        /// standard deviation), and chi2a(X^2 per degree of freedom, an indicator of
        /// whether consistent results are being obtained).
        /// </summary>
        /// <param name="regn"></param>
        /// <param name="init"></param>
        /// <param name="ncall"></param>
        /// <param name="itmx"></param>
        /// <param name="nprn"></param>
        /// <param name="tgral"></param>
        /// <param name="sd"></param>
        /// <param name="chi2a"></param>
        public void vegas(double[] regn, int init, int ncall, int itmx, int nprn, ref double tgral, ref double sd, ref double chi2a)
        {
            int mds = 0;
            int ndo = 0;
            double schi = 0.0;
            double si = 0.0;
            double swgt = 0.0;
            int[] ia = new int[MXDIM];
            int[] kg = new int[MXDIM];
            double[] dt = new double[MXDIM];
            double[] dx = new double[MXDIM];
            double[] r = new double[NDMX];
            double[] x = new double[MXDIM];
            double[] xin = new double[NDMX];
            double[,] d = new double[NDMX, MXDIM];
            double[,] di = new double[NDMX, MXDIM];
            double[,] xi = new double[MXDIM, NDMX];

            //Ran ran_vegas = new Ran(RANSEED);

            int ndim = regn.Length / 2;
            if (init <= 0)
            {
                mds = ndo = 1;
                for (int j = 0; j < ndim; j++)
                {
                    xi[j, 0] = 1.0;
                }
            }
            if (init <= 1)
            {
                si = swgt = schi = 0.0;
            }
            if (init <= 2)
            {
                int nd = NDMX;
                int ng = 1;
                if (mds != 0)
                {
                    ng = (int)Math.Pow(ncall / 2.0 + 0.25, 1.0 / ndim);
                    mds = 1;
                    if ((2 * ng - NDMX) >= 0)
                    {
                        mds = -1;
                        int n1pg = ng / NDMX + 1;
                        nd = ng / n1pg;
                        ng = n1pg * nd;
                    }
                }
                int k = 1;
                for (int i = 0; i < ndim; i++)
                {
                    k *= ng;
                }
                int npg = Math.Max((int)(ncall / k), 2);
                double calls = (double)npg * (double)k;
                double dxg = 1.0 / ng;
                double dv2g = 1.0;
                for (int i = 0; i < ndim; i++)
                {
                    dv2g *= dxg;
                }
                dv2g = Globals.SQR(calls * dv2g) / npg / npg / (npg - 1.0);
                int xnd = nd;
                dxg *= xnd;
                double xjac = 1.0 / calls;
                for (int j = 0; j < ndim; j++)
                {
                    dx[j] = regn[j + ndim] - regn[j];
                    xjac *= dx[j];
                }
                if (nd != ndo)
                {
                    for (int i = 0; i < Math.Max(nd, ndo); i++)
                    {
                        r[i] = 1.0;
                    }
                    for (int j = 0; j < ndim; j++)
                    {
                        rebin(ndo / xnd, nd, r, xin, xi, j);
                    }
                    ndo = nd;
                }
                if (nprn >= 0)
                {
                    /*
                    Console.Write(" Input parameters for vegas");
                    Console.Write("  ndim= ");
                    Console.Write("{0,4}", ndim);
                    Console.Write("{0,4}", "  ncall= ");
                    Console.Write("{0,8}", calls);
                    Console.Write("{0}", "\n");
                    Console.Write("{0,34}", "  it=");
                    Console.Write("{0,5}", it);
                    Console.Write("{0,5}", "  itmx=");
                    Console.Write("{0,5}", itmx);
                    Console.Write("{0}", "\n");
                    Console.Write("{0,34}", "  nprn=");
                    Console.Write("{0,5}", nprn);
                    Console.Write("{0,5}", "  ALPH=");
                    Console.Write("{0,9}", ALPH);
                    Console.Write("{0}", "\n");
                    Console.Write("{0,34}", "  mds=");
                    Console.Write("{0,5}", mds);
                    Console.Write("{0,5}", "  nd=");
                    Console.Write("{0,5}", nd);
                    Console.Write("{0}", "\n");
                    for (j = 0; j < ndim; j++)
                    {
                        Console.Write("{0,30}", " x1[");
                        Console.Write("{0,2}", j);
                        Console.Write("{0,2}", "]= ");
                        Console.Write("{0,11}", regn[j]);
                        Console.Write("{0}", " xu[");
                        Console.Write("{0,2}", j);
                        Console.Write("{0}", "]= ");
                        Console.Write("{0,11}", regn[j + ndim]);
                        Console.Write("{0}", "\n");
                    }
                    */
                    for (int it = 0; it < itmx; it++)
                    {
                        double ti = 0.0;
                        double tsi = 0.0;
                        for (int j = 0; j < ndim; j++)
                        {
                            kg[j] = 1;
                            for (int i = 0; i < nd; i++)
                            {
                                d[i, j] = di[i, j] = 0.0;
                            }
                        }
                        for (; ; )
                        {
                            double fb = 0.0;
                            double f2b = 0.0;
                            for (k = 0; k < npg; k++)
                            {
                                double w1gt = xjac;
                                for (int j = 0; j < ndim; j++)
                                {
                                    double xn = (kg[j] - ran_vegas.doub()) * dxg + 1.0;
                                    ia[j] = Math.Max(Math.Min((int)xn, NDMX), 1);
                                    double xo;
                                    double rc;
                                    if (ia[j] > 1)
                                    {
                                        xo = xi[j, ia[j] - 1] - xi[j, ia[j] - 2];
                                        rc = xi[j, ia[j] - 2] + (xn - ia[j]) * xo;
                                    }
                                    else
                                    {
                                        xo = xi[j, ia[j] - 1];
                                        rc = (xn - ia[j]) * xo;
                                    }
                                    x[j] = regn[j] + rc * dx[j];
                                    w1gt *= xo * xnd;
                                }
                                double f = w1gt * fxn(x, w1gt);
                                double f2 = f * f;
                                fb += f;
                                f2b += f2;
                                for (int j = 0; j < ndim; j++)
                                {
                                    di[ia[j] - 1, j] += f;
                                    if (mds >= 0)
                                    {
                                        d[ia[j] - 1, j] += f2;
                                    }
                                }
                            }
                            f2b = Math.Sqrt(f2b * npg);
                            f2b = (f2b - fb) * (f2b + fb);
                            if (f2b <= 0.0)
                            {
                                f2b = TINY;
                            }
                            ti += fb;
                            tsi += f2b;
                            if (mds < 0)
                            {
                                for (int j = 0; j < ndim; j++)
                                {
                                    d[ia[j] - 1, j] += f2b;
                                }
                            }
                            for (k = ndim - 1; k >= 0; k--)
                            {
                                kg[k] %= ng;
                                if (++kg[k] != 1)
                                {
                                    break;
                                }
                            }
                            if (k < 0)
                            {
                                break;
                            }
                        }
                        tsi *= dv2g;
                        double wgt = 1.0 / tsi;
                        si += wgt * ti;
                        schi += wgt * ti * ti;
                        swgt += wgt;
                        tgral = si / swgt;
                        chi2a = (schi - si * tgral) / (it + 0.0001);
                        if (chi2a < 0.0)
                        {
                            chi2a = 0.0;
                        }
                        sd = Math.Sqrt(1.0 / swgt);
                        tsi = Math.Sqrt(tsi);
                    }

                    if (nprn >= 0)
                    {
                        /*
                        Console.Write(" iteration no. ");
                        Console.Write("{0,3}", (it + 1));
                        Console.Write("{0,3}", " : integral = ");
                        Console.Write("{0,14}", ti);
                        Console.Write("{0,14}", " +/- ");
                        Console.Write("{0,9}", tsi);
                        Console.Write("{0}", "\n");
                        Console.Write("{0}", " all iterations:  ");
                        Console.Write("{0}", " integral =");
                        Console.Write("{0,14}", tgral);
                        Console.Write("{0}", "+-");
                        Console.Write("{0,9}", sd);
                        Console.Write("{0,9}", " chi**2/IT n =");
                        Console.Write("{0,9}", chi2a);
                        Console.Write("{0}", "\n");
                        if (nprn != 0)
                        {
                            for (j = 0; j < ndim; j++)
                            {
                                Console.Write("{0}", " DATA FOR axis  ");
                                Console.Write("{0,2}", j);
                                Console.Write("{0}", "\n");
                                Console.Write("{0}", "     X      delta i          X      delta i");
                                Console.Write("{0}", "          X       deltai");
                                Console.Write("{0}", "\n");
                                for (i = nprn / 2; i < nd - 2; i += nprn + 2)
                                {
                                    Console.Write("{0,8}", xi[j, i]);
                                    Console.Write("{0,12}", di[i, j]);
                                    Console.Write("{0,12}", xi[j, i + 1]);
                                    Console.Write("{0,12}", di[i + 1, j]);
                                    Console.Write("{0,12}", xi[j, i + 2]);
                                    Console.Write("{0,12}", di[i + 2, j]);
                                    Console.Write("{0,12}", "\n");
                                }
                            }
                        }
                        */
                    }
                    for (int j = 0; j < ndim; j++)
                    {
                        double xo = d[0, j];
                        double xn = d[1, j];
                        d[0, j] = (xo + xn) / 2.0;
                        dt[j] = d[0, j];
                        for (int i = 2; i < nd; i++)
                        {
                            double rc = xo + xn;
                            xo = xn;
                            xn = d[i, j];
                            d[i - 1, j] = (rc + xn) / 3.0;
                            dt[j] += d[i - 1, j];
                        }
                        d[nd - 1, j] = (xo + xn) / 2.0;
                        dt[j] += d[nd - 1, j];
                    }
                    for (int j = 0; j < ndim; j++)
                    {
                        double rc = 0.0;
                        for (int i = 0; i < nd; i++)
                        {
                            if (d[i, j] < TINY)
                            {
                                d[i, j] = TINY;
                            }
                            r[i] = Math.Pow((1.0 - d[i, j] / dt[j]) / (Math.Log(dt[j]) - Math.Log(d[i, j])), ALPH);
                            rc += r[i];
                        }
                        rebin(rc / xnd, nd, r, xin, xi, j);
                    }
                }
            }
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1063025.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【HCIE】跨域MPLS-VPN Option C 方式一

实验目的&#xff1a;R5与R7私网互通&#xff1b;R6与R8私网互通 说明&#xff1a;R1PE1&#xff1b;R2ASBR1&#xff1b;R3-ASBR2&#xff1b;R4PE2&#xff1b;R5/R6/R7/R8CE 方式一图谱 步骤1&#xff1a;给R1 R9 R2 R3 R4 配置接口IP与环回IP &#xff08;略&#xff09; …

互联网Java工程师面试题·Elasticsearch 篇·第二弹

12、详细描述一下 Elasticsearch 索引文档的过程。 协调节点默认使用文档 ID 参与计算&#xff08;也支持通过 routing &#xff09;&#xff0c;以便为路由提供合适的分片。 shard hash(document_id) % (num_of_primary_shards) 1 、当分片所在的节点接收到来自协调节点…

阿里云服务器价格计算器(一键计算精准报价)

阿里云服务器价格计算器&#xff0c;鼠标选择云服务器ECS实例规格、地域、系统盘、带宽及购买时长即可一键计算出精准报价&#xff0c;阿里云服务器网分享阿里云服务器价格计算器链接地址&#xff1a; 目录 阿里云服务器价格计算器 阿里云服务器价格计算器 先打开阿里云服务…

【Java】猫和狗接口版本思路分析

目录 猫&#x1f431;和狗&#x1f415;&#xff08;接口版本&#xff09; 画图分析 案例代码 猫&#x1f431;和狗&#x1f415;&#xff08;接口版本&#xff09; 需求&#xff1a;对猫和狗进行训练&#xff0c;它们就可以跳高了&#xff0c;这里加入了跳高功能&#xff0…

Dubbo3应用开发—Dubbo注册中心引言

Dubbo注册中心引言 什么是Dubbo注册中心 Dubbo的注册中心&#xff0c;是Dubbo服务治理的⼀个重要的概念&#xff0c;他主要用于 RPC服务集群实例的管理。 注册中心的运行流程 使用注册中心的好处 可以有效的管理RPC集群的健康情况&#xff0c;动态的上线或者下线服务。让我…

计算机网络——计算机网络的性能指标(上)-速率、带宽、吞吐量、时延

目录 速率 比特 速率 例1 带宽 带宽在模拟信号系统中的意义 带宽在计算机网络中的意义 吞吐量 时延 发送时延 传播时延 处理时延 例2 例3 速率 了解速率之前&#xff0c;先详细了解一下比特&#xff1a; 比特 计算机中数据量的单位&#xff0c;也是信息论中信…

Elasticsearch数据操作原理

Elasticsearch 是一个开源的、基于 Lucene 的分布式搜索和分析引擎&#xff0c;设计用于云计算环境中&#xff0c;能够实现实时的、可扩展的搜索、分析和探索全文和结构化数据。它具有高度的可扩展性&#xff0c;可以在短时间内搜索和分析大量数据。 Elasticsearch 不仅仅是一个…

《向量数据库指南》——用Milvus cloud搭建聊天机器人

作为向量数据库的佼佼者&#xff0c;Milvus 适用于各种需要借助高效和可扩展向量搜索功能的 AI 应用。 举个例子&#xff0c;如果想要搭建一个聊天机器人&#xff0c;Milvus 一定是其进行数据管理的首选。那么&#xff0c;如何让这个应用程序开发变得易于管理及更好理解&#x…

力扣第226翻转二叉数 c++三种方法 +注释

题目 226. 翻转二叉树 简单 给你一棵二叉树的根节点 root &#xff0c;翻转这棵二叉树&#xff0c;并返回其根节点。 示例 1&#xff1a; 输入&#xff1a;root [4,2,7,1,3,6,9] 输出&#xff1a;[4,7,2,9,6,3,1]示例 2&#xff1a; 输入&#xff1a;root [2,1,3] 输出&am…

阿里云服务器镜像系统Anolis OS龙蜥详细介绍

阿里云服务器Anolis OS镜像系统由龙蜥OpenAnolis社区推出&#xff0c;Anolis OS是CentOS 8 100%兼容替代版本&#xff0c;Anolis OS是完全开源、中立、开放的Linux发行版&#xff0c;具备企业级的稳定性、高性能、安全性和可靠性。目前阿里云服务器ECS可选的Anolis OS镜像系统版…

Linux shell编程学习笔记8:使用字符串

一、前言 字符串是大多数编程语言中最常用最有用的数据类型&#xff0c;这在Linux shell编程中也不例外。 本文讨论了Linux Shell编程中的字符串的三种定义方式的差别&#xff0c;以及字符串拼接、取字符串长度、提取字符串、查找子字符串等常用字符串操作,&#xff0c;以及反…

Nacos 使用

大家好我是苏麟今天带来Nacos注册中心 . Nacos注册中心 国内公司一般都推崇阿里巴巴的技术&#xff0c;比如注册中心&#xff0c;SpringCloudAlibaba也推出了一个名为Nacos的 注册中心。 认识Nacos Nacos是阿里巴巴的产品&#xff0c;现在是SpringCloud中的一个组件。相比E…

【Spring笔记04】Spring中Bean的生命周期及Bean的后置处理器

这篇文章主要介绍的是Spring框架中Bean的生命周期&#xff0c;Bean的后置处理器、以及多个后置处理器的先后执行顺序。 目录 一、生命周期介绍 1.1、什么是Bean的生命周期 1.2、Bean生命周期的过程 &#xff08;1&#xff09;实例化阶段 &#xff08;2&#xff09;依赖注入…

PostgreSQL ash —— pgsentinel插件

一、 插件作用 众所周知&#xff0c;pg是没有像oracle那样的ash视图的&#xff0c;因此要回溯历史问题不太方便。pgsentinel插件会将pg_stat_activity与pg_stat_statements视图内容定期快照&#xff0c;并存入pg_active_session_history和pg_stat_statements_history视图中。 1…

【实操记录】Oracle数据整库同步至Apache Doris

本文是Oracle数据整库同步至Apache Doris实操记录&#xff0c;仅供参考 参考&#xff1a;https://cn.selectdb.com/blog/104 1、Oracle 配置 [rootnode1 oracle]# pwd /u01/app/oracle [rootnode1 oracle]# mkdir recovery_area [rootnode1 oracle]# chown -R oracle:dba re…

WPF中, 如何将控件的触发事件绑定到ViewModel

在DataGrid 等控件中, 有很多这种带闪电符号的触发事件. 如果用传统的事件驱动, 则直接在后台中建立 一个private PropertyChanged(Sender s, EventAgars Args) 即可. 但是如果需要绑定到ViewModel的话? 应该怎么做? 带闪电符号的触发事件 实现viewModel绑定前端触发事件的…

【C++设计模式之原型模式:创建型】分析及示例

简介 原型模式&#xff08;Prototype Pattern&#xff09;是一种创建型设计模式&#xff0c;它允许通过复制已有对象来生成新的对象&#xff0c;而无需再次使用构造函数。 描述 原型模式通过复制现有对象来创建新的对象&#xff0c;而无需显式地调用构造函数或暴露对象的创建…

JAVA编程题-求矩阵螺旋值

螺旋类 package entity; /*** 打印数组螺旋值类*/ public class Spiral { // 数组行private int row; // 数组列private int col; // 行列数private int size; // 当前行索引private int rowIndex; // 当前列索引private int colIndex; // 行开始索引private int rowStart; //…

大模型部署手记(5)ChatGLM2+Jetson AGX Orin

1.简介&#xff1a; 组织机构&#xff1a;智谱/清华 代码仓&#xff1a;https://github.com/THUDM/ChatGLM2-6B 模型&#xff1a;THUDM/chatglm2-6b 下载&#xff1a;https://huggingface.co/THUDM/chatglm2-6b 镜像下载&#xff1a;https://aliendao.cn/models/THUDM/chat…

Java日期的学习篇

关于日期的学习 目录 关于日期的学习JDK8以前的APIDate Date常用APIDate的API应用 SimpleDateFormatSimpleDateFormat常用API测试 反向格式化(逆操作)测试 训练案例需求(秒杀活动)实现 Calendar需求痛点常见API应用测试 JDK8及以后的API(修改与新增)为啥学习(推荐使用)新增的AP…