コード例 #1
0
 public static void updateHM(double[,] HMtab, Function f, double[] vec)
 {
     HarmonyTool.performVec(f, vec);
     if (vec[vec.GetLength(0) - 1] < HMtab[HMtab.GetLength(0) - 1, HMtab.GetLength(1) - 1])
     {
         for (int i = 0; i < HMtab.GetLength(1); i++)
         {
             HMtab[HMtab.GetLength(0) - 1, i] = vec[i];
         }
         HarmonyTool.sortHM(HMtab);
     }
 }
コード例 #2
0
        public static void HarmonySearchAlgorithm(Function f, int NI, int HMS, double HMCR, double PAR, double BW, double[] PVBmin, double[] PVBmax)
        {
            int numberofVariables = f.getArgumentsNumber();

            double[,] HMtab = new double[HMS, numberofVariables + 1];
            int iterations = 0;

            HarmonyTool.initializeHM(HMtab, PVBmin, PVBmax);
            HarmonyTool.performHM(f, HMtab);
            HarmonyTool.sortHM(HMtab);
            double[] newVec = new double[HMtab.GetLength(1)];
            for (int i = 0; i < NI; i++)
            {
                newVec = HarmonyTool.newHarmonyVector(HMtab, HMCR, PAR, BW, PVBmin, PVBmax);
                HarmonyTool.updateHM(HMtab, f, newVec);
                iterations++;
            }
            Console.WriteLine("Koniec obliczen");
            Console.WriteLine("Liczba wykonanych iteracji: " + iterations);
            Console.WriteLine("Ostateczna tabela Harmony Memory:");
            HarmonyTool.displayHM(HMtab);
        }