Beispiel #1
0
        public override bool GetNext(double[] probDist, int nOps)
        {
            // Create an array of operators that we are going to perform to generate neighbors
            List <NOp> ops = new List <NOp>(schedule.GetOperations(probDist, nOps));

            // Take a random operator
            // if it may be performed
            //  - Apply it if the operator decreases the score
            //  - Apply the operator with chance decpending on the temperator if the score is increased
            while (ops.Count != 0)
            {
                int i  = StaticRandom.Next(0, ops.Count);
                NOp op = ops[i];
                ops.RemoveAt(i);
                if (op.Evaluate())
                {
                    double delta = op.TotalDelta;
                    if (delta < 0)
                    {
                        op.Apply();
                        return(true);
                    }
                    else
                    {
                        double p = Prob(delta, c);
                        double r = StaticRandom.NextDouble();

                        if (p > r)
                        {
                            op.Apply();
                            return(true);
                        }
                    }
                }
                c *= a; // Update temperature
            }
            return(false);
        }