Beispiel #1
0
        protected internal override void  NextSearch()
        {
            if (totalTimeout > 0)
            {
                long   elapsedTime       = Math.Max(1, (DateTime.Now.Ticks - 621355968000000000) / 10000 - startTime);
                double iterationRate     = (double)iteration / elapsedTime;
                var    expectedIteration = (int)(iterationRate * (totalTimeout - elapsedTime));
                if (expectedIteration > 0)
                {
                    gamma = Math.Exp(Math.Log(1.0 / temperature) / expectedIteration);
                    gamma = Math.Min(0.9999, gamma);
                }
            }
            temperature *= gamma;
            solution     = GetCandidate();
            int  objectiveIntValue = solution.ObjectiveIntValue;
            Code code = solution.Code;

            System.Collections.IList operations = code.Operations();
            while (operations.Count > 0)
            {
                var    i          = (int)(operations.Count * SupportClass.Random.NextDouble());
                object tempObject = operations[i];
                operations.RemoveAt(i);
                var op = (Operation)tempObject;
                code.To = network;
                op.ApplyTo(network);
                Solution sol = solver.FindBest(IterTimeout);
                if (sol == null)
                {
                    continue;
                }
                double delta = sol.ObjectiveIntValue - objectiveIntValue;
                if (IsOption(Maximize))
                {
                    delta = -delta;
                }
                if (delta < 0)
                {
                    solution = sol;
                    return;
                }
                double p = Math.Exp((-delta) / temperature);
                if (p < SupportClass.Random.NextDouble())
                {
                    continue;
                }
                solution = sol;
                return;
            }
            solution = null;
        }
Beispiel #2
0
        protected internal override void  NextSearch()
        {
            Operation locallyBestOp  = null;
            Solution  locallyBestSol = null;
            int       locallyBest    = IntDomain.MaxValue;

            solution = GetCandidate();
            Code code = solution.Code;

            while (!Aborted)
            {
                IEnumerator ops = code.Operations().GetEnumerator();
                while (ops.MoveNext() && !Aborted)
                {
                    var op = (Operation)ops.Current;
                    if (IsTaboo(op, taboo))
                    {
                        continue;
                    }
                    code.To = network;
                    op.ApplyTo(network);
                    Solution sol = solver.FindBest(IterTimeout);
                    if (sol == null)
                    {
                        continue;
                    }
                    int objectiveIntValue = sol.ObjectiveIntValue;
                    if (!IsBetter(objectiveIntValue, locallyBest))
                    {
                        continue;
                    }
                    locallyBest    = objectiveIntValue;
                    locallyBestOp  = op;
                    locallyBestSol = sol;
                }
                if (locallyBestOp != null)
                {
                    break;
                }
                ClearTaboo();
            }
            code.To = network;
            if (locallyBestOp != null)
            {
                locallyBestOp.ApplyTo(network);
            }

            solution = locallyBestSol;
            AddTaboo(locallyBestOp);
        }
Beispiel #3
0
        protected internal virtual void  NextSearch()
        {
            solution = GetCandidate();
            Code code = solution.Code;

            System.Collections.IList operations = code.Operations();
            while (operations.Count > 0)
            {
                var    i          = (int)(operations.Count * SupportClass.Random.NextDouble());
                object tempObject = operations[i];
                operations.RemoveAt(i);
                var op = (Operation)tempObject;
                code.To = network;
                op.ApplyTo(network);
                Solution sol = solver.FindBest(IterTimeout);
                if (sol == null)
                {
                    continue;
                }
                solution = sol;
                return;
            }
            solution = null;
        }