コード例 #1
0
ファイル: Annelling.cs プロジェクト: Qdzia/University
        public double FindMin(IFunction function)
        {
            double[] currentState = RandGenerator.RandomArray
                                        (dimensions, searchSpace[0], searchSpace[1]);

            double T     = maxTemp;
            double alpha = 0.999;

            for (int i = 0; i < iterTreshold; i++)
            {
                double[] newState = new double[dimensions];
                currentState.CopyTo(newState, 0);
                for (int j = 0; j < dimensions; j++)
                {
                    newState[j] += RandGenerator.RandomNormal(-1.0, 1.0, 1) * T;
                }
                if (AcceptanceProb(function.Calculate(currentState), function.Calculate(newState), T) >= rand.NextDouble())
                {
                    currentState = newState;
                }

                T *= alpha;
            }
            return(function.Calculate(currentState));
        }
コード例 #2
0
 private double[] Move(double[] start, int iteration)
 {
     double[] result = new double[start.Length];
     start.CopyTo(result, 0);
     for (int i = 0; i < iteration; i++)
     {
         for (int j = 0; j < result.Length; j++)
         {
             result[j] += RandGenerator.RandomNormal(-1.0, 1.0, 100) * walkSize;
         }
     }
     return(result);
 }