Beispiel #1
0
            protected override bool _Evaluate(out double deltaTime, out double deltaPenalty)
            {
                // Initialize variables:
                deltaTime    = double.NaN;
                deltaPenalty = double.NaN;
                if (toAdd == null)
                {
                    return(false);
                }

                // Get the possible day combinations the order may be added:
                List <int[]> combis = GD.AllowedDayCombinations[nAdditions].ToList();

                // Try each day combination:
                while (!(combis.Count == 0))
                {
                    int[] combi = combis[StaticRandom.Next(0, combis.Count)];
                    int   everyDayInCombiAllowed = 0;
                    deltas           = new List <double>(nAdditions);
                    whereToAdd       = new List <Node>(nAdditions);
                    whereToAddDays   = new List <int>(nAdditions);
                    whereToAddTrucks = new List <int>(nAdditions);
                    foreach (int day in combi)
                    {
                        // Try to add order in a random truck:
                        int truck = StaticRandom.Next(0, 2);
                        if (State.DayRoutes[day][truck].EvaluateRandomAdd(toAdd, out double delta1, out Node where1)) // MISS NIET BEIDE TRUCKS PROBEREN
                        {
                            deltas.Add(delta1);
                            whereToAdd.Add(where1);
                            whereToAddDays.Add(day);
                            whereToAddTrucks.Add(truck);
                            everyDayInCombiAllowed++;
                            continue;
                        }
Beispiel #2
0
            protected override bool _Evaluate(out double deltaTime, out double deltaPenalty)
            {
                // Pick random order:
                int ind = StaticRandom.Next(0, State.UnScheduledOrders.Count);

                // Evaluate the addition:
                addOp = new AddOperation(State, ind);
                bool possible = addOp.Evaluate();

                deltaTime    = addOp.DeltaTime;
                deltaPenalty = addOp.DeltaPenalty;
                return(possible);
            }
Beispiel #3
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);
        }