Exemplo n.º 1
0
    private static void sgmga_vcn_timing_test(int dim_num, double[] importance,
                                              double[] level_weight, double q_min, double q_max)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_VCN_TIMING_TEST times SGMGA_VCN and SGMGA_VCN_NAIVE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 April 2011
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int dim;

        SGMGAniso.SGMGAData data = new();
        string cout;

        int[] level_1d     = new int[dim_num];
        int[] level_1d_max = new int[dim_num];
        int[] level_1d_min = new int[dim_num];

        Console.WriteLine("");
        Console.WriteLine("SGMGA_VCN_TIMING_TEST");
        Console.WriteLine("  Consider vectors 0 <= LEVEL_1D(1:N) <= LEVEL_1D_MAX(1:N),");
        Console.WriteLine("  Set Q = sum ( LEVEL_WEIGHT(1:N) * LEVEL_1D(1:N) )");
        Console.WriteLine("  Accept vectors for which Q_MIN < Q <= Q_MAX");
        Console.WriteLine("  No particular order is imposed on the LEVEL_1D values.");
        Console.WriteLine("  SGMGA_VCN_NAIVE uses a naive approach;");
        Console.WriteLine("  SGMGA_VCN tries to be more efficient.");
        Console.WriteLine("  Here, we compare the timings.");

        for (dim = 0; dim < dim_num; dim++)
        {
            switch (level_weight[dim])
            {
            case > 0.0:
            {
                level_1d_max[dim] = (int)Math.Floor(q_max / level_weight[dim]) + 1;
                if (q_max <= (level_1d_max[dim] - 1) * level_weight[dim])
                {
                    level_1d_max[dim] -= 1;
                }

                break;
            }

            default:
                level_1d_max[dim] = 0;
                break;
            }
        }

        for (dim = 0; dim < dim_num; dim++)
        {
            level_1d_min[dim] = 0;
        }

        bool more_grids = false;

        Console.WriteLine("");
        Console.WriteLine("  IMPORTANCE:");
        cout = "";
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + importance[dim].ToString(CultureInfo.InvariantCulture).PadLeft(14);
        }

        Console.WriteLine(cout);
        Console.WriteLine("  LEVEL_WEIGHT:");
        cout = "";
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_weight[dim].ToString(CultureInfo.InvariantCulture).PadLeft(14);
        }

        Console.WriteLine(cout);
        Console.WriteLine("");
        Console.WriteLine("  SGMGA_VCN_NAIVE");
        Console.WriteLine("     I               Q   X");
        cout = "   MIN" + "  " + q_min.ToString(CultureInfo.InvariantCulture).PadLeft(14);
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_1d_min[dim].ToString().PadLeft(2);
        }

        Console.WriteLine(cout);

        DateTime t1 = DateTime.Now;

        for (;;)
        {
            SGMGAniso.sgmga_vcn_naive(dim_num, level_weight, level_1d_max, level_1d,
                                      q_min, q_max, ref more_grids);

            if (!more_grids)
            {
                break;
            }
        }

        DateTime t2 = DateTime.Now;

        cout = "   MAX" + "  " + q_max.ToString(CultureInfo.InvariantCulture).PadLeft(14);
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_1d_max[dim].ToString().PadLeft(2);
        }

        Console.WriteLine(cout);
        Console.WriteLine("  TIME" + "  "
                          + (t2 - t1).TotalSeconds.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

        Console.WriteLine("");
        Console.WriteLine("  SGMGA_VCN");
        Console.WriteLine("     I               Q   X");
        cout = "   MIN" + "  " + q_min.ToString(CultureInfo.InvariantCulture).PadLeft(14);
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_1d_min[dim].ToString().PadLeft(2);
        }

        Console.WriteLine(cout);

        t1 = DateTime.Now;
        for (;;)
        {
            SGMGAniso.sgmga_vcn(ref data, dim_num, level_weight, ref level_1d, q_min, q_max,
                                ref more_grids);

            if (!more_grids)
            {
                break;
            }
        }

        t2   = DateTime.Now;
        cout = "   MAX" + "  " + q_max.ToString(CultureInfo.InvariantCulture).PadLeft(14);
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_1d_max[dim].ToString().PadLeft(2);
        }

        Console.WriteLine(cout);
        Console.WriteLine("  TIME" + "  "
                          + (t2 - t1).TotalSeconds.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
    }