Пример #1
0
        public static void initializeHM(double[,] HMtab, double[] PVBmin, double[] PVBmax)
        {
            double tmp;

            for (int i = 0; i < HMtab.GetLength(0); i++)
            {
                for (int j = 0; j < HMtab.GetLength(1) - 1; j++)
                {
                    tmp         = HarmonyTool.rand_cont_gen("0", "1") * (PVBmax[j] - PVBmin[j]) + PVBmin[j];
                    HMtab[i, j] = tmp;
                }
                HMtab[i, HMtab.GetLength(1) - 1] = 0;
            }
        }
Пример #2
0
        public static double[] newHarmonyVector(double[,] HMtab, double HMCR, double PAR, double BW, double[] PVBmin, double[] PVBmax)
        {
            int    newIndex;
            int    variables = HMtab.GetLength(1);
            Random rand      = new Random();

            double[] vec = new double[variables];   //new harmony vector
            for (int i = 0; i < variables - 1; i++) // -1 bo osatnia kolumna dla f(X)
            {
                if (rand.NextDouble() < HMCR)
                {
                    newIndex = HarmonyTool.rand_discrete_gen("0", "9");
                    vec[i]   = HMtab[newIndex, i];
                    if (rand.NextDouble() < PAR)
                    {
                        if (rand.NextDouble() < 0.5)
                        {
                            double D5 = vec[i] - HarmonyTool.rand_cont_gen("0", "1") * BW;
                            if (D5 >= PVBmin[i])
                            {
                                vec[i] = D5; //pitch adjustment
                            }
                        }
                        else
                        {
                            double D5_2 = vec[i] + HarmonyTool.rand_cont_gen("0", "1") * BW;
                            if (D5_2 <= PVBmax[i])
                            {
                                vec[i] = D5_2;
                            }
                        }
                    }
                }
                else
                {
                    vec[i] = HarmonyTool.rand_cont_gen("0", "1") * (PVBmax[i] - PVBmin[i]) + PVBmin[i]; //randomizacja
                }
            }
            return(vec);
        }